mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-07 05:24:46 +01:00
api cleanup: dict_iter -> di
(JNI changed too, so it's not just compiler-checked, but tests ok)
This commit is contained in:
parent
851fa1a76e
commit
98ce0e416f
7 changed files with 119 additions and 120 deletions
|
@ -81,9 +81,9 @@ public class DictBrowseDelegate extends DelegateBase
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
XwJNI.dict_iter_setMinMax( m_dictClosure, m_browseState.m_minShown,
|
XwJNI.di_setMinMax( m_dictClosure, m_browseState.m_minShown,
|
||||||
m_browseState.m_maxShown );
|
m_browseState.m_maxShown );
|
||||||
m_nWords = XwJNI.dict_iter_wordCount( m_dictClosure );
|
m_nWords = XwJNI.di_wordCount( m_dictClosure );
|
||||||
|
|
||||||
int format = m_browseState.m_minShown == m_browseState.m_maxShown ?
|
int format = m_browseState.m_minShown == m_browseState.m_maxShown ?
|
||||||
R.string.dict_browse_title1_fmt : R.string.dict_browse_title_fmt;
|
R.string.dict_browse_title1_fmt : R.string.dict_browse_title_fmt;
|
||||||
|
@ -96,7 +96,7 @@ public class DictBrowseDelegate extends DelegateBase
|
||||||
{
|
{
|
||||||
TextView text = (TextView)
|
TextView text = (TextView)
|
||||||
inflate( android.R.layout.simple_list_item_1 );
|
inflate( android.R.layout.simple_list_item_1 );
|
||||||
String str = XwJNI.dict_iter_nthWord( m_dictClosure, position );
|
String str = XwJNI.di_nthWord( m_dictClosure, position );
|
||||||
if ( null != str ) {
|
if ( null != str ) {
|
||||||
text.setText( str );
|
text.setText( str );
|
||||||
text.setOnClickListener( DictBrowseDelegate.this );
|
text.setOnClickListener( DictBrowseDelegate.this );
|
||||||
|
@ -138,8 +138,8 @@ public class DictBrowseDelegate extends DelegateBase
|
||||||
|
|
||||||
public Object[] getSections()
|
public Object[] getSections()
|
||||||
{
|
{
|
||||||
m_prefixes = XwJNI.dict_iter_getPrefixes( m_dictClosure );
|
m_prefixes = XwJNI.di_getPrefixes( m_dictClosure );
|
||||||
m_indices = XwJNI.dict_iter_getIndices( m_dictClosure );
|
m_indices = XwJNI.di_getIndices( m_dictClosure );
|
||||||
return m_prefixes;
|
return m_prefixes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,10 +166,10 @@ public class DictBrowseDelegate extends DelegateBase
|
||||||
|
|
||||||
String[] names = { name };
|
String[] names = { name };
|
||||||
DictUtils.DictPairs pairs = DictUtils.openDicts( m_activity, names );
|
DictUtils.DictPairs pairs = DictUtils.openDicts( m_activity, names );
|
||||||
m_dictClosure = XwJNI.dict_iter_init( pairs.m_bytes[0],
|
m_dictClosure = XwJNI.di_init( pairs.m_bytes[0],
|
||||||
name, pairs.m_paths[0] );
|
name, pairs.m_paths[0] );
|
||||||
|
|
||||||
String desc = XwJNI.dict_iter_getDesc( m_dictClosure );
|
String desc = XwJNI.di_getDesc( m_dictClosure );
|
||||||
Log.d( TAG, "got desc: %s", desc );
|
Log.d( TAG, "got desc: %s", desc );
|
||||||
if ( null != desc ) {
|
if ( null != desc ) {
|
||||||
TextView view = (TextView)findViewById( R.id.desc );
|
TextView view = (TextView)findViewById( R.id.desc );
|
||||||
|
@ -186,8 +186,7 @@ public class DictBrowseDelegate extends DelegateBase
|
||||||
m_browseState.m_top = 0;
|
m_browseState.m_top = 0;
|
||||||
}
|
}
|
||||||
if ( null == m_browseState.m_counts ) {
|
if ( null == m_browseState.m_counts ) {
|
||||||
m_browseState.m_counts =
|
m_browseState.m_counts = XwJNI.di_getCounts( m_dictClosure );
|
||||||
XwJNI.dict_iter_getCounts( m_dictClosure );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( null == m_browseState.m_counts ) {
|
if ( null == m_browseState.m_counts ) {
|
||||||
|
@ -246,7 +245,7 @@ public class DictBrowseDelegate extends DelegateBase
|
||||||
|
|
||||||
protected void onDestroy()
|
protected void onDestroy()
|
||||||
{
|
{
|
||||||
XwJNI.dict_iter_destroy( m_dictClosure );
|
XwJNI.di_destroy( m_dictClosure );
|
||||||
m_dictClosure = 0;
|
m_dictClosure = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +253,7 @@ public class DictBrowseDelegate extends DelegateBase
|
||||||
@Override
|
@Override
|
||||||
public void finalize()
|
public void finalize()
|
||||||
{
|
{
|
||||||
XwJNI.dict_iter_destroy( m_dictClosure );
|
XwJNI.di_destroy( m_dictClosure );
|
||||||
try {
|
try {
|
||||||
super.finalize();
|
super.finalize();
|
||||||
} catch ( java.lang.Throwable err ){
|
} catch ( java.lang.Throwable err ){
|
||||||
|
@ -348,7 +347,7 @@ public class DictBrowseDelegate extends DelegateBase
|
||||||
{
|
{
|
||||||
String text = m_browseState.m_prefix;
|
String text = m_browseState.m_prefix;
|
||||||
if ( null != text && 0 < text.length() ) {
|
if ( null != text && 0 < text.length() ) {
|
||||||
int pos = XwJNI.dict_iter_getStartsWith( m_dictClosure, text );
|
int pos = XwJNI.di_getStartsWith( m_dictClosure, text );
|
||||||
if ( 0 <= pos ) {
|
if ( 0 <= pos ) {
|
||||||
m_list.setSelection( pos );
|
m_list.setSelection( pos );
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -514,22 +514,22 @@ public class XwJNI {
|
||||||
|
|
||||||
// Dict iterator
|
// Dict iterator
|
||||||
public final static int MAX_COLS_DICT = 15; // from dictiter.h
|
public final static int MAX_COLS_DICT = 15; // from dictiter.h
|
||||||
public static long dict_iter_init( byte[] dict, String name,
|
public static long di_init( byte[] dict, String name,
|
||||||
String path )
|
String path )
|
||||||
{
|
{
|
||||||
return dict_iter_init( getJNI().m_ptrGlobals, dict, name, path );
|
return di_init( getJNI().m_ptrGlobals, dict, name, path );
|
||||||
}
|
}
|
||||||
public static native void dict_iter_setMinMax( long closure,
|
public static native void di_setMinMax( long closure,
|
||||||
int min, int max );
|
int min, int max );
|
||||||
public static native void dict_iter_destroy( long closure );
|
public static native void di_destroy( long closure );
|
||||||
public static native int dict_iter_wordCount( long closure );
|
public static native int di_wordCount( long closure );
|
||||||
public static native int[] dict_iter_getCounts( long closure );
|
public static native int[] di_getCounts( long closure );
|
||||||
public static native String dict_iter_nthWord( long closure, int nn );
|
public static native String di_nthWord( long closure, int nn );
|
||||||
public static native String[] dict_iter_getPrefixes( long closure );
|
public static native String[] di_getPrefixes( long closure );
|
||||||
public static native int[] dict_iter_getIndices( long closure );
|
public static native int[] di_getIndices( long closure );
|
||||||
public static native int dict_iter_getStartsWith( long closure,
|
public static native int di_getStartsWith( long closure,
|
||||||
String prefix );
|
String prefix );
|
||||||
public static native String dict_iter_getDesc( long closure );
|
public static native String di_getDesc( long closure );
|
||||||
|
|
||||||
// Private methods -- called only here
|
// Private methods -- called only here
|
||||||
private static native long initGlobals( DUtilCtxt dutil, JNIUtils jniu );
|
private static native long initGlobals( DUtilCtxt dutil, JNIUtils jniu );
|
||||||
|
@ -548,7 +548,7 @@ public class XwJNI {
|
||||||
String name, String path,
|
String name, String path,
|
||||||
boolean check,
|
boolean check,
|
||||||
DictInfo info );
|
DictInfo info );
|
||||||
private static native long dict_iter_init( long jniState, byte[] dict,
|
private static native long di_init( long jniState, byte[] dict,
|
||||||
String name, String path );
|
String name, String path );
|
||||||
|
|
||||||
private static native byte[][]
|
private static native byte[][]
|
||||||
|
|
|
@ -2413,7 +2413,7 @@ static void makeIndex( DictIterData* data );
|
||||||
static void freeIndices( DictIterData* data );
|
static void freeIndices( DictIterData* data );
|
||||||
|
|
||||||
JNIEXPORT jlong JNICALL
|
JNIEXPORT jlong JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1init
|
Java_org_eehouse_android_xw4_jni_XwJNI_di_1init
|
||||||
( JNIEnv* env, jclass C, jlong jniGlobalPtr, jbyteArray jDictBytes,
|
( JNIEnv* env, jclass C, jlong jniGlobalPtr, jbyteArray jDictBytes,
|
||||||
jstring jname, jstring jpath )
|
jstring jname, jstring jpath )
|
||||||
{
|
{
|
||||||
|
@ -2441,19 +2441,19 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1init
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1setMinMax
|
Java_org_eehouse_android_xw4_jni_XwJNI_di_1setMinMax
|
||||||
( JNIEnv* env, jclass C, jlong closure, jint min, jint max )
|
( JNIEnv* env, jclass C, jlong closure, jint min, jint max )
|
||||||
{
|
{
|
||||||
DictIterData* data = (DictIterData*)closure;
|
DictIterData* data = (DictIterData*)closure;
|
||||||
if ( NULL != data ) {
|
if ( NULL != data ) {
|
||||||
dict_initIter( &data->iter, data->dict, min, max );
|
di_initIter( &data->iter, data->dict, min, max );
|
||||||
makeIndex( data );
|
makeIndex( data );
|
||||||
(void)dict_firstWord( &data->iter );
|
(void)di_firstWord( &data->iter );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1destroy
|
Java_org_eehouse_android_xw4_jni_XwJNI_di_1destroy
|
||||||
( JNIEnv* env, jclass C, jlong closure )
|
( JNIEnv* env, jclass C, jlong closure )
|
||||||
{
|
{
|
||||||
DictIterData* data = (DictIterData*)closure;
|
DictIterData* data = (DictIterData*)closure;
|
||||||
|
@ -2472,7 +2472,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1destroy
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL
|
JNIEXPORT jint JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1wordCount
|
Java_org_eehouse_android_xw4_jni_XwJNI_di_1wordCount
|
||||||
(JNIEnv* env, jclass C, jlong closure )
|
(JNIEnv* env, jclass C, jlong closure )
|
||||||
{
|
{
|
||||||
jint result = 0;
|
jint result = 0;
|
||||||
|
@ -2484,17 +2484,17 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1wordCount
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jintArray JNICALL
|
JNIEXPORT jintArray JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getCounts
|
Java_org_eehouse_android_xw4_jni_XwJNI_di_1getCounts
|
||||||
(JNIEnv* env, jclass C, jlong closure )
|
(JNIEnv* env, jclass C, jlong closure )
|
||||||
{
|
{
|
||||||
jintArray result = NULL;
|
jintArray result = NULL;
|
||||||
DictIterData* data = (DictIterData*)closure;
|
DictIterData* data = (DictIterData*)closure;
|
||||||
if ( NULL != data ) {
|
if ( NULL != data ) {
|
||||||
DictIter iter;
|
DictIter iter;
|
||||||
dict_initIter( &iter, data->dict, 0, MAX_COLS_DICT );
|
di_initIter( &iter, data->dict, 0, MAX_COLS_DICT );
|
||||||
|
|
||||||
LengthsArray lens;
|
LengthsArray lens;
|
||||||
if ( 0 < dict_countWords( &iter, &lens ) ) {
|
if ( 0 < di_countWords( &iter, &lens ) ) {
|
||||||
XP_ASSERT( sizeof(jint) == sizeof(lens.lens[0]) );
|
XP_ASSERT( sizeof(jint) == sizeof(lens.lens[0]) );
|
||||||
result = makeIntArray( env, VSIZE(lens.lens), (jint*)&lens.lens,
|
result = makeIntArray( env, VSIZE(lens.lens), (jint*)&lens.lens,
|
||||||
sizeof(lens.lens[0]) );
|
sizeof(lens.lens[0]) );
|
||||||
|
@ -2504,7 +2504,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getCounts
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jobjectArray JNICALL
|
JNIEXPORT jobjectArray JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getPrefixes
|
Java_org_eehouse_android_xw4_jni_XwJNI_di_1getPrefixes
|
||||||
( JNIEnv* env, jclass C, jlong closure )
|
( JNIEnv* env, jclass C, jlong closure )
|
||||||
{
|
{
|
||||||
jobjectArray result = NULL;
|
jobjectArray result = NULL;
|
||||||
|
@ -2527,7 +2527,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getPrefixes
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jintArray JNICALL
|
JNIEXPORT jintArray JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getIndices
|
Java_org_eehouse_android_xw4_jni_XwJNI_di_1getIndices
|
||||||
( JNIEnv* env, jclass C, jlong closure )
|
( JNIEnv* env, jclass C, jlong closure )
|
||||||
{
|
{
|
||||||
jintArray jindices = NULL;
|
jintArray jindices = NULL;
|
||||||
|
@ -2543,15 +2543,15 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getIndices
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL
|
JNIEXPORT jstring JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1nthWord
|
Java_org_eehouse_android_xw4_jni_XwJNI_di_1nthWord
|
||||||
( JNIEnv* env, jclass C, jlong closure, jint nn)
|
( JNIEnv* env, jclass C, jlong closure, jint nn)
|
||||||
{
|
{
|
||||||
jstring result = NULL;
|
jstring result = NULL;
|
||||||
DictIterData* data = (DictIterData*)closure;
|
DictIterData* data = (DictIterData*)closure;
|
||||||
if ( NULL != data ) {
|
if ( NULL != data ) {
|
||||||
if ( dict_getNthWord( &data->iter, nn, data->depth, &data->idata ) ) {
|
if ( di_getNthWord( &data->iter, nn, data->depth, &data->idata ) ) {
|
||||||
XP_UCHAR buf[64];
|
XP_UCHAR buf[64];
|
||||||
dict_wordToString( &data->iter, buf, VSIZE(buf) );
|
di_wordToString( &data->iter, buf, VSIZE(buf) );
|
||||||
result = (*env)->NewStringUTF( env, buf );
|
result = (*env)->NewStringUTF( env, buf );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2559,15 +2559,15 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1nthWord
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL
|
JNIEXPORT jint JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getStartsWith
|
Java_org_eehouse_android_xw4_jni_XwJNI_di_1getStartsWith
|
||||||
( JNIEnv* env, jclass C, jlong closure, jstring jprefix )
|
( JNIEnv* env, jclass C, jlong closure, jstring jprefix )
|
||||||
{
|
{
|
||||||
jint result = -1;
|
jint result = -1;
|
||||||
DictIterData* data = (DictIterData*)closure;
|
DictIterData* data = (DictIterData*)closure;
|
||||||
if ( NULL != data ) {
|
if ( NULL != data ) {
|
||||||
const char* prefix = (*env)->GetStringUTFChars( env, jprefix, NULL );
|
const char* prefix = (*env)->GetStringUTFChars( env, jprefix, NULL );
|
||||||
if ( 0 <= dict_findStartsWith( &data->iter, prefix ) ) {
|
if ( 0 <= di_findStartsWith( &data->iter, prefix ) ) {
|
||||||
result = dict_getPosition( &data->iter );
|
result = di_getPosition( &data->iter );
|
||||||
}
|
}
|
||||||
(*env)->ReleaseStringUTFChars( env, jprefix, prefix );
|
(*env)->ReleaseStringUTFChars( env, jprefix, prefix );
|
||||||
}
|
}
|
||||||
|
@ -2575,7 +2575,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getStartsWith
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL
|
JNIEXPORT jstring JNICALL
|
||||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getDesc
|
Java_org_eehouse_android_xw4_jni_XwJNI_di_1getDesc
|
||||||
( JNIEnv* env, jclass C, jlong closure )
|
( JNIEnv* env, jclass C, jlong closure )
|
||||||
{
|
{
|
||||||
jstring result = NULL;
|
jstring result = NULL;
|
||||||
|
@ -2622,7 +2622,7 @@ makeIndex( DictIterData* data )
|
||||||
count * sizeof(*idata->indices) );
|
count * sizeof(*idata->indices) );
|
||||||
idata->count = count;
|
idata->count = count;
|
||||||
|
|
||||||
dict_makeIndex( &data->iter, data->depth, idata );
|
di_makeIndex( &data->iter, data->depth, idata );
|
||||||
if ( 0 < idata->count ) {
|
if ( 0 < idata->count ) {
|
||||||
idata->prefixes = XP_REALLOC( data->mpool, idata->prefixes,
|
idata->prefixes = XP_REALLOC( data->mpool, idata->prefixes,
|
||||||
idata->count * data->depth *
|
idata->count * data->depth *
|
||||||
|
|
|
@ -282,9 +282,9 @@ wordsEqual( const DictIter* word1, const DictIter* word2 )
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dict_initIterFrom( DictIter* dest, const DictIter* src )
|
initIterFrom( DictIter* dest, const DictIter* src )
|
||||||
{
|
{
|
||||||
dict_initIter( dest, src->dict,
|
di_initIter( dest, src->dict,
|
||||||
#ifdef XWFEATURE_WALKDICT_FILTER
|
#ifdef XWFEATURE_WALKDICT_FILTER
|
||||||
src->min, src->max
|
src->min, src->max
|
||||||
#else
|
#else
|
||||||
|
@ -307,10 +307,10 @@ firstWord( DictIter* iter )
|
||||||
}
|
}
|
||||||
|
|
||||||
XP_U32
|
XP_U32
|
||||||
dict_countWords( const DictIter* iter, LengthsArray* lens )
|
di_countWords( const DictIter* iter, LengthsArray* lens )
|
||||||
{
|
{
|
||||||
DictIter counter;
|
DictIter counter;
|
||||||
dict_initIterFrom( &counter, iter );
|
initIterFrom( &counter, iter );
|
||||||
|
|
||||||
if ( NULL != lens ) {
|
if ( NULL != lens ) {
|
||||||
XP_MEMSET( lens, 0, sizeof(*lens) );
|
XP_MEMSET( lens, 0, sizeof(*lens) );
|
||||||
|
@ -333,7 +333,7 @@ dict_countWords( const DictIter* iter, LengthsArray* lens )
|
||||||
#define ASSERT_INITED( iter ) XP_ASSERT( (iter)->guard == GUARD_VALUE )
|
#define ASSERT_INITED( iter ) XP_ASSERT( (iter)->guard == GUARD_VALUE )
|
||||||
|
|
||||||
void
|
void
|
||||||
dict_initIter( DictIter* iter, const DictionaryCtxt* dict,
|
di_initIter( DictIter* iter, const DictionaryCtxt* dict,
|
||||||
XP_U16 min, XP_U16 max )
|
XP_U16 min, XP_U16 max )
|
||||||
{
|
{
|
||||||
XP_MEMSET( iter, 0, sizeof(*iter) );
|
XP_MEMSET( iter, 0, sizeof(*iter) );
|
||||||
|
@ -421,7 +421,7 @@ indexOne( XP_U16 depth, Tile* tiles, IndexData* data, DictIter* prevIter,
|
||||||
DictPosition* prevIndex )
|
DictPosition* prevIndex )
|
||||||
{
|
{
|
||||||
DictIter curIter;
|
DictIter curIter;
|
||||||
dict_initIterFrom( &curIter, prevIter );
|
initIterFrom( &curIter, prevIter );
|
||||||
if ( findWordStartsWith( &curIter, tiles, depth ) ) {
|
if ( findWordStartsWith( &curIter, tiles, depth ) ) {
|
||||||
while ( !wordsEqual( &curIter, prevIter ) ) {
|
while ( !wordsEqual( &curIter, prevIter ) ) {
|
||||||
++*prevIndex;
|
++*prevIndex;
|
||||||
|
@ -458,7 +458,7 @@ doOneDepth( const Tile* allTiles, XP_U16 nTiles, Tile* prefix,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dict_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data )
|
di_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data )
|
||||||
{
|
{
|
||||||
ASSERT_INITED( iter );
|
ASSERT_INITED( iter );
|
||||||
const DictionaryCtxt* dict = iter->dict;
|
const DictionaryCtxt* dict = iter->dict;
|
||||||
|
@ -490,7 +490,7 @@ dict_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data )
|
||||||
*/
|
*/
|
||||||
data->count = 0;
|
data->count = 0;
|
||||||
DictIter prevIter;
|
DictIter prevIter;
|
||||||
dict_initIterFrom( &prevIter, iter );
|
initIterFrom( &prevIter, iter );
|
||||||
if ( firstWord( &prevIter ) ) {
|
if ( firstWord( &prevIter ) ) {
|
||||||
DictPosition prevIndex = 0;
|
DictPosition prevIndex = 0;
|
||||||
Tile prefix[depth];
|
Tile prefix[depth];
|
||||||
|
@ -504,16 +504,16 @@ dict_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data )
|
||||||
DI_ASSERT( data->indices[pos-1] < data->indices[pos] );
|
DI_ASSERT( data->indices[pos-1] < data->indices[pos] );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} /* dict_makeIndex */
|
} /* di_makeIndex */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
initWord( DictIter* iter )
|
initWord( DictIter* iter )
|
||||||
{
|
{
|
||||||
iter->nWords = dict_countWords( iter, NULL );
|
iter->nWords = di_countWords( iter, NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
XP_Bool
|
XP_Bool
|
||||||
dict_firstWord( DictIter* iter )
|
di_firstWord( DictIter* iter )
|
||||||
{
|
{
|
||||||
ASSERT_INITED( iter );
|
ASSERT_INITED( iter );
|
||||||
XP_Bool success = firstWord( iter );
|
XP_Bool success = firstWord( iter );
|
||||||
|
@ -526,7 +526,7 @@ dict_firstWord( DictIter* iter )
|
||||||
}
|
}
|
||||||
|
|
||||||
XP_Bool
|
XP_Bool
|
||||||
dict_getNextWord( DictIter* iter )
|
di_getNextWord( DictIter* iter )
|
||||||
{
|
{
|
||||||
ASSERT_INITED( iter );
|
ASSERT_INITED( iter );
|
||||||
XP_Bool success = nextWord( iter );
|
XP_Bool success = nextWord( iter );
|
||||||
|
@ -537,7 +537,7 @@ dict_getNextWord( DictIter* iter )
|
||||||
}
|
}
|
||||||
|
|
||||||
XP_Bool
|
XP_Bool
|
||||||
dict_lastWord( DictIter* iter )
|
di_lastWord( DictIter* iter )
|
||||||
{
|
{
|
||||||
ASSERT_INITED( iter );
|
ASSERT_INITED( iter );
|
||||||
iter->nEdges = 1;
|
iter->nEdges = 1;
|
||||||
|
@ -553,7 +553,7 @@ dict_lastWord( DictIter* iter )
|
||||||
}
|
}
|
||||||
|
|
||||||
XP_Bool
|
XP_Bool
|
||||||
dict_getPrevWord( DictIter* iter )
|
di_getPrevWord( DictIter* iter )
|
||||||
{
|
{
|
||||||
ASSERT_INITED( iter );
|
ASSERT_INITED( iter );
|
||||||
XP_Bool success = prevWord( iter );
|
XP_Bool success = prevWord( iter );
|
||||||
|
@ -567,7 +567,7 @@ dict_getPrevWord( DictIter* iter )
|
||||||
sought. OR if we're father than necessary from what's sought, start over
|
sought. OR if we're father than necessary from what's sought, start over
|
||||||
at the closer end. Then move as many steps as necessary to reach it. */
|
at the closer end. Then move as many steps as necessary to reach it. */
|
||||||
XP_Bool
|
XP_Bool
|
||||||
dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth,
|
di_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth,
|
||||||
const IndexData* data )
|
const IndexData* data )
|
||||||
{
|
{
|
||||||
ASSERT_INITED( iter );
|
ASSERT_INITED( iter );
|
||||||
|
@ -576,7 +576,7 @@ dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth,
|
||||||
XP_Bool validWord = 0 < iter->nEdges;
|
XP_Bool validWord = 0 < iter->nEdges;
|
||||||
if ( validWord ) { /* uninitialized */
|
if ( validWord ) { /* uninitialized */
|
||||||
wordCount = iter->nWords;
|
wordCount = iter->nWords;
|
||||||
DI_ASSERT( wordCount == dict_countWords( iter, NULL ) );
|
DI_ASSERT( wordCount == di_countWords( iter, NULL ) );
|
||||||
} else {
|
} else {
|
||||||
wordCount = dict_getWordCount( dict );
|
wordCount = dict_getWordCount( dict );
|
||||||
}
|
}
|
||||||
|
@ -589,9 +589,9 @@ dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth,
|
||||||
success = XP_TRUE;
|
success = XP_TRUE;
|
||||||
/* do nothing; we're done */
|
/* do nothing; we're done */
|
||||||
} else if ( iter->position == position - 1 ) {
|
} else if ( iter->position == position - 1 ) {
|
||||||
success = dict_getNextWord( iter );
|
success = di_getNextWord( iter );
|
||||||
} else if ( iter->position == position + 1 ) {
|
} else if ( iter->position == position + 1 ) {
|
||||||
success = dict_getPrevWord( iter );
|
success = di_getPrevWord( iter );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -614,9 +614,9 @@ dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth,
|
||||||
|
|
||||||
if ( !validWord ) {
|
if ( !validWord ) {
|
||||||
if ( position >= wordCount ) {
|
if ( position >= wordCount ) {
|
||||||
dict_lastWord( iter );
|
di_lastWord( iter );
|
||||||
} else {
|
} else {
|
||||||
dict_firstWord( iter );
|
di_firstWord( iter );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wordIndex = iter->position;
|
wordIndex = iter->position;
|
||||||
|
@ -642,14 +642,14 @@ dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
} /* dict_getNthWord */
|
} /* di_getNthWord */
|
||||||
|
|
||||||
static DictPosition
|
static DictPosition
|
||||||
figurePosition( DictIter* iter )
|
figurePosition( DictIter* iter )
|
||||||
{
|
{
|
||||||
DictPosition result = 0;
|
DictPosition result = 0;
|
||||||
DictIter iterZero;
|
DictIter iterZero;
|
||||||
dict_initIterFrom( &iterZero, iter );
|
initIterFrom( &iterZero, iter );
|
||||||
if ( !firstWord( &iterZero ) ) {
|
if ( !firstWord( &iterZero ) ) {
|
||||||
XP_ASSERT( 0 );
|
XP_ASSERT( 0 );
|
||||||
}
|
}
|
||||||
|
@ -665,7 +665,7 @@ figurePosition( DictIter* iter )
|
||||||
}
|
}
|
||||||
|
|
||||||
XP_S16
|
XP_S16
|
||||||
dict_findStartsWith( DictIter* iter, const XP_UCHAR* prefix )
|
di_findStartsWith( DictIter* iter, const XP_UCHAR* prefix )
|
||||||
{
|
{
|
||||||
ASSERT_INITED( iter );
|
ASSERT_INITED( iter );
|
||||||
array_edge* edge = dict_getTopEdge( iter->dict );
|
array_edge* edge = dict_getTopEdge( iter->dict );
|
||||||
|
@ -688,14 +688,14 @@ dict_findStartsWith( DictIter* iter, const XP_UCHAR* prefix )
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dict_wordToString( const DictIter* iter, XP_UCHAR* buf, XP_U16 buflen )
|
di_wordToString( const DictIter* iter, XP_UCHAR* buf, XP_U16 buflen )
|
||||||
{
|
{
|
||||||
ASSERT_INITED( iter );
|
ASSERT_INITED( iter );
|
||||||
iterToString( iter, buf, buflen );
|
iterToString( iter, buf, buflen );
|
||||||
}
|
}
|
||||||
|
|
||||||
DictPosition
|
DictPosition
|
||||||
dict_getPosition( const DictIter* iter )
|
di_getPosition( const DictIter* iter )
|
||||||
{
|
{
|
||||||
ASSERT_INITED( iter );
|
ASSERT_INITED( iter );
|
||||||
return iter->position;
|
return iter->position;
|
||||||
|
|
|
@ -63,19 +63,19 @@ typedef struct _LengthsArray {
|
||||||
XP_U32 lens[MAX_COLS_DICT+1];
|
XP_U32 lens[MAX_COLS_DICT+1];
|
||||||
} LengthsArray;
|
} LengthsArray;
|
||||||
|
|
||||||
void dict_initIter( DictIter* iter, const DictionaryCtxt* dict,
|
void di_initIter( DictIter* iter, const DictionaryCtxt* dict,
|
||||||
XP_U16 min, XP_U16 max );
|
XP_U16 min, XP_U16 max );
|
||||||
XP_U32 dict_countWords( const DictIter* iter, LengthsArray* lens );
|
XP_U32 di_countWords( const DictIter* iter, LengthsArray* lens );
|
||||||
void dict_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data );
|
void di_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data );
|
||||||
XP_Bool dict_firstWord( DictIter* iter );
|
XP_Bool di_firstWord( DictIter* iter );
|
||||||
XP_Bool dict_lastWord( DictIter* iter );
|
XP_Bool di_lastWord( DictIter* iter );
|
||||||
XP_Bool dict_getNextWord( DictIter* iter );
|
XP_Bool di_getNextWord( DictIter* iter );
|
||||||
XP_Bool dict_getPrevWord( DictIter* iter );
|
XP_Bool di_getPrevWord( DictIter* iter );
|
||||||
XP_Bool dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth,
|
XP_Bool di_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth,
|
||||||
const IndexData* data );
|
const IndexData* data );
|
||||||
void dict_wordToString( const DictIter* iter, XP_UCHAR* buf, XP_U16 buflen );
|
void di_wordToString( const DictIter* iter, XP_UCHAR* buf, XP_U16 buflen );
|
||||||
XP_S16 dict_findStartsWith( DictIter* iter, const XP_UCHAR* prefix );
|
XP_S16 di_findStartsWith( DictIter* iter, const XP_UCHAR* prefix );
|
||||||
DictPosition dict_getPosition( const DictIter* iter );
|
DictPosition di_getPosition( const DictIter* iter );
|
||||||
#ifdef CPLUS
|
#ifdef CPLUS
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -844,8 +844,8 @@ dict_getWordCount( const DictionaryCtxt* dict )
|
||||||
#ifdef XWFEATURE_WALKDICT
|
#ifdef XWFEATURE_WALKDICT
|
||||||
if ( 0 == nWords ) {
|
if ( 0 == nWords ) {
|
||||||
DictIter iter;
|
DictIter iter;
|
||||||
dict_initIter( &iter, dict, 0, MAX_COLS_DICT );
|
di_initIter( &iter, dict, 0, MAX_COLS_DICT );
|
||||||
nWords = dict_countWords( &iter, NULL );
|
nWords = di_countWords( &iter, NULL );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return nWords;
|
return nWords;
|
||||||
|
|
|
@ -1903,16 +1903,16 @@ testGetNthWord( const DictionaryCtxt* dict, char** XP_UNUSED_DBG(words),
|
||||||
XP_U32 ii, jj;
|
XP_U32 ii, jj;
|
||||||
DictIter iter;
|
DictIter iter;
|
||||||
|
|
||||||
dict_initIter( &iter, dict, min, max );
|
di_initIter( &iter, dict, min, max );
|
||||||
XP_U32 half = dict_countWords( &iter, NULL ) / 2;
|
XP_U32 half = di_countWords( &iter, NULL ) / 2;
|
||||||
XP_U32 interval = half / 100;
|
XP_U32 interval = half / 100;
|
||||||
if ( interval == 0 ) {
|
if ( interval == 0 ) {
|
||||||
++interval;
|
++interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( ii = 0, jj = half; ii < half; ii += interval, jj += interval ) {
|
for ( ii = 0, jj = half; ii < half; ii += interval, jj += interval ) {
|
||||||
if ( dict_getNthWord( &iter, ii, depth, data ) ) {
|
if ( di_getNthWord( &iter, ii, depth, data ) ) {
|
||||||
dict_wordToString( &iter, buf, VSIZE(buf) );
|
di_wordToString( &iter, buf, VSIZE(buf) );
|
||||||
XP_ASSERT( 0 == strcmp( buf, words[ii] ) );
|
XP_ASSERT( 0 == strcmp( buf, words[ii] ) );
|
||||||
# ifdef PRINT_ALL
|
# ifdef PRINT_ALL
|
||||||
XP_LOGF( "%s: word[%ld]: %s", __func__, ii, buf );
|
XP_LOGF( "%s: word[%ld]: %s", __func__, ii, buf );
|
||||||
|
@ -1920,8 +1920,8 @@ testGetNthWord( const DictionaryCtxt* dict, char** XP_UNUSED_DBG(words),
|
||||||
} else {
|
} else {
|
||||||
XP_ASSERT( 0 );
|
XP_ASSERT( 0 );
|
||||||
}
|
}
|
||||||
if ( dict_getNthWord( &iter, jj, depth, data ) ) {
|
if ( di_getNthWord( &iter, jj, depth, data ) ) {
|
||||||
dict_wordToString( &iter, buf, VSIZE(buf) );
|
di_wordToString( &iter, buf, VSIZE(buf) );
|
||||||
XP_ASSERT( 0 == strcmp( buf, words[jj] ) );
|
XP_ASSERT( 0 == strcmp( buf, words[jj] ) );
|
||||||
# ifdef PRINT_ALL
|
# ifdef PRINT_ALL
|
||||||
XP_LOGF( "%s: word[%ld]: %s", __func__, jj, buf );
|
XP_LOGF( "%s: word[%ld]: %s", __func__, jj, buf );
|
||||||
|
@ -1948,9 +1948,9 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict,
|
||||||
max = MAX_COLS_DICT;
|
max = MAX_COLS_DICT;
|
||||||
}
|
}
|
||||||
|
|
||||||
dict_initIter( &iter, dict, min, max );
|
di_initIter( &iter, dict, min, max );
|
||||||
LengthsArray lens;
|
LengthsArray lens;
|
||||||
XP_U32 count = dict_countWords( &iter, &lens );
|
XP_U32 count = di_countWords( &iter, &lens );
|
||||||
|
|
||||||
XP_U32 sum = 0;
|
XP_U32 sum = 0;
|
||||||
for ( jj = 0; jj < VSIZE(lens.lens); ++jj ) {
|
for ( jj = 0; jj < VSIZE(lens.lens); ++jj ) {
|
||||||
|
@ -1963,12 +1963,12 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict,
|
||||||
char** words = g_malloc( count * sizeof(char*) );
|
char** words = g_malloc( count * sizeof(char*) );
|
||||||
XP_ASSERT( !!words );
|
XP_ASSERT( !!words );
|
||||||
|
|
||||||
for ( jj = 0, gotOne = dict_firstWord( &iter );
|
for ( jj = 0, gotOne = di_firstWord( &iter );
|
||||||
gotOne;
|
gotOne;
|
||||||
gotOne = dict_getNextWord( &iter ) ) {
|
gotOne = di_getNextWord( &iter ) ) {
|
||||||
XP_ASSERT( dict_getPosition( &iter ) == jj );
|
XP_ASSERT( di_getPosition( &iter ) == jj );
|
||||||
XP_UCHAR buf[64];
|
XP_UCHAR buf[64];
|
||||||
dict_wordToString( &iter, buf, VSIZE(buf) );
|
di_wordToString( &iter, buf, VSIZE(buf) );
|
||||||
# ifdef PRINT_ALL
|
# ifdef PRINT_ALL
|
||||||
fprintf( stderr, "%.6ld: %s\n", jj, buf );
|
fprintf( stderr, "%.6ld: %s\n", jj, buf );
|
||||||
# endif
|
# endif
|
||||||
|
@ -1979,12 +1979,12 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict,
|
||||||
}
|
}
|
||||||
XP_ASSERT( count == jj );
|
XP_ASSERT( count == jj );
|
||||||
|
|
||||||
for ( jj = 0, gotOne = dict_lastWord( &iter );
|
for ( jj = 0, gotOne = di_lastWord( &iter );
|
||||||
gotOne;
|
gotOne;
|
||||||
++jj, gotOne = dict_getPrevWord( &iter ) ) {
|
++jj, gotOne = di_getPrevWord( &iter ) ) {
|
||||||
XP_ASSERT( dict_getPosition(&iter) == count-jj-1 );
|
XP_ASSERT( di_getPosition(&iter) == count-jj-1 );
|
||||||
XP_UCHAR buf[64];
|
XP_UCHAR buf[64];
|
||||||
dict_wordToString( &iter, buf, VSIZE(buf) );
|
di_wordToString( &iter, buf, VSIZE(buf) );
|
||||||
# ifdef PRINT_ALL
|
# ifdef PRINT_ALL
|
||||||
fprintf( stderr, "%.6ld: %s\n", jj, buf );
|
fprintf( stderr, "%.6ld: %s\n", jj, buf );
|
||||||
# endif
|
# endif
|
||||||
|
@ -2012,7 +2012,7 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict,
|
||||||
depth * data.count * sizeof(data.prefixes[0]) );
|
depth * data.count * sizeof(data.prefixes[0]) );
|
||||||
|
|
||||||
XP_LOGF( "making index..." );
|
XP_LOGF( "making index..." );
|
||||||
dict_makeIndex( &iter, depth, &data );
|
di_makeIndex( &iter, depth, &data );
|
||||||
XP_LOGF( "DONE making index" );
|
XP_LOGF( "DONE making index" );
|
||||||
|
|
||||||
data.indices = XP_REALLOC( mpool, data.indices,
|
data.indices = XP_REALLOC( mpool, data.indices,
|
||||||
|
@ -2047,22 +2047,22 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict,
|
||||||
guint count = g_slist_length( testPrefixes );
|
guint count = g_slist_length( testPrefixes );
|
||||||
for ( ii = 0; ii < count; ++ii ) {
|
for ( ii = 0; ii < count; ++ii ) {
|
||||||
gchar* prefix = (gchar*)g_slist_nth_data( testPrefixes, ii );
|
gchar* prefix = (gchar*)g_slist_nth_data( testPrefixes, ii );
|
||||||
XP_S16 lenMatched = dict_findStartsWith( &iter, prefix );
|
XP_S16 lenMatched = di_findStartsWith( &iter, prefix );
|
||||||
if ( 0 <= lenMatched ) {
|
if ( 0 <= lenMatched ) {
|
||||||
XP_UCHAR buf[32];
|
XP_UCHAR buf[32];
|
||||||
XP_UCHAR bufPrev[32] = {0};
|
XP_UCHAR bufPrev[32] = {0};
|
||||||
dict_wordToString( &iter, buf, VSIZE(buf) );
|
di_wordToString( &iter, buf, VSIZE(buf) );
|
||||||
|
|
||||||
/* This doesn't work with synonyms like "L-L" for "L·L" */
|
/* This doesn't work with synonyms like "L-L" for "L·L" */
|
||||||
// XP_ASSERT( 0 == strncasecmp( buf, prefix, lenMatched ) );
|
// XP_ASSERT( 0 == strncasecmp( buf, prefix, lenMatched ) );
|
||||||
|
|
||||||
DictPosition pos = dict_getPosition( &iter );
|
DictPosition pos = di_getPosition( &iter );
|
||||||
XP_ASSERT( 0 == strcmp( buf, words[pos] ) );
|
XP_ASSERT( 0 == strcmp( buf, words[pos] ) );
|
||||||
if ( pos > 0 ) {
|
if ( pos > 0 ) {
|
||||||
if ( !dict_getNthWord( &iter, pos-1, depth, &data ) ) {
|
if ( !di_getNthWord( &iter, pos-1, depth, &data ) ) {
|
||||||
XP_ASSERT( 0 );
|
XP_ASSERT( 0 );
|
||||||
}
|
}
|
||||||
dict_wordToString( &iter, bufPrev, VSIZE(bufPrev) );
|
di_wordToString( &iter, bufPrev, VSIZE(bufPrev) );
|
||||||
XP_ASSERT( 0 == strcmp( bufPrev, words[pos-1] ) );
|
XP_ASSERT( 0 == strcmp( bufPrev, words[pos-1] ) );
|
||||||
}
|
}
|
||||||
XP_LOGF( "dict_getStartsWith(%s) => %s (prev=%s)",
|
XP_LOGF( "dict_getStartsWith(%s) => %s (prev=%s)",
|
||||||
|
@ -2103,12 +2103,12 @@ static void
|
||||||
dumpDict( DictionaryCtxt* dict )
|
dumpDict( DictionaryCtxt* dict )
|
||||||
{
|
{
|
||||||
DictIter iter;
|
DictIter iter;
|
||||||
dict_initIter( &iter, dict, 0, MAX_COLS_DICT );
|
di_initIter( &iter, dict, 0, MAX_COLS_DICT );
|
||||||
for ( XP_Bool result = dict_firstWord( &iter );
|
for ( XP_Bool result = di_firstWord( &iter );
|
||||||
result;
|
result;
|
||||||
result = dict_getNextWord( &iter ) ) {
|
result = di_getNextWord( &iter ) ) {
|
||||||
XP_UCHAR buf[32];
|
XP_UCHAR buf[32];
|
||||||
dict_wordToString( &iter, buf, VSIZE(buf) );
|
di_wordToString( &iter, buf, VSIZE(buf) );
|
||||||
fprintf( stdout, "%s\n", buf );
|
fprintf( stdout, "%s\n", buf );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue