xwords/xwords4/common/dictiter.h
Eric House b2bc4e34cf do wordlist lookups using tiles not chars
Fixing a problem with languages (like Hungarian) where it's legal to use
a two-letter tile or two single-letter tiles to play the same word. When
words are seen, or searched for, as char-arrays, there are
duplicates. Current code crashes, but there's also risk the user gets
unexpected behavior. Crash is fixed, and foundation laid for better UX,
by doing all searches for tile arrays. If a search string translates to
more than one tile array the user must choose. For that choice to make
sense it's now possible to translate tile[] to char[] with a delimiter
between the tile strings.
2020-04-28 13:29:12 -07:00

86 lines
2.6 KiB
C

/* -*- compile-command: "cd ../linux && make MEMDEBUG=TRUE -j3"; -*- */
/*
* Copyright 1997 - 2011 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __DICTITER_H__
#define __DICTITER_H__
#ifdef XWFEATURE_WALKDICT
#include "comtypes.h"
#include "dawg.h"
#include "model.h"
#include "mempool.h"
#ifdef CPLUS
extern "C" {
#endif
#define MAX_COLS_DICT 15
/* API for iterating over a dict */
typedef XP_S32 DictPosition;
typedef struct _DictIter {
XP_U16 nEdges;
array_edge* edges[MAX_COLS_DICT];
#ifdef XWFEATURE_WALKDICT_FILTER
XP_U16 min;
XP_U16 max;
#endif
#ifdef DEBUG
XP_U32 guard;
#endif
const DictionaryCtxt* dict;
XP_U32 nWords;
DictPosition position;
} DictIter;
typedef struct _IndexData {
DictPosition* indices;
Tile* prefixes;
XP_U16 count; /* in-out: must indicate others are large enough */
} IndexData;
typedef struct _LengthsArray {
XP_U32 lens[MAX_COLS_DICT+1];
} LengthsArray;
void dict_initIter( DictIter* iter, const DictionaryCtxt* dict,
XP_U16 min, XP_U16 max );
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 );
XP_Bool dict_getNextWord( DictIter* iter );
XP_Bool dict_getPrevWord( DictIter* iter );
XP_Bool dict_getNthWord( DictIter* iter, DictPosition position, XP_U16 depth,
const IndexData* data );
void dict_wordToString( const DictIter* iter, XP_UCHAR* buf, XP_U16 buflen,
const XP_UCHAR* delim );
XP_S16 dict_findStartsWith( DictIter* iter, const Tile* prefix, XP_U16 nTiles );
void dict_stringToTiles( const XP_UCHAR* str, Tile out[], XP_U16* nTiles );
DictPosition dict_getPosition( const DictIter* iter );
#ifdef CPLUS
}
#endif
#endif /* XWFEATURE_WALKDICT */
#endif