1/*-------------------------------------------------------------------------
5 * Declarations for ISpell dictionary
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
9 * src/include/tsearch/dicts/spell.h
11 *-------------------------------------------------------------------------
22 * SPNode and SPNodeData are used to represent prefix tree (Trie) to store
31 /* Stores compound flags listed below */
33 /* Reference to an entry of the AffixData field */
39 * Names of FF_ are correlated with Hunspell options in affix file
40 * https://hunspell.github.io/
42 #define FF_COMPOUNDONLY 0x01
43 #define FF_COMPOUNDBEGIN 0x02
44 #define FF_COMPOUNDMIDDLE 0x04
45 #define FF_COMPOUNDLAST 0x08
46 #define FF_COMPOUNDFLAG ( FF_COMPOUNDBEGIN | FF_COMPOUNDMIDDLE | \
48 #define FF_COMPOUNDFLAGMASK 0x0f
56 #define SPNHDRSZ (offsetof(SPNode,data))
59 * Represents an entry in a words list.
66 * flag is filled in by NIImportDictionary(). After
67 * NISortDictionary(), d is used instead of flag.
70 /* d is used in mkSPNode() */
73 /* Reference to an entry of the AffixData field */
75 /* Length of the word */
82 #define SPELLHDRSZ (offsetof(SPELL, word))
85 * Represents an entry in an affix list.
90 /* FF_SUFFIX or FF_PREFIX */
101 * Arrays of AFFIX are moved and sorted. We'll use a pointer to
102 * regex_t to keep this struct small, and avoid assuming that regex_t
111 * affixes use dictionary flags too
113 #define FF_COMPOUNDPERMITFLAG 0x10
114 #define FF_COMPOUNDFORBIDFLAG 0x20
115 #define FF_CROSSPRODUCT 0x40
118 * Don't change the order of these. Initialization sorts by these,
119 * and expects prefixes to come first after sorting.
125 * AffixNode and AffixNodeData are used to represent prefix tree (Trie) to store
145 #define ANHRDSZ (offsetof(AffixNode, data))
155 * Type of encoding affix flags in Hunspell dictionaries
165 * Structure to store Hunspell options. Flag representation depends on flag
166 * type. These flags are about support of compound words.
172 /* Flag name if flagMode is FM_CHAR or FM_LONG */
174 /* Flag name if flagMode is FM_NUM */
177 /* we don't have a bsearch_arg version, so, copy FlagMode */
182 #define FLAGNUM_MAXSIZE (1 << 16)
194 /* Array of sets of affixes */
206 * All follow fields are actually needed only for initialization
209 /* Array of Hunspell options in affix file */
211 /* number of entries in CompoundAffixFlags array */
213 /* allocated length of CompoundAffixFlags array */
217 * Remaining fields are only used during dictionary construction; they are
218 * set up by NIStartBuild and cleared by NIFinishBuild.
222 /* Temporary array of all words in the dict file */
224 int nspell;
/* number of valid entries in Spell array */
225 int mspell;
/* allocated length of Spell array */
227 /* These are used to allocate "compact" data without palloc overhead */
228 char *
firstfree;
/* first free address (always maxaligned) */
229 size_t avail;
/* free space remaining at firstfree */
#define FLEXIBLE_ARRAY_MEMBER
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
void NIStartBuild(IspellDict *Conf)
void NIFinishBuild(IspellDict *Conf)
void NIImportAffixes(IspellDict *Conf, const char *filename)
void NISortDictionary(IspellDict *Conf)
struct CompoundAffixFlag CompoundAffixFlag
void NISortAffixes(IspellDict *Conf)
struct spell_struct SPELL
void NIImportDictionary(IspellDict *Conf, const char *filename)
TSLexeme * NINormalizeWord(IspellDict *Conf, const char *word)
struct AffixNode AffixNode
AffixNodeData data[FLEXIBLE_ARRAY_MEMBER]
union CompoundAffixFlag::@142 flag
CompoundAffixFlag * CompoundAffixFlags
CMPDAffix * CompoundAffix
SPNodeData data[FLEXIBLE_ARRAY_MEMBER]
union aff_struct::@141 reg
union spell_struct::@139 p
struct spell_struct::@139::@140 d
char word[FLEXIBLE_ARRAY_MEMBER]