diff --git a/xwords4/common/dictiter.c b/xwords4/common/dictiter.c index 80d679cde..3446e835c 100644 --- a/xwords4/common/dictiter.c +++ b/xwords4/common/dictiter.c @@ -244,16 +244,24 @@ firstWord( DictIter* iter ) } XP_U32 -dict_countWords( const DictIter* iter ) +dict_countWords( const DictIter* iter, LengthsArray* lens ) { DictIter counter; dict_initIterFrom( &counter, iter ); + if ( NULL != lens ) { + XP_MEMSET( lens, 0, sizeof(*lens) ); + } + XP_U32 count; XP_Bool ok; for ( count = 0, ok = firstWord( &counter ); ok; ok = nextWord( &counter) ) { ++count; + + if ( NULL != lens ) { + ++lens->lens[counter.nEdges]; + } } return count; } @@ -438,7 +446,7 @@ dict_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data ) static void initWord( DictIter* iter ) { - iter->nWords = dict_countWords( iter ); + iter->nWords = dict_countWords( iter, NULL ); } XP_Bool @@ -505,7 +513,7 @@ dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth, XP_Bool validWord = 0 < iter->nEdges; if ( validWord ) { /* uninitialized */ wordCount = iter->nWords; - XP_ASSERT( wordCount == dict_countWords( iter ) ); + XP_ASSERT( wordCount == dict_countWords( iter, NULL ) ); } else { wordCount = dict_getWordCount( dict ); } diff --git a/xwords4/common/dictiter.h b/xwords4/common/dictiter.h index 14b258b4b..14b755bcf 100644 --- a/xwords4/common/dictiter.h +++ b/xwords4/common/dictiter.h @@ -59,9 +59,13 @@ typedef struct _IndexData { XP_U16 count; /* in-out: must indicate others are large enough */ } IndexData; +typedef struct _LengthsArray { + XP_U32 lens[MAX_COLS_DICT]; +} LengthsArray; + void dict_initIter( DictIter* iter, const DictionaryCtxt* dict, XP_U16 min, XP_U16 max ); -XP_U32 dict_countWords( const DictIter* iter ); +XP_U32 dict_countWords( const DictIter* iter, LengthsArray* lens ); void dict_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data ); XP_Bool dict_firstWord( DictIter* iter ); XP_Bool dict_lastWord( DictIter* iter ); diff --git a/xwords4/common/dictnry.c b/xwords4/common/dictnry.c index 3884ce0f2..3668debce 100644 --- a/xwords4/common/dictnry.c +++ b/xwords4/common/dictnry.c @@ -483,7 +483,7 @@ dict_getWordCount( const DictionaryCtxt* dict ) if ( 0 == nWords ) { DictIter iter; dict_initIter( &iter, dict, 0, MAX_COLS_DICT ); - nWords = dict_countWords( &iter ); + nWords = dict_countWords( &iter, NULL ); } #endif return nWords; diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index f2a602071..deae4a4d1 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -915,7 +915,7 @@ testGetNthWord( const DictionaryCtxt* dict, char** words, DictIter iter; dict_initIter( &iter, dict, min, max ); - XP_U32 half = dict_countWords( &iter ) / 2; + XP_U32 half = dict_countWords( &iter, NULL ) / 2; XP_U32 interval = half / 100; if ( interval == 0 ) { ++interval; @@ -960,7 +960,16 @@ walk_dict_test( const LaunchParams* params, const DictionaryCtxt* dict, } dict_initIter( &iter, dict, min, max ); - XP_U32 count = dict_countWords( &iter ); + LengthsArray lens; + XP_U32 count = dict_countWords( &iter, &lens ); + + XP_U32 sum = 0; + for ( jj = 0; jj < VSIZE(lens.lens); ++jj ) { + sum += lens.lens[jj]; + XP_LOGF( "%ld words of length %ld", lens.lens[jj], jj ); + } + XP_ASSERT( sum == count ); + if ( count > 0 ) { char** words = g_malloc( count * sizeof(char*) ); XP_ASSERT( !!words );