#include "postgres.h"
#include "catalog/pg_type.h"
#include "mb/pg_wchar.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/memutils.h"
#include "daitch_mokotoff.h"
Go to the source code of this file.
|
| static bool | daitch_mokotoff_coding (const char *word, ArrayBuildState *soundex) |
| |
| | PG_FUNCTION_INFO_V1 (daitch_mokotoff) |
| |
| Datum | daitch_mokotoff (PG_FUNCTION_ARGS) |
| |
| static void | initialize_node (dm_node *node, int last_update) |
| |
| static void | add_next_code_digit (dm_node *node, int code_index, char code_digit) |
| |
| static void | set_leaf (dm_node *first_node[2], dm_node *last_node[2], dm_node *node, int ix_node) |
| |
| static dm_node * | find_or_create_child_node (dm_node *parent, char code_digit, ArrayBuildState *soundex) |
| |
| static void | update_node (dm_node *first_node[2], dm_node *last_node[2], dm_node *node, int ix_node, int letter_no, int prev_code_index, int next_code_index, const char *next_code_digits, int digit_no, ArrayBuildState *soundex) |
| |
| static void | update_leaves (dm_node *first_node[2], int *ix_node, int letter_no, const dm_codes *codes, const dm_codes *next_codes, ArrayBuildState *soundex) |
| |
| static char | read_char (const unsigned char *str, int *ix) |
| |
| static char | read_valid_char (const char *str, int *ix) |
| |
| static const dm_codes * | read_letter (const char *str, int *ix) |
| |
◆ DM_CODE_DIGITS
◆ dm_node
◆ add_next_code_digit()
◆ daitch_mokotoff()
Definition at line 123 of file daitch_mokotoff.c.
124{
131
132
134 "daitch_mokotoff temporary context",
137
138
141
142
144
146 {
147
151 }
152
154
157
159}
ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
static bool daitch_mokotoff_coding(const char *word, ArrayBuildState *soundex)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_DATUM(x)
Datum soundex(PG_FUNCTION_ARGS)
char * pg_server_to_any(const char *s, int len, int encoding)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
char * text_to_cstring(const text *t)
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, arg, CurrentMemoryContext, daitch_mokotoff_coding(), fb(), initArrayResult(), makeArrayResult(), MemoryContextDelete(), MemoryContextSwitchTo(), PG_GETARG_TEXT_PP, PG_RETURN_DATUM, PG_RETURN_NULL, pg_server_to_any(), PG_UTF8, soundex(), text_to_cstring(), and VARSIZE_ANY_EXHDR().
◆ daitch_mokotoff_coding()
Definition at line 519 of file daitch_mokotoff.c.
520{
527 *node;
528
529
531 {
532
533 return false;
534 }
535
536
539
540
541
542
543
545 {
547
548
552
555 }
556
557
559 {
562
565 false,
568 }
569
570 return true;
571}
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
static const dm_node start_node
static const dm_codes end_codes[2]
static const dm_codes * read_letter(const char *str, int *ix)
static void update_leaves(dm_node *first_node[2], int *ix_node, int letter_no, const dm_codes *codes, const dm_codes *next_codes, ArrayBuildState *soundex)
#define palloc_object(type)
#define PointerGetDatum(X)
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
char soundex[DM_CODE_DIGITS]
text * cstring_to_text_with_len(const char *s, int len)
References accumArrayResult(), cstring_to_text_with_len(), CurrentMemoryContext, DM_CODE_DIGITS, end_codes, fb(), i, dm_node::next, palloc_object, PointerGetDatum, read_letter(), soundex(), dm_node::soundex, start_node, update_leaves(), and word().
Referenced by daitch_mokotoff().
◆ find_or_create_child_node()
Definition at line 216 of file daitch_mokotoff.c.
218{
219 int i = code_digit -
'0';
222
223 if (node)
224 {
225
227 }
228
229
232
239
241 {
242 return node;
243 }
244 else
245 {
246
249
252 false,
256 }
257}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
struct dm_node * children[10]
References accumArrayResult(), dm_node::children, dm_node::code_digit, cstring_to_text_with_len(), CurrentMemoryContext, DM_CODE_DIGITS, fb(), i, memcpy(), dm_node::next_code_index, palloc_object, PointerGetDatum, dm_node::prev_code_index, soundex(), dm_node::soundex, dm_node::soundex_length, and start_node.
Referenced by update_node().
◆ initialize_node()
◆ PG_FUNCTION_INFO_V1()
◆ read_char()
Definition at line 396 of file daitch_mokotoff.c.
397{
398
399 const char na =
'\x1a';
401
402
405
406
409
410
411 if (
c >= (
unsigned char)
'[' &&
c <= (
unsigned char)
']')
412 {
413
415 }
417 {
418
420 }
422 {
423
425 }
426 else
427 {
428
430 {
431 case 0x0104:
432 case 0x0105:
433 return '[';
434 case 0x0118:
435 case 0x0119:
436 return '\\';
437 case 0x0162:
438 case 0x0163:
439 case 0x021A:
440 case 0x021B:
441 return ']';
442 default:
444 }
445 }
446}
static const char iso8859_1_to_ascii_upper[]
static char32_t utf8_to_unicode(const unsigned char *c)
References fb(), iso8859_1_to_ascii_upper, pg_utf_mblen, str, and utf8_to_unicode().
Referenced by read_valid_char().
◆ read_letter()
Definition at line 467 of file daitch_mokotoff.c.
468{
475
476
479
483
484
486 {
488 {
490 {
491
494 {
495
498 }
499 break;
500 }
501 }
503 {
504
505 break;
506 }
507 }
508
510}
static char read_valid_char(const char *str, int *ix)
static int cmp(const chr *x, const chr *y, size_t len)
References cmp(), fb(), i, j, read_valid_char(), and str.
Referenced by daitch_mokotoff_coding().
◆ read_valid_char()
◆ set_leaf()
◆ update_leaves()
Definition at line 332 of file daitch_mokotoff.c.
335{
344
345
348
349
351 {
352
353 for (
i = 0;
i < 2 && (code =
codes[
i]) && code[0][0];
i++)
354 {
355
356 int prev_code_index = (code[0][0] > '1') + 1;
357
358
360 {
361
363 {
364
366 }
368 {
369
371 }
372 else
373 {
374
376 }
377
378
383 }
384 }
385 }
386
388}
static void update_node(dm_node *first_node[2], dm_node *last_node[2], dm_node *node, int ix_node, int letter_no, int prev_code_index, int next_code_index, const char *next_code_digits, int digit_no, ArrayBuildState *soundex)
References fb(), i, j, dm_node::next, dm_node::prev_code_index, soundex(), and update_node().
Referenced by daitch_mokotoff_coding().
◆ update_node()
Definition at line 262 of file daitch_mokotoff.c.
267{
272
274
276 {
277
278
279
280
281
282
283 return;
284 }
285
290 {
291
293 }
294
299 {
300
302 if (node)
303 {
306 }
307 }
308
310 {
311
313
315 {
317 letter_no, prev_code_index, next_code_index,
320 }
321 else
322 {
323
325 }
326 }
327}
static dm_node * find_or_create_child_node(dm_node *parent, char code_digit, ArrayBuildState *soundex)
static void add_next_code_digit(dm_node *node, int code_index, char code_digit)
static void set_leaf(dm_node *first_node[2], dm_node *last_node[2], dm_node *node, int ix_node)
static void initialize_node(dm_node *node, int last_update)
References add_next_code_digit(), fb(), find_or_create_child_node(), i, initialize_node(), dm_node::next_code_digits, dm_node::next_code_index, dm_node::prev_code_digits, dm_node::prev_code_index, set_leaf(), soundex(), and update_node().
Referenced by update_leaves(), and update_node().
◆ end_codes
◆ iso8859_1_to_ascii_upper
Initial value:=
"`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~ ! ?AAAAAAECEEEEIIIIDNOOOOO*OUUUUYDSAAAAAAECEEEEIIIIDNOOOOO/OUUUUYDY"
Definition at line 113 of file daitch_mokotoff.c.
Referenced by read_char().
◆ start_node
Initial value:= {
.soundex_length = 0,
.soundex = "000000",
.is_leaf = 0,
.last_update = 0,
.code_digit = '\0',
.prev_code_digits = {'\0', '\0'},
.next_code_digits = {'\0', '\0'},
.prev_code_index = 0,
.next_code_index = 0,
}
Definition at line 90 of file daitch_mokotoff.c.
90 {
91 .soundex_length = 0,
92 .soundex = "000000",
93 .is_leaf = 0,
94 .last_update = 0,
95 .code_digit = '\0',
96 .prev_code_digits = {'\0', '\0'},
97 .next_code_digits = {'\0', '\0'},
98 .prev_code_index = 0,
99 .next_code_index = 0,
102};
Referenced by daitch_mokotoff_coding(), and find_or_create_child_node().