mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-14 08:01:38 +01:00
export index from jni and use for fastscrolling. Works, but is a bit slow still.
This commit is contained in:
parent
5282246dd6
commit
ed055b83c6
3 changed files with 91 additions and 8 deletions
|
@ -1266,8 +1266,12 @@ Java_org_eehouse_android_xw4_jni_XwJNI_server_1sendChat
|
||||||
typedef struct _DictIterData {
|
typedef struct _DictIterData {
|
||||||
JNIEnv* env;
|
JNIEnv* env;
|
||||||
JNIUtilCtxt* jniutil;
|
JNIUtilCtxt* jniutil;
|
||||||
|
VTableMgr* vtMgr;
|
||||||
DictionaryCtxt* dict;
|
DictionaryCtxt* dict;
|
||||||
DictWord word;
|
DictWord word;
|
||||||
|
XWStreamCtxt* prefixStream;
|
||||||
|
DictIndex* indices;
|
||||||
|
XP_U16 nIndices;
|
||||||
#ifdef MEM_DEBUG
|
#ifdef MEM_DEBUG
|
||||||
MemPoolCtx* mpool;
|
MemPoolCtx* mpool;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1287,6 +1291,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1init
|
||||||
DictionaryCtxt* dict = makeDict( MPPARM(mpool) env, jniutil, NULL,
|
DictionaryCtxt* dict = makeDict( MPPARM(mpool) env, jniutil, NULL,
|
||||||
jDictBytes, jpath, NULL );
|
jDictBytes, jpath, NULL );
|
||||||
if ( !!dict ) {
|
if ( !!dict ) {
|
||||||
|
data->vtMgr = make_vtablemgr( MPPARM_NOCOMMA(mpool) );
|
||||||
data->jniutil = jniutil;
|
data->jniutil = jniutil;
|
||||||
data->dict = dict;
|
data->dict = dict;
|
||||||
#ifdef MEM_DEBUG
|
#ifdef MEM_DEBUG
|
||||||
|
@ -1313,6 +1318,13 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1destroy
|
||||||
if ( NULL != data ) {
|
if ( NULL != data ) {
|
||||||
dict_destroy( data->dict );
|
dict_destroy( data->dict );
|
||||||
destroyJNIUtil( &data->jniutil );
|
destroyJNIUtil( &data->jniutil );
|
||||||
|
if ( NULL != data->prefixStream ) {
|
||||||
|
stream_destroy( data->prefixStream );
|
||||||
|
}
|
||||||
|
if ( !!data->indices ) {
|
||||||
|
XP_FREE( data->mpool, data->indices );
|
||||||
|
}
|
||||||
|
vtmgr_destroy( MPPARM(data->mpool) data->vtMgr );
|
||||||
#ifdef MEM_DEBUG
|
#ifdef MEM_DEBUG
|
||||||
MemPoolCtx* mpool = data->mpool;
|
MemPoolCtx* mpool = data->mpool;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1332,10 +1344,57 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1wordCount
|
||||||
if ( NULL != data ) {
|
if ( NULL != data ) {
|
||||||
result = data->word.wordCount;
|
result = data->word.wordCount;
|
||||||
}
|
}
|
||||||
LOG_RETURNF( "%d", result );
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1makeIndex
|
||||||
|
( JNIEnv* env, jclass C, jint closure )
|
||||||
|
{
|
||||||
|
DictIterData* data = (DictIterData*)closure;
|
||||||
|
if ( NULL != data ) {
|
||||||
|
XP_U16 depth = 2;
|
||||||
|
DictIndex indices[depth*32*32];
|
||||||
|
XWStreamCtxt* stream = mem_stream_make( MPPARM(data->mpool) data->vtMgr,
|
||||||
|
NULL, 0, NULL );
|
||||||
|
XP_U16 nIndices = dict_makeIndex( data->dict, depth, indices, VSIZE(indices),
|
||||||
|
stream );
|
||||||
|
|
||||||
|
data->indices = XP_MALLOC( data->mpool, nIndices * sizeof(*data->indices) );
|
||||||
|
XP_MEMCPY( data->indices, indices, nIndices * sizeof(*data->indices) );
|
||||||
|
data->nIndices = nIndices;
|
||||||
|
data->prefixStream = stream;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jstring JNICALL
|
||||||
|
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getPrefixes
|
||||||
|
( JNIEnv* env, jclass C, jint closure )
|
||||||
|
{
|
||||||
|
jstring result = NULL;
|
||||||
|
DictIterData* data = (DictIterData*)closure;
|
||||||
|
if ( NULL != data && NULL != data->prefixStream ) {
|
||||||
|
result = streamToJString( MPPARM(data->mpool) env, data->prefixStream );
|
||||||
|
(*env)->DeleteLocalRef( env, result );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jintArray JNICALL
|
||||||
|
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getIndices
|
||||||
|
( JNIEnv* env, jclass C , jint closure )
|
||||||
|
{
|
||||||
|
jintArray jindices = NULL;
|
||||||
|
DictIterData* data = (DictIterData*)closure;
|
||||||
|
if ( NULL != data ) {
|
||||||
|
XP_ASSERT( !!data->indices );
|
||||||
|
XP_ASSERT( sizeof(jint) == sizeof(data->indices[0]) );
|
||||||
|
jindices = makeIntArray( env, data->nIndices, data->indices );
|
||||||
|
(*env)->DeleteLocalRef( env, jindices );
|
||||||
|
}
|
||||||
|
return jindices;
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL
|
JNIEXPORT jstring JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1nthWord
|
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1nthWord
|
||||||
( JNIEnv* env, jclass C, jint closure, jint nn)
|
( JNIEnv* env, jclass C, jint closure, jint nn)
|
||||||
|
|
|
@ -23,12 +23,14 @@ package org.eehouse.android.xw4;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.DataSetObserver;
|
import android.database.DataSetObserver;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.ListAdapter;
|
import android.widget.ListAdapter;
|
||||||
import android.widget.SectionIndexer;
|
import android.widget.SectionIndexer;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
@ -51,6 +53,9 @@ public class DictBrowseActivity extends XWListActivity {
|
||||||
private class DictListAdapter extends BaseAdapter
|
private class DictListAdapter extends BaseAdapter
|
||||||
implements SectionIndexer {
|
implements SectionIndexer {
|
||||||
|
|
||||||
|
private String[] m_prefixes;
|
||||||
|
private int[] m_indices;
|
||||||
|
|
||||||
public Object getItem( int position )
|
public Object getItem( int position )
|
||||||
{
|
{
|
||||||
TextView text = new TextView( DictBrowseActivity.this );
|
TextView text = new TextView( DictBrowseActivity.this );
|
||||||
|
@ -76,21 +81,36 @@ public class DictBrowseActivity extends XWListActivity {
|
||||||
// SectionIndexer
|
// SectionIndexer
|
||||||
public int getPositionForSection( int section )
|
public int getPositionForSection( int section )
|
||||||
{
|
{
|
||||||
Utils.logf( "DictBrowseActivity: getPositionForSection" );
|
return m_indices[section];
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSectionForPosition( int position )
|
public int getSectionForPosition( int position )
|
||||||
{
|
{
|
||||||
Utils.logf( "DictBrowseActivity: getSectionForPosition" );
|
int section = Arrays.binarySearch( m_indices, position );
|
||||||
return 0;
|
if ( section < 0 ) {
|
||||||
|
section *= -1;
|
||||||
|
}
|
||||||
|
if ( section >= m_indices.length ) {
|
||||||
|
section = m_indices.length - 1;
|
||||||
|
}
|
||||||
|
// for ( section = 0; section < m_indices.length - 1; ++section ) {
|
||||||
|
// if ( position <= m_indices[section] ) {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// Utils.logf( "DictBrowseActivity: getSectionForPosition" );
|
||||||
|
return section;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getSections()
|
public Object[] getSections()
|
||||||
{
|
{
|
||||||
Utils.logf( "DictBrowseActivity: getSections" );
|
String prefs = XwJNI.dict_iter_getPrefixes( m_dictClosure );
|
||||||
String[] sections = { "AA", "BB", "CC", "DD", "EE" };
|
m_prefixes = TextUtils.split( prefs, "\n" );
|
||||||
return sections;
|
m_indices = XwJNI.dict_iter_getIndices( m_dictClosure );
|
||||||
|
Utils.logf( "len(m_indices): %d; len(m_prefixes): %d",
|
||||||
|
m_indices.length, m_prefixes.length );
|
||||||
|
Assert.assertTrue( m_indices.length == m_prefixes.length );
|
||||||
|
return m_prefixes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +128,7 @@ public class DictBrowseActivity extends XWListActivity {
|
||||||
DictUtils.DictPairs pairs = DictUtils.openDicts( this, names );
|
DictUtils.DictPairs pairs = DictUtils.openDicts( this, names );
|
||||||
m_dictClosure = XwJNI.dict_iter_init( pairs.m_bytes[0], pairs.m_paths[0],
|
m_dictClosure = XwJNI.dict_iter_init( pairs.m_bytes[0], pairs.m_paths[0],
|
||||||
JNIUtilsImpl.get() );
|
JNIUtilsImpl.get() );
|
||||||
|
XwJNI.dict_iter_makeIndex( m_dictClosure );
|
||||||
|
|
||||||
setContentView( R.layout.dict_browser );
|
setContentView( R.layout.dict_browser );
|
||||||
setListAdapter( new DictListAdapter() );
|
setListAdapter( new DictListAdapter() );
|
||||||
|
|
|
@ -241,4 +241,7 @@ public class XwJNI {
|
||||||
public static native void dict_iter_destroy( int closure );
|
public static native void dict_iter_destroy( int closure );
|
||||||
public static native int dict_iter_wordCount( int closure );
|
public static native int dict_iter_wordCount( int closure );
|
||||||
public static native String dict_iter_nthWord( int closure, int nn );
|
public static native String dict_iter_nthWord( int closure, int nn );
|
||||||
|
public static native void dict_iter_makeIndex( int closure );
|
||||||
|
public static native String dict_iter_getPrefixes( int closure );
|
||||||
|
public static native int[] dict_iter_getIndices( int closure );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue