mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
Merge branch 'android_branch' into android_browsedict
This commit is contained in:
commit
ff3a8d4179
3 changed files with 47 additions and 45 deletions
|
@ -863,20 +863,19 @@ dict_countWords( const DictionaryCtxt* dict )
|
||||||
|
|
||||||
static DictIndex
|
static DictIndex
|
||||||
placeWordClose( const DictionaryCtxt* dict, DictIndex position,
|
placeWordClose( const DictionaryCtxt* dict, DictIndex position,
|
||||||
XP_U16 depth, const DictIndex* indices, const Tile* prefixes,
|
XP_U16 depth, IndexData* data, EdgeArray* result )
|
||||||
XP_U16 count, EdgeArray* result )
|
|
||||||
{
|
{
|
||||||
XP_S16 low = 0;
|
XP_S16 low = 0;
|
||||||
XP_S16 high = count - 1;
|
XP_S16 high = data->count - 1;
|
||||||
XP_S16 index = -1;
|
XP_S16 index = -1;
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
if ( low > high ) {
|
if ( low > high ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index = low + ( (high - low) / 2);
|
index = low + ( (high - low) / 2);
|
||||||
if ( position < indices[index] ) {
|
if ( position < data->indices[index] ) {
|
||||||
high = index - 1;
|
high = index - 1;
|
||||||
} else if ( indices[index+1] <= position) {
|
} else if ( data->indices[index+1] <= position) {
|
||||||
low = index + 1;
|
low = index + 1;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
@ -891,22 +890,23 @@ placeWordClose( const DictionaryCtxt* dict, DictIndex position,
|
||||||
may be better off starting with the next if it's closer. The last
|
may be better off starting with the next if it's closer. The last
|
||||||
index is a special case since we use lastWord rather than a prefix to
|
index is a special case since we use lastWord rather than a prefix to
|
||||||
init */
|
init */
|
||||||
if ( ( index + 1 < count )
|
if ( ( index + 1 < data->count )
|
||||||
&& (indices[index + 1] - position) < (position - indices[index]) ) {
|
&& (data->indices[index + 1] - position)
|
||||||
|
< (position - data->indices[index]) ) {
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
XP_Bool success = findStartsWith( dict, &prefixes[depth*index], depth, result )
|
XP_Bool success = findStartsWith( dict, &data->prefixes[depth*index],
|
||||||
|
depth, result )
|
||||||
&& ( ISACCEPTING( dict, result->edges[result->nEdges-1] )
|
&& ( ISACCEPTING( dict, result->edges[result->nEdges-1] )
|
||||||
|| nextWord( dict, result ) );
|
|| nextWord( dict, result ) );
|
||||||
XP_ASSERT( success );
|
XP_ASSERT( success );
|
||||||
|
|
||||||
return indices[index];
|
return data->indices[index];
|
||||||
} /* placeWordClose */
|
} /* placeWordClose */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
indexOne( const DictionaryCtxt* dict, XP_U16 depth, Tile* tiles,
|
indexOne( const DictionaryCtxt* dict, XP_U16 depth, Tile* tiles,
|
||||||
DictIndex* indices, Tile* prefixes, XP_U16* nextIndex,
|
IndexData* data, EdgeArray* prevEdges, DictIndex* prevIndex )
|
||||||
EdgeArray* prevEdges, DictIndex* prevIndex )
|
|
||||||
{
|
{
|
||||||
EdgeArray curEdges = { .nEdges = 0 };
|
EdgeArray curEdges = { .nEdges = 0 };
|
||||||
if ( findStartsWith( dict, tiles, depth, &curEdges ) ) {
|
if ( findStartsWith( dict, tiles, depth, &curEdges ) ) {
|
||||||
|
@ -927,37 +927,34 @@ indexOne( const DictionaryCtxt* dict, XP_U16 depth, Tile* tiles,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indices[*nextIndex] = *prevIndex;
|
data->indices[data->count] = *prevIndex;
|
||||||
if ( NULL != prefixes ) {
|
if ( NULL != data->prefixes ) {
|
||||||
XP_MEMCPY( prefixes + (*nextIndex * depth), tiles, depth );
|
XP_MEMCPY( data->prefixes + (data->count * depth), tiles, depth );
|
||||||
}
|
}
|
||||||
++*nextIndex;
|
++data->count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
doOneDepth( const DictionaryCtxt* dict,
|
doOneDepth( const DictionaryCtxt* dict,
|
||||||
const Tile* allTiles, XP_U16 nTiles, Tile* prefix,
|
const Tile* allTiles, XP_U16 nTiles, Tile* prefix,
|
||||||
XP_U16 curDepth, XP_U16 maxDepth,
|
XP_U16 curDepth, XP_U16 maxDepth, IndexData* data,
|
||||||
DictIndex* indices, Tile* prefixes, XP_U16* nextEntry,
|
|
||||||
EdgeArray* prevEdges, DictIndex* prevIndex )
|
EdgeArray* prevEdges, DictIndex* prevIndex )
|
||||||
{
|
{
|
||||||
XP_U16 ii;
|
XP_U16 ii;
|
||||||
for ( ii = 0; ii < nTiles; ++ii ) {
|
for ( ii = 0; ii < nTiles; ++ii ) {
|
||||||
prefix[curDepth] = allTiles[ii];
|
prefix[curDepth] = allTiles[ii];
|
||||||
if ( curDepth + 1 == maxDepth ) {
|
if ( curDepth + 1 == maxDepth ) {
|
||||||
indexOne( dict, maxDepth, prefix, indices, prefixes,
|
indexOne( dict, maxDepth, prefix, data, prevEdges, prevIndex );
|
||||||
nextEntry, prevEdges, prevIndex);
|
|
||||||
} else {
|
} else {
|
||||||
doOneDepth( dict, allTiles, nTiles, prefix, curDepth+1, maxDepth,
|
doOneDepth( dict, allTiles, nTiles, prefix, curDepth+1, maxDepth,
|
||||||
indices, prefixes, nextEntry, prevEdges, prevIndex );
|
data, prevEdges, prevIndex );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XP_U16
|
void
|
||||||
dict_makeIndex( const DictionaryCtxt* dict, XP_U16 depth,
|
dict_makeIndex( const DictionaryCtxt* dict, XP_U16 depth, IndexData* data )
|
||||||
DictIndex* indices, Tile* prefixes, XP_U16 count )
|
|
||||||
{
|
{
|
||||||
XP_ASSERT( depth < MAX_COLS );
|
XP_ASSERT( depth < MAX_COLS );
|
||||||
XP_U16 ii, needCount, nTiles;
|
XP_U16 ii, needCount, nTiles;
|
||||||
|
@ -969,7 +966,7 @@ dict_makeIndex( const DictionaryCtxt* dict, XP_U16 depth,
|
||||||
for ( ii = 1, needCount = nFaces; ii < depth; ++ii ) {
|
for ( ii = 1, needCount = nFaces; ii < depth; ++ii ) {
|
||||||
needCount *= nFaces;
|
needCount *= nFaces;
|
||||||
}
|
}
|
||||||
XP_ASSERT( needCount <= count );
|
XP_ASSERT( needCount <= data->count );
|
||||||
|
|
||||||
Tile allTiles[nFaces];
|
Tile allTiles[nFaces];
|
||||||
nTiles = 0;
|
nTiles = 0;
|
||||||
|
@ -984,7 +981,7 @@ dict_makeIndex( const DictionaryCtxt* dict, XP_U16 depth,
|
||||||
* find the first word starting with that IF EXISTS. If it does, find its
|
* find the first word starting with that IF EXISTS. If it does, find its
|
||||||
* index. As an optimization, find index starting with the previous word.
|
* index. As an optimization, find index starting with the previous word.
|
||||||
*/
|
*/
|
||||||
XP_U16 nextIndex = 0;
|
data->count = 0;
|
||||||
DictWord firstWord;
|
DictWord firstWord;
|
||||||
if ( dict_firstWord( dict, &firstWord ) ) {
|
if ( dict_firstWord( dict, &firstWord ) ) {
|
||||||
EdgeArray prevEdges;
|
EdgeArray prevEdges;
|
||||||
|
@ -993,10 +990,9 @@ dict_makeIndex( const DictionaryCtxt* dict, XP_U16 depth,
|
||||||
indicesToEdges( dict, &firstWord, &prevEdges );
|
indicesToEdges( dict, &firstWord, &prevEdges );
|
||||||
|
|
||||||
doOneDepth( dict, allTiles, nFaces, prefix, 0, depth,
|
doOneDepth( dict, allTiles, nFaces, prefix, 0, depth,
|
||||||
indices, prefixes, &nextIndex, &prevEdges, &prevIndex );
|
data, &prevEdges, &prevIndex );
|
||||||
|
|
||||||
}
|
}
|
||||||
return nextIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1064,8 +1060,7 @@ dict_getPrevWord( const DictionaryCtxt* dict, DictWord* word )
|
||||||
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( const DictionaryCtxt* dict, DictWord* word, XP_U32 nn,
|
dict_getNthWord( const DictionaryCtxt* dict, DictWord* word, XP_U32 nn,
|
||||||
XP_U16 depth, DictIndex* indices, Tile* prefixes,
|
XP_U16 depth, IndexData* data )
|
||||||
XP_U16 count )
|
|
||||||
{
|
{
|
||||||
XP_U32 wordCount;
|
XP_U32 wordCount;
|
||||||
XP_Bool validWord = 0 < word->nTiles;
|
XP_Bool validWord = 0 < word->nTiles;
|
||||||
|
@ -1093,9 +1088,8 @@ dict_getNthWord( const DictionaryCtxt* dict, DictWord* word, XP_U32 nn,
|
||||||
if ( !success ) {
|
if ( !success ) {
|
||||||
EdgeArray edges;
|
EdgeArray edges;
|
||||||
XP_U32 wordIndex;
|
XP_U32 wordIndex;
|
||||||
if ( !!indices ) {
|
if ( !!data ) {
|
||||||
wordIndex = placeWordClose( dict, nn, depth, indices,
|
wordIndex = placeWordClose( dict, nn, depth, data, &edges );
|
||||||
prefixes, count, &edges );
|
|
||||||
if ( !validWord ) {
|
if ( !validWord ) {
|
||||||
initWord( dict, word );
|
initWord( dict, word );
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,16 +217,21 @@ typedef struct _DictWord {
|
||||||
XP_U32 indices[MAX_COLS];
|
XP_U32 indices[MAX_COLS];
|
||||||
} DictWord;
|
} DictWord;
|
||||||
|
|
||||||
|
typedef struct _IndexData {
|
||||||
|
DictIndex* indices;
|
||||||
|
Tile* prefixes;
|
||||||
|
XP_U16 count; /* in-out: must indicate others are large enough */
|
||||||
|
} IndexData;
|
||||||
|
|
||||||
XP_U32 dict_countWords( const DictionaryCtxt* dict );
|
XP_U32 dict_countWords( const DictionaryCtxt* dict );
|
||||||
XP_U16 dict_makeIndex( const DictionaryCtxt* dict, XP_U16 depth,
|
void dict_makeIndex( const DictionaryCtxt* dict, XP_U16 depth,
|
||||||
DictIndex* indices, Tile* prefixes, XP_U16 count );
|
IndexData* data );
|
||||||
XP_Bool dict_firstWord( const DictionaryCtxt* dict, DictWord* word );
|
XP_Bool dict_firstWord( const DictionaryCtxt* dict, DictWord* word );
|
||||||
XP_Bool dict_lastWord( const DictionaryCtxt* dict, DictWord* word );
|
XP_Bool dict_lastWord( const DictionaryCtxt* dict, DictWord* word );
|
||||||
XP_Bool dict_getNextWord( const DictionaryCtxt* dict, DictWord* word );
|
XP_Bool dict_getNextWord( const DictionaryCtxt* dict, DictWord* word );
|
||||||
XP_Bool dict_getPrevWord( const DictionaryCtxt* dict, DictWord* word );
|
XP_Bool dict_getPrevWord( const DictionaryCtxt* dict, DictWord* word );
|
||||||
XP_Bool dict_getNthWord( const DictionaryCtxt* dict, DictWord* word, XP_U32 nn,
|
XP_Bool dict_getNthWord( const DictionaryCtxt* dict, DictWord* word, XP_U32 nn,
|
||||||
XP_U16 depth, DictIndex* indices,
|
XP_U16 depth, IndexData* data );
|
||||||
Tile* prefixes, XP_U16 count );
|
|
||||||
void dict_wordToString( const DictionaryCtxt* dict, const DictWord* word,
|
void dict_wordToString( const DictionaryCtxt* dict, const DictWord* word,
|
||||||
XP_UCHAR* buf, XP_U16 buflen );
|
XP_UCHAR* buf, XP_U16 buflen );
|
||||||
|
|
||||||
|
|
|
@ -895,8 +895,7 @@ tmp_noop_sigintterm( int XP_UNUSED(sig) )
|
||||||
#ifdef XWFEATURE_WALKDICT
|
#ifdef XWFEATURE_WALKDICT
|
||||||
static void
|
static void
|
||||||
testGetNthWord( const DictionaryCtxt* dict, char** words,
|
testGetNthWord( const DictionaryCtxt* dict, char** words,
|
||||||
XP_U16 depth, DictIndex* indices,
|
XP_U16 depth, IndexData* data )
|
||||||
Tile* prefixes, XP_U16 nIndices )
|
|
||||||
{
|
{
|
||||||
XP_U32 half = dict_getWordCount( dict ) / 2;
|
XP_U32 half = dict_getWordCount( dict ) / 2;
|
||||||
XP_UCHAR buf[64];
|
XP_UCHAR buf[64];
|
||||||
|
@ -905,13 +904,13 @@ testGetNthWord( const DictionaryCtxt* dict, char** words,
|
||||||
XP_U32 interval = 100;
|
XP_U32 interval = 100;
|
||||||
|
|
||||||
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( dict, &word, ii, depth, indices, prefixes, nIndices ) ) {
|
if ( dict_getNthWord( dict, &word, ii, depth, data ) ) {
|
||||||
dict_wordToString( dict, &word, buf, VSIZE(buf) );
|
dict_wordToString( dict, &word, buf, VSIZE(buf) );
|
||||||
XP_ASSERT( 0 == strcmp( buf, words[ii] ) );
|
XP_ASSERT( 0 == strcmp( buf, words[ii] ) );
|
||||||
} else {
|
} else {
|
||||||
XP_ASSERT( 0 );
|
XP_ASSERT( 0 );
|
||||||
}
|
}
|
||||||
if ( dict_getNthWord( dict, &word, jj, depth, indices, prefixes, nIndices ) ) {
|
if ( dict_getNthWord( dict, &word, jj, depth, data ) ) {
|
||||||
dict_wordToString( dict, &word, buf, VSIZE(buf) );
|
dict_wordToString( dict, &word, buf, VSIZE(buf) );
|
||||||
XP_ASSERT( 0 == strcmp( buf, words[jj] ) );
|
XP_ASSERT( 0 == strcmp( buf, words[jj] ) );
|
||||||
} else {
|
} else {
|
||||||
|
@ -979,16 +978,20 @@ walk_dict_test( const LaunchParams* params )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
XP_ASSERT( count == jj );
|
XP_ASSERT( count == jj );
|
||||||
XP_LOGF( "finished comparing runs in both directions\n" );
|
XP_LOGF( "finished comparing runs in both directions" );
|
||||||
|
|
||||||
XP_LOGF( "testing getNth" );
|
XP_LOGF( "testing getNth" );
|
||||||
testGetNthWord( dict, words, 0, NULL, NULL, 0 );
|
testGetNthWord( dict, words, 0, NULL );
|
||||||
|
|
||||||
XP_U16 depth = 2;
|
XP_U16 depth = 2;
|
||||||
DictIndex indices[26*26]; /* pow(26,depth) */
|
DictIndex indices[26*26]; /* pow(26,depth) */
|
||||||
Tile prefixes[depth*26*26];
|
Tile prefixes[depth*26*26];
|
||||||
XP_U16 nIndices = dict_makeIndex( dict, depth, indices,
|
IndexData data = { .indices = indices,
|
||||||
prefixes, VSIZE(indices) );
|
.prefixes = prefixes,
|
||||||
|
.count = VSIZE(indices)
|
||||||
|
};
|
||||||
|
dict_makeIndex( dict, depth, &data );
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
for ( ii = 0; ii < nIndices; ++ii ) {
|
for ( ii = 0; ii < nIndices; ++ii ) {
|
||||||
if ( !dict_getNthWord( dict, &word, indices[ii] ) ) {
|
if ( !dict_getNthWord( dict, &word, indices[ii] ) ) {
|
||||||
|
@ -1009,7 +1012,7 @@ walk_dict_test( const LaunchParams* params )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
XP_LOGF( "testing getNth WITH INDEXING" );
|
XP_LOGF( "testing getNth WITH INDEXING" );
|
||||||
testGetNthWord( dict, words, depth, indices, prefixes, nIndices );
|
testGetNthWord( dict, words, depth, &data );
|
||||||
|
|
||||||
XP_LOGF( "done" );
|
XP_LOGF( "done" );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
|
|
Loading…
Reference in a new issue