wire min/max through jni: now selecting numbers changes the number and

length of words selected.  But it's really slow, and indexing seems
broken in some cases.  Not ready for release yet.
This commit is contained in:
Andy2 2011-11-04 06:56:59 -07:00
parent fa14f02b69
commit 57a1069efe
4 changed files with 74 additions and 51 deletions

View file

@ -25,12 +25,12 @@ local_DEFINES += \
-DDISABLE_TILE_SEL \
-DXWFEATURE_BOARDWORDS \
-DXWFEATURE_WALKDICT \
-DXWFEATURE_WALKDICT_FILTER \
-DFEATURE_TRAY_EDIT \
-DNODE_CAN_4 \
-DRELAY_ROOM_DEFAULT=\"\"\
-D__LITTLE_ENDIAN \
# -DXWFEATURE_WALKDICT_FILTER \
local_SRC_FILES += \
xwjni.c \

View file

@ -1294,13 +1294,11 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1init
data->vtMgr = make_vtablemgr( MPPARM_NOCOMMA(mpool) );
data->jniutil = jniutil;
data->dict = dict;
data->depth = 2;
#ifdef MEM_DEBUG
data->mpool = mpool;
#endif
closure = (int)data;
dict_initIter( &data->iter, data->dict, 0, MAX_COLS-1 );
(void)dict_firstWord( &data->iter );
} else {
destroyJNIUtil( &jniutil );
XP_FREE( mpool, data );
@ -1311,6 +1309,63 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1init
return closure;
}
static void
freeIndices( DictIterData* data )
{
IndexData* idata = &data->idata;
if ( !!idata->prefixes ) {
XP_FREE( data->mpool, idata->prefixes );
idata->prefixes = NULL;
}
if( !!idata->indices ) {
XP_FREE( data->mpool, idata->indices );
idata->indices = NULL;
}
}
static void
makeIndex( DictIterData* data )
{
XP_U16 nFaces = dict_numTileFaces( data->dict );
XP_U16 ii;
XP_U16 count;
for ( count = 1, ii = 0; ii < data->depth; ++ii ) {
count *= nFaces;
}
freeIndices( data );
IndexData* idata = &data->idata;
idata->prefixes = XP_MALLOC( data->mpool, count * data->depth
* sizeof(*idata->prefixes) );
idata->indices = XP_MALLOC( data->mpool,
count * sizeof(*idata->indices) );
idata->count = count;
dict_makeIndex( &data->iter, data->depth, idata );
if ( 0 < count ) {
idata->prefixes = XP_REALLOC( data->mpool, idata->prefixes,
idata->count * data->depth *
sizeof(*idata->prefixes) );
idata->indices = XP_REALLOC( data->mpool, idata->indices,
idata->count * sizeof(*idata->indices) );
} else {
freeIndices( data );
}
}
JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1setMinMax
( JNIEnv* env, jclass C, jint closure, jint min, jint max )
{
DictIterData* data = (DictIterData*)closure;
if ( NULL != data ) {
dict_initIter( &data->iter, data->dict, min, max );
makeIndex( data );
(void)dict_firstWord( &data->iter );
}
}
JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1destroy
( JNIEnv* env, jclass C, jint closure )
@ -1322,12 +1377,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1destroy
#endif
dict_destroy( data->dict );
destroyJNIUtil( &data->jniutil );
if ( !!data->idata.indices ) {
XP_FREE( mpool, data->idata.indices );
}
if ( !!data->idata.prefixes ) {
XP_FREE( mpool, data->idata.prefixes );
}
freeIndices( data );
vtmgr_destroy( MPPARM(mpool) data->vtMgr );
XP_FREE( mpool, data );
#ifdef MEM_DEBUG
@ -1348,39 +1398,6 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1wordCount
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 ) {
data->depth = 2; /* for now */
XP_U16 nFaces = dict_numTileFaces( data->dict );
XP_U16 ii;
XP_U16 count;
for ( count = 1, ii = 0; ii < data->depth; ++ii ) {
count *= nFaces;
}
IndexData* idata = &data->idata;
XP_ASSERT( !idata->prefixes );
idata->prefixes = XP_MALLOC( data->mpool, count * data->depth
* sizeof(*idata->prefixes) );
XP_ASSERT( !idata->indices );
idata->indices = XP_MALLOC( data->mpool,
count * sizeof(*idata->indices) );
idata->count = count;
dict_makeIndex( &data->iter, data->depth, idata );
idata->prefixes = XP_REALLOC( data->mpool, idata->prefixes,
idata->count * data->depth *
sizeof(*idata->prefixes) );
idata->indices = XP_REALLOC( data->mpool, idata->indices,
idata->count * sizeof(*idata->indices) );
}
}
JNIEXPORT jobjectArray JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getPrefixes
( JNIEnv* env, jclass C, jint closure )

View file

@ -53,7 +53,6 @@ public class DictBrowseActivity extends XWListActivity
private int m_dictClosure = 0;
private int m_lang;
private String m_name;
private int m_nWords;
private float m_textSize;
private Spinner m_minSpinner;
private Spinner m_maxSpinner;
@ -72,6 +71,18 @@ public class DictBrowseActivity extends XWListActivity
private String[] m_prefixes;
private int[] m_indices;
private int m_nWords;
public DictListAdapter()
{
super();
XwJNI.dict_iter_setMinMax( m_dictClosure, m_min, m_max );
m_nWords = XwJNI.dict_iter_wordCount( m_dictClosure );
setTitle( Utils.format( DictBrowseActivity.this,
R.string.dict_browse_titlef,
m_name, m_nWords ) );
}
public Object getItem( int position )
{
@ -142,12 +153,6 @@ public class DictBrowseActivity extends XWListActivity
m_dictClosure = XwJNI.dict_iter_init( pairs.m_bytes[0],
pairs.m_paths[0],
JNIUtilsImpl.get() );
m_nWords = XwJNI.dict_iter_wordCount( m_dictClosure );
setTitle( Utils.format( this, R.string.dict_browse_titlef,
name, m_nWords ) );
XwJNI.dict_iter_makeIndex( m_dictClosure );
setContentView( R.layout.dict_browser );

View file

@ -238,10 +238,11 @@ public class XwJNI {
// Dict iterator
public static native int dict_iter_init( byte[] dict, String path,
JNIUtils jniu );
public static native void dict_iter_setMinMax( int closure,
int min, int max );
public static native void dict_iter_destroy( 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 void dict_iter_makeIndex( int closure );
public static native String[] dict_iter_getPrefixes( int closure );
public static native int[] dict_iter_getIndices( int closure );
public static native int dict_iter_getStartsWith( int closure,