59 #include "daitch_mokotoff.h"
61 #define DM_CODE_DIGITS 6
96 .prev_code_digits = {
'\0',
'\0'},
97 .next_code_digits = {
'\0',
'\0'},
114 "`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~ ! ?AAAAAAECEEEEIIIIDNOOOOO*OUUUUYDSAAAAAAECEEEEIIIIDNOOOOO/OUUUUYDY";
134 "daitch_mokotoff temporary context",
203 if (first_node[ix_node] == NULL)
204 first_node[ix_node] = node;
206 last_node[ix_node]->
next[ix_node] = node;
208 last_node[ix_node] = node;
209 node->
next[ix_node] = NULL;
270 int num_dirty_nodes = 0;
286 if (next_code_digit ==
'X' ||
292 dirty_nodes[num_dirty_nodes++] = node;
295 if (next_code_digit !=
'X' &&
305 dirty_nodes[num_dirty_nodes++] = node;
309 for (
i = 0;
i < num_dirty_nodes;
i++)
316 update_node(first_node, last_node, dirty_nodes[
i], ix_node,
324 set_leaf(first_node, last_node, dirty_nodes[
i], ix_node);
333 const dm_codes *codes,
const dm_codes *next_codes,
343 int ix_node_next = (*ix_node + 1) & 1;
346 first_node[ix_node_next] = NULL;
347 last_node[ix_node_next] = NULL;
350 for (node = first_node[*ix_node]; node; node = node->
next[*ix_node])
353 for (
i = 0;
i < 2 && (code = codes[
i]) && code[0][0];
i++)
359 for (
j = 0;
j < 2 && (next_code = next_codes[
j]) && next_code[0][0];
j++)
367 else if (next_code[0][0] <=
'1')
379 update_node(first_node, last_node, node, ix_node_next,
387 *ix_node = ix_node_next;
399 const char na =
'\x1a';
411 if (
c >= (
unsigned char)
'[' &&
c <= (
unsigned char)
']')
455 while ((
c =
read_char((
const unsigned char *)
str, ix)) !=
'\0')
457 if (
c >=
'A' &&
c <=
']')
466 static const dm_codes *
473 const dm_letter *letters;
474 const dm_codes *codes;
480 letters = &letter_[
c -
'A'];
481 codes = letters->codes;
487 for (
j = 0; (
cmp = letters[
j].letter);
j++)
492 letters = &letters[
j];
496 codes = letters->codes;
524 const dm_codes *codes,
544 while (codes && first_node[ix_node])
550 codes, next_codes ? next_codes :
end_codes,
558 for (node = first_node[ix_node]; node; node = node->
next[ix_node])
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
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)
PG_FUNCTION_INFO_V1(daitch_mokotoff)
static const char iso8859_1_to_ascii_upper[]
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 dm_node * find_or_create_child_node(dm_node *parent, char code_digit, ArrayBuildState *soundex)
static const dm_node start_node
Datum daitch_mokotoff(PG_FUNCTION_ARGS)
static const dm_codes end_codes[2]
static char read_char(const unsigned 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)
static const dm_codes * read_letter(const char *str, int *ix)
static void add_next_code_digit(dm_node *node, int code_index, char code_digit)
static char read_valid_char(const char *str, int *ix)
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)
#define palloc_object(type)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_DATUM(x)
Datum soundex(PG_FUNCTION_ARGS)
static pg_wchar utf8_to_unicode(const unsigned char *c)
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 Datum PointerGetDatum(const void *X)
RT_SCOPE RT_RADIX_TREE *MemoryContext old_ctx
MemoryContextSwitchTo(old_ctx)
static int cmp(const chr *x, const chr *y, size_t len)
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
struct dm_node * children[10]
char soundex[DM_CODE_DIGITS]
#define VARSIZE_ANY_EXHDR(PTR)
char * text_to_cstring(const text *t)
text * cstring_to_text_with_len(const char *s, int len)