Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4b06c18

Browse files
committed
The data structure used in unaccent is a trie, not suffix tree.
Fix the term used in variable and struct names, and comments.Alexander Korotkov
1 parent2ffa66f commit4b06c18

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

‎contrib/unaccent/unaccent.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,29 @@
2323
PG_MODULE_MAGIC;
2424

2525
/*
26-
* Unaccent dictionary uses uncompressed suffix tree to find a
27-
* character to replace. Each node of tree is an array of
28-
* SuffixChar struct with length = 256 (n-th element of array
26+
* Unaccent dictionary uses a trie to find a character to replace. Each node of
27+
* the trie is an array of 256 TrieChar structs (n-th element of array
2928
* corresponds to byte)
3029
*/
31-
typedefstructSuffixChar
30+
typedefstructTrieChar
3231
{
33-
structSuffixChar*nextChar;
32+
structTrieChar*nextChar;
3433
char*replaceTo;
3534
intreplacelen;
36-
}SuffixChar;
35+
}TrieChar;
3736

3837
/*
39-
* placeChar - put str intotree's structure, byte by byte.
38+
* placeChar - put str intotrie's structure, byte by byte.
4039
*/
41-
staticSuffixChar*
42-
placeChar(SuffixChar*node,unsignedchar*str,intlenstr,char*replaceTo,intreplacelen)
40+
staticTrieChar*
41+
placeChar(TrieChar*node,unsignedchar*str,intlenstr,char*replaceTo,intreplacelen)
4342
{
44-
SuffixChar*curnode;
43+
TrieChar*curnode;
4544

4645
if (!node)
4746
{
48-
node=palloc(sizeof(SuffixChar)*256);
49-
memset(node,0,sizeof(SuffixChar)*256);
47+
node=palloc(sizeof(TrieChar)*256);
48+
memset(node,0,sizeof(TrieChar)*256);
5049
}
5150

5251
curnode=node+*str;
@@ -71,13 +70,14 @@ placeChar(SuffixChar *node, unsigned char *str, int lenstr, char *replaceTo, int
7170
}
7271

7372
/*
74-
* initSuffixTree - create suffix tree from file. Function converts
75-
* UTF8-encoded file into current encoding.
73+
* initTrie - create trie from file.
74+
*
75+
* Function converts UTF8-encoded file into current encoding.
7676
*/
77-
staticSuffixChar*
78-
initSuffixTree(char*filename)
77+
staticTrieChar*
78+
initTrie(char*filename)
7979
{
80-
SuffixChar*volatilerootSuffixTree=NULL;
80+
TrieChar*volatilerootTrie=NULL;
8181
MemoryContextccxt=CurrentMemoryContext;
8282
tsearch_readline_statetrst;
8383
volatileboolskip;
@@ -161,7 +161,7 @@ initSuffixTree(char *filename)
161161
}
162162

163163
if (state >=3)
164-
rootSuffixTree=placeChar(rootSuffixTree,
164+
rootTrie=placeChar(rootTrie,
165165
(unsignedchar*)src,srclen,
166166
trg,trglen);
167167

@@ -192,14 +192,14 @@ initSuffixTree(char *filename)
192192

193193
tsearch_readline_end(&trst);
194194

195-
returnrootSuffixTree;
195+
returnrootTrie;
196196
}
197197

198198
/*
199-
* findReplaceTo - find multibyte character intree
199+
* findReplaceTo - find multibyte character intrie
200200
*/
201-
staticSuffixChar*
202-
findReplaceTo(SuffixChar*node,unsignedchar*src,intsrclen)
201+
staticTrieChar*
202+
findReplaceTo(TrieChar*node,unsignedchar*src,intsrclen)
203203
{
204204
while (node)
205205
{
@@ -221,7 +221,7 @@ Datum
221221
unaccent_init(PG_FUNCTION_ARGS)
222222
{
223223
List*dictoptions= (List*)PG_GETARG_POINTER(0);
224-
SuffixChar*rootSuffixTree=NULL;
224+
TrieChar*rootTrie=NULL;
225225
boolfileloaded= false;
226226
ListCell*l;
227227

@@ -235,7 +235,7 @@ unaccent_init(PG_FUNCTION_ARGS)
235235
ereport(ERROR,
236236
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
237237
errmsg("multiple Rules parameters")));
238-
rootSuffixTree=initSuffixTree(defGetString(defel));
238+
rootTrie=initTrie(defGetString(defel));
239239
fileloaded= true;
240240
}
241241
else
@@ -254,29 +254,29 @@ unaccent_init(PG_FUNCTION_ARGS)
254254
errmsg("missing Rules parameter")));
255255
}
256256

257-
PG_RETURN_POINTER(rootSuffixTree);
257+
PG_RETURN_POINTER(rootTrie);
258258
}
259259

260260
PG_FUNCTION_INFO_V1(unaccent_lexize);
261261
Datumunaccent_lexize(PG_FUNCTION_ARGS);
262262
Datum
263263
unaccent_lexize(PG_FUNCTION_ARGS)
264264
{
265-
SuffixChar*rootSuffixTree= (SuffixChar*)PG_GETARG_POINTER(0);
265+
TrieChar*rootTrie= (TrieChar*)PG_GETARG_POINTER(0);
266266
char*srcchar= (char*)PG_GETARG_POINTER(1);
267267
int32len=PG_GETARG_INT32(2);
268268
char*srcstart,
269269
*trgchar=NULL;
270270
intcharlen;
271271
TSLexeme*res=NULL;
272-
SuffixChar*node;
272+
TrieChar*node;
273273

274274
srcstart=srcchar;
275275
while (srcchar-srcstart<len)
276276
{
277277
charlen=pg_mblen(srcchar);
278278

279-
node=findReplaceTo(rootSuffixTree, (unsignedchar*)srcchar,charlen);
279+
node=findReplaceTo(rootTrie, (unsignedchar*)srcchar,charlen);
280280
if (node&&node->replaceTo)
281281
{
282282
if (!res)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp