Wed, 26 Mar 2014 14:24:19 +0100
Add testsuite for PurpleTrie and fix found bugs
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
1 | /* |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
2 | * Purple |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
3 | * |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
4 | * Purple is the legal property of its developers, whose names are too |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
5 | * numerous to list here. Please refer to the COPYRIGHT file distributed |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
6 | * with this source distribution |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
7 | * |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
8 | * This program is free software; you can redistribute it and/or modify |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
9 | * it under the terms of the GNU General Public License as published by |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
10 | * the Free Software Foundation; either version 2 of the License, or (at |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
11 | * your option) any later version. |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
12 | * |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
13 | * This program is distributed in the hope that it will be useful, but |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
16 | * General Public License for more details. |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
17 | * |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
19 | * along with this program; if not, write to the Free Software |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
21 | */ |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
22 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
23 | #include "trie.h" |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
24 | |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
25 | #include <string.h> |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
26 | |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
27 | #include "debug.h" |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
28 | #include "memorypool.h" |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
29 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
30 | #define PURPLE_TRIE_GET_PRIVATE(obj) \ |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
31 | (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_TRIE, PurpleTriePrivate)) |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
32 | |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
33 | #define PURPLE_TRIE_STATES_POOL_BLOCK_SIZE 102400 |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
34 | |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
35 | typedef struct _PurpleTrieRecord PurpleTrieRecord; |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
36 | typedef struct _PurpleTrieState PurpleTrieState; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
37 | typedef struct _PurpleTrieRecordList PurpleTrieRecordList; |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
38 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
39 | typedef struct |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
40 | { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
41 | gboolean reset_on_match; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
42 | |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
43 | PurpleMemoryPool *records_str_mempool; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
44 | PurpleMemoryPool *records_obj_mempool; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
45 | PurpleTrieRecordList *records; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
46 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
47 | PurpleMemoryPool *states_mempool; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
48 | PurpleTrieState *root_state; |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
49 | } PurpleTriePrivate; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
50 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
51 | struct _PurpleTrieRecord |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
52 | { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
53 | const gchar *word; |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
54 | guint word_len; |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
55 | gpointer data; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
56 | }; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
57 | |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
58 | struct _PurpleTrieRecordList |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
59 | { |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
60 | PurpleTrieRecord *rec; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
61 | PurpleTrieRecordList *next; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
62 | PurpleTrieRecordList *prev; |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
63 | |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
64 | gpointer extra_data; |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
65 | }; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
66 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
67 | struct _PurpleTrieState |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
68 | { |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
69 | PurpleTrieState *parent; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
70 | PurpleTrieState **children; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
71 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
72 | PurpleTrieState *longest_suffix; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
73 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
74 | PurpleTrieRecord *found_word; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
75 | }; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
76 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
77 | /******************************************************************************* |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
78 | * Records list |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
79 | ******************************************************************************/ |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
80 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
81 | static PurpleTrieRecordList * |
|
35654
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
82 | purple_record_list_new(PurpleMemoryPool *mpool, PurpleTrieRecord *rec) |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
83 | { |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
84 | PurpleTrieRecordList *node; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
85 | |
|
35662
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
86 | node = purple_memory_pool_alloc0(mpool, |
|
35654
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
87 | sizeof(PurpleTrieRecordList), sizeof(gpointer)); |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
88 | g_return_val_if_fail(node != NULL, NULL); |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
89 | |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
90 | node->rec = rec; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
91 | |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
92 | return node; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
93 | } |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
94 | |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
95 | static PurpleTrieRecordList * |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
96 | purple_record_list_prepend(PurpleMemoryPool *mpool, |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
97 | PurpleTrieRecordList *old_head, PurpleTrieRecord *rec) |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
98 | { |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
99 | PurpleTrieRecordList *new_head; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
100 | |
|
35654
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
101 | new_head = purple_record_list_new(mpool, rec); |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
102 | g_return_val_if_fail(new_head != NULL, NULL); |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
103 | |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
104 | new_head->next = old_head; |
|
35662
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
105 | if (old_head) |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
106 | old_head->prev = new_head; |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
107 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
108 | return new_head; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
109 | } |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
110 | |
|
35654
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
111 | static PurpleTrieRecordList * |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
112 | purple_record_list_copy(PurpleMemoryPool *mpool, |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
113 | const PurpleTrieRecordList *head) |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
114 | { |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
115 | PurpleTrieRecordList *new_head = NULL, *new_tail = NULL; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
116 | |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
117 | while (head) { |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
118 | PurpleTrieRecordList *node; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
119 | |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
120 | node = purple_record_list_new(mpool, head->rec); |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
121 | g_return_val_if_fail(node != NULL, NULL); /* there is no leak */ |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
122 | |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
123 | node->prev = new_tail; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
124 | if (new_tail) |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
125 | new_tail->next = node; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
126 | new_tail = node; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
127 | if (!new_head) |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
128 | new_head = node; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
129 | |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
130 | head = head->next; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
131 | } |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
132 | |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
133 | return new_head; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
134 | } |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
135 | |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
136 | static PurpleTrieRecordList * |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
137 | purple_record_list_remove(PurpleTrieRecordList *head, |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
138 | PurpleTrieRecordList *node) |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
139 | { |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
140 | g_return_val_if_fail(head != NULL, NULL); |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
141 | g_return_val_if_fail(node != NULL, head); |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
142 | g_return_val_if_fail(head->prev == NULL, NULL); |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
143 | |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
144 | if (head == node) { |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
145 | if (head->next != NULL) |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
146 | head->next->prev = NULL; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
147 | return head->next; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
148 | } else { |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
149 | g_return_val_if_fail(node->prev != NULL, NULL); |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
150 | node->prev->next = node->next; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
151 | if (node->next != NULL) |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
152 | node->next->prev = node->prev; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
153 | return head; |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
154 | } |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
155 | } |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
156 | |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
157 | |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
158 | /******************************************************************************* |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
159 | * States management |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
160 | ******************************************************************************/ |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
161 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
162 | static void |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
163 | purple_trie_states_cleanup(PurpleTrie *trie) |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
164 | { |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
165 | PurpleTriePrivate *priv = PURPLE_TRIE_GET_PRIVATE(trie); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
166 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
167 | g_return_if_fail(priv != NULL); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
168 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
169 | if (priv->root_state != NULL) { |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
170 | purple_memory_pool_cleanup(priv->states_mempool); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
171 | priv->root_state = NULL; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
172 | } |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
173 | } |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
174 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
175 | /* Allocates a state and binds it to the parent. */ |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
176 | static PurpleTrieState * |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
177 | purple_trie_state_new(PurpleTrie *trie, PurpleTrieState *parent, guchar character) |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
178 | { |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
179 | PurpleTriePrivate *priv = PURPLE_TRIE_GET_PRIVATE(trie); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
180 | PurpleTrieState *state; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
181 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
182 | g_return_val_if_fail(priv != NULL, NULL); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
183 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
184 | state = purple_memory_pool_alloc0(priv->states_mempool, |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
185 | sizeof(PurpleTrieState), sizeof(gpointer)); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
186 | g_return_val_if_fail(state != NULL, NULL); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
187 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
188 | if (parent == NULL) |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
189 | return state; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
190 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
191 | state->parent = parent; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
192 | if (parent->children == NULL) { |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
193 | parent->children = purple_memory_pool_alloc0( |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
194 | priv->states_mempool, |
|
35662
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
195 | /* PurpleTrieState *children[G_MAXUCHAR + 1] */ |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
196 | 256 * sizeof(gpointer), |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
197 | sizeof(gpointer)); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
198 | } |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
199 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
200 | if (parent->children == NULL) { |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
201 | purple_memory_pool_free(priv->states_mempool, state); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
202 | g_warn_if_reached(); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
203 | return NULL; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
204 | } |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
205 | |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
206 | parent->children[character] = state; |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
207 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
208 | return state; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
209 | } |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
210 | |
|
35662
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
211 | #if 0 |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
212 | static gchar * |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
213 | purple_trie_print(PurpleTrieState *state, int limit) |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
214 | { |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
215 | GString *str = g_string_new(NULL); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
216 | int i; |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
217 | |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
218 | if (limit < 0) |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
219 | return g_strdup("{ LIMIT }"); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
220 | |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
221 | if (state->found_word) |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
222 | g_string_append(str, "*"); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
223 | g_string_append(str, "{ "); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
224 | for (i = 0; i < 256; i++) { |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
225 | gchar *chp; |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
226 | if (!state->children) |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
227 | continue; |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
228 | if (!state->children[i]) |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
229 | continue; |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
230 | if (i == 0) |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
231 | g_string_append(str, "(null)->"); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
232 | else |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
233 | g_string_append_printf(str, "%c->", i); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
234 | if (state->children[i] == state) |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
235 | g_string_append(str, "loop"); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
236 | else { |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
237 | chp = purple_trie_print(state->children[i], limit - 1); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
238 | g_string_append(str, chp); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
239 | g_string_append_c(str, ' '); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
240 | g_free(chp); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
241 | } |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
242 | } |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
243 | g_string_append(str, "}"); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
244 | |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
245 | return g_string_free(str, FALSE); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
246 | } |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
247 | #endif |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
248 | |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
249 | static gboolean |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
250 | purple_trie_states_build(PurpleTrie *trie) |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
251 | { |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
252 | PurpleTriePrivate *priv = PURPLE_TRIE_GET_PRIVATE(trie); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
253 | PurpleTrieState *root; |
|
35654
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
254 | PurpleMemoryPool *reclist_mpool; |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
255 | PurpleTrieRecordList *reclist, *it; |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
256 | gulong cur_len; |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
257 | PurpleTrieRecordList *empty_word = NULL; |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
258 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
259 | g_return_val_if_fail(priv != NULL, FALSE); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
260 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
261 | if (priv->root_state != NULL) |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
262 | return TRUE; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
263 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
264 | priv->root_state = root = purple_trie_state_new(trie, NULL, '\0'); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
265 | g_return_val_if_fail(root != NULL, FALSE); |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
266 | g_assert(root->longest_suffix == NULL); |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
267 | |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
268 | /* reclist is a list of words not yet added to the trie. Shorter words |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
269 | * are removed from the list, when they are fully added to the trie. */ |
|
35654
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
270 | reclist_mpool = purple_memory_pool_new(); |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
271 | reclist = purple_record_list_copy(reclist_mpool, priv->records); |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
272 | |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
273 | /* extra_data on every element of reclist will be a pointer to a trie |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
274 | * node -- the prefix of the word with len of cur_len */ |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
275 | for (it = reclist; it != NULL; it = it->next) { |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
276 | it->extra_data = root; |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
277 | if (it->rec->word_len == 0) |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
278 | empty_word = it; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
279 | } |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
280 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
281 | /* a special case for the empty word */ |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
282 | if (empty_word) { |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
283 | root->found_word = empty_word->rec; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
284 | reclist = purple_record_list_remove(reclist, empty_word); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
285 | } |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
286 | |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
287 | /* Iterate over indexes of words -- every loop iteration checks certain |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
288 | * index of all remaining words. Loop finishes when there are no words |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
289 | * longer than cur_len. */ |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
290 | for (cur_len = 0; reclist != NULL; cur_len++) { |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
291 | for (it = reclist; it; it = it->next) { |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
292 | PurpleTrieRecord *rec = it->rec; |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
293 | guchar character = rec->word[cur_len]; |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
294 | PurpleTrieState *prefix = it->extra_data; |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
295 | PurpleTrieState *lon_suf_parent; |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
296 | |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
297 | if (character == '\0') { |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
298 | purple_debug_warning("trie", "found " |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
299 | "a collision of empty words"); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
300 | /* it->next is still valid, see below */ |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
301 | reclist = purple_record_list_remove(reclist, it); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
302 | continue; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
303 | } |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
304 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
305 | if (prefix->children && prefix->children[character]) { |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
306 | /* Word's prefix is already in the trie, added |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
307 | * by the other word. */ |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
308 | prefix = prefix->children[character]; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
309 | } else { |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
310 | /* We need to create a new branch of trie. */ |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
311 | prefix = purple_trie_state_new(trie, prefix, |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
312 | character); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
313 | if (!prefix) { |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
314 | g_warn_if_reached(); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
315 | g_object_unref(reclist_mpool); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
316 | return FALSE; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
317 | } |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
318 | } |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
319 | it->extra_data = prefix; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
320 | /* prefix is now of length increased by one character. */ |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
321 | |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
322 | /* The whole word is now added to the trie. */ |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
323 | if (rec->word[cur_len + 1] == '\0') { |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
324 | if (prefix->found_word == NULL) |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
325 | prefix->found_word = rec; |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
326 | else { |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
327 | purple_debug_warning("trie", "found " |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
328 | "a collision of \"%s\" words", |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
329 | rec->word); |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
330 | } |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
331 | |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
332 | /* "it" is not modified here, so it->next is |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
333 | * still valid */ |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
334 | reclist = purple_record_list_remove(reclist, it); |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
335 | } |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
336 | |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
337 | /* We need to fill the longest_suffix field -- a longest |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
338 | * complete suffix of the prefix we created. We look for |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
339 | * that suffix in any path starting in root and ending |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
340 | * in the (cur_len - 1) level of trie. */ |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
341 | if (prefix->longest_suffix != NULL) |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
342 | continue; |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
343 | lon_suf_parent = prefix->parent->longest_suffix; |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
344 | while (lon_suf_parent) { |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
345 | if (lon_suf_parent->children && |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
346 | lon_suf_parent->children[character]) |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
347 | { |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
348 | prefix->longest_suffix = lon_suf_parent-> |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
349 | children[character]; |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
350 | break; |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
351 | } |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
352 | lon_suf_parent = lon_suf_parent->longest_suffix; |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
353 | } |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
354 | if (prefix->longest_suffix == NULL) |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
355 | prefix->longest_suffix = root; |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
356 | if (prefix->found_word == NULL) { |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
357 | prefix->found_word = |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
358 | prefix->longest_suffix->found_word; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
359 | } |
|
35655
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
360 | } |
|
94f0de42866d
Trie: building the trie
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35654
diff
changeset
|
361 | } |
|
35654
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
362 | |
|
d8f3b538d6db
Trie: PurpleTrieRecordList manipulation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35653
diff
changeset
|
363 | g_object_unref(reclist_mpool); |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
364 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
365 | return TRUE; |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
366 | } |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
367 | |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
368 | /******************************************************************************* |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
369 | * Searching |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
370 | ******************************************************************************/ |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
371 | |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
372 | gchar * |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
373 | purple_trie_replace(PurpleTrie *trie, const gchar *src, |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
374 | PurpleTrieReplaceCb replace_cb, gpointer user_data) |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
375 | { |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
376 | PurpleTriePrivate *priv = PURPLE_TRIE_GET_PRIVATE(trie); |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
377 | PurpleTrieState *state; |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
378 | gsize i = 0; |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
379 | GString *out; |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
380 | |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
381 | if (src == NULL) |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
382 | return NULL; |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
383 | |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
384 | g_return_val_if_fail(replace_cb != NULL, g_strdup(src)); |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
385 | g_return_val_if_fail(priv != NULL, NULL); |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
386 | |
|
35662
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
387 | purple_trie_states_build(trie); |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
388 | |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
389 | out = g_string_new(NULL); |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
390 | state = priv->root_state; |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
391 | while (src[i] != '\0') { |
|
35662
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
392 | guchar character = src[i++]; |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
393 | gboolean was_replaced = FALSE; |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
394 | |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
395 | /* change state after processing a character */ |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
396 | while (TRUE) { |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
397 | /* Perfect fit - next character is the same, as the |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
398 | * child of the prefix we reached so far. */ |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
399 | if (state->children && state->children[character]) { |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
400 | state = state->children[character]; |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
401 | break; |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
402 | } |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
403 | |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
404 | /* We reached root, that's a pity. */ |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
405 | if (state == priv->root_state) |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
406 | break; |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
407 | |
|
35659
f97feb9a67f2
Trie: better comments, fix a small flaw in algorithm
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35658
diff
changeset
|
408 | /* Let's try a bit shorter suffix. */ |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
409 | state = state->longest_suffix; |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
410 | } |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
411 | |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
412 | /* if we reached a "found" state, let's process it */ |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
413 | if (state->found_word) { |
|
35662
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
414 | gsize str_old_len; |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
415 | |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
416 | /* let's get back to the beginning of the word */ |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
417 | str_old_len = out->len; |
|
35663
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
418 | if (state->found_word->word_len > 0) { |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
419 | g_assert(out->len >= state->found_word->word_len - 1); |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
420 | out->len -= state->found_word->word_len - 1; |
|
6527214c491e
Add testsuite for PurpleTrie and fix found bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35662
diff
changeset
|
421 | } |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
422 | |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
423 | was_replaced = replace_cb(out, state->found_word->word, |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
424 | state->found_word->data, user_data); |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
425 | |
|
35662
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
426 | /* output string was untouched, rollback to the |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
427 | * previous position*/ |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
428 | if (!was_replaced) |
|
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
429 | out->len = str_old_len; |
|
35659
f97feb9a67f2
Trie: better comments, fix a small flaw in algorithm
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35658
diff
changeset
|
430 | |
|
35662
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
431 | if (was_replaced || priv->reset_on_match) |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
432 | state = priv->root_state; |
|
35662
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
433 | } |
|
35659
f97feb9a67f2
Trie: better comments, fix a small flaw in algorithm
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35658
diff
changeset
|
434 | |
|
f97feb9a67f2
Trie: better comments, fix a small flaw in algorithm
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35658
diff
changeset
|
435 | /* We skipped a character without finding any records, |
|
f97feb9a67f2
Trie: better comments, fix a small flaw in algorithm
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35658
diff
changeset
|
436 | * let's just copy it to the output. */ |
|
35662
33bfffdb9e63
Trie, memory pool: fix and make them actually working
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35659
diff
changeset
|
437 | if (!was_replaced) |
|
35659
f97feb9a67f2
Trie: better comments, fix a small flaw in algorithm
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35658
diff
changeset
|
438 | g_string_append_c(out, character); |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
439 | } |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
440 | |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
441 | return g_string_free(out, FALSE); |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
442 | } |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
443 | |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
444 | |
|
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
445 | /******************************************************************************* |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
446 | * Records |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
447 | ******************************************************************************/ |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
448 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
449 | void |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
450 | purple_trie_add(PurpleTrie *trie, const gchar *word, gpointer data) |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
451 | { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
452 | PurpleTriePrivate *priv = PURPLE_TRIE_GET_PRIVATE(trie); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
453 | PurpleTrieRecord *rec; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
454 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
455 | g_return_if_fail(priv != NULL); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
456 | g_return_if_fail(word != NULL); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
457 | |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
458 | /* Every change in a trie invalidates longest_suffix map. |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
459 | * These prefixes could be updated instead of cleaning the whole graph. |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
460 | */ |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
461 | purple_trie_states_cleanup(trie); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
462 | |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
463 | rec = purple_memory_pool_alloc(priv->records_obj_mempool, |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
464 | sizeof(PurpleTrieRecord), sizeof(gpointer)); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
465 | rec->word = purple_memory_pool_strdup(priv->records_str_mempool, word); |
|
35658
799b62769bd3
Trie: implement search-and-replace (not yet tested)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35655
diff
changeset
|
466 | rec->word_len = strlen(word); |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
467 | rec->data = data; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
468 | |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
469 | priv->records = purple_record_list_prepend(priv->records_obj_mempool, |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
470 | priv->records, rec); |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
471 | } |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
472 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
473 | /******************************************************************************* |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
474 | * API implementation |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
475 | ******************************************************************************/ |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
476 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
477 | gboolean |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
478 | purple_trie_get_reset_on_match(PurpleTrie *trie) |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
479 | { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
480 | PurpleTriePrivate *priv = PURPLE_TRIE_GET_PRIVATE(trie); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
481 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
482 | g_return_val_if_fail(priv, FALSE); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
483 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
484 | return priv->reset_on_match; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
485 | } |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
486 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
487 | void |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
488 | purple_trie_set_reset_on_match(PurpleTrie *trie, gboolean reset) |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
489 | { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
490 | PurpleTriePrivate *priv = PURPLE_TRIE_GET_PRIVATE(trie); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
491 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
492 | g_return_if_fail(priv); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
493 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
494 | priv->reset_on_match = reset; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
495 | } |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
496 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
497 | /******************************************************************************* |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
498 | * Object stuff |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
499 | ******************************************************************************/ |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
500 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
501 | enum |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
502 | { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
503 | PROP_ZERO, |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
504 | PROP_RESET_ON_MATCH, |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
505 | PROP_LAST |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
506 | }; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
507 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
508 | static GObjectClass *parent_class = NULL; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
509 | static GParamSpec *properties[PROP_LAST]; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
510 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
511 | PurpleTrie * |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
512 | purple_trie_new(void) |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
513 | { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
514 | return g_object_new(PURPLE_TYPE_TRIE, NULL); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
515 | } |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
516 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
517 | static void |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
518 | purple_trie_init(GTypeInstance *instance, gpointer klass) |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
519 | { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
520 | PurpleTrie *trie = PURPLE_TRIE(instance); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
521 | PurpleTriePrivate *priv = PURPLE_TRIE_GET_PRIVATE(trie); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
522 | |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
523 | priv->records_obj_mempool = purple_memory_pool_new(); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
524 | priv->records_str_mempool = purple_memory_pool_new(); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
525 | priv->states_mempool = purple_memory_pool_new_sized( |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
526 | PURPLE_TRIE_STATES_POOL_BLOCK_SIZE); |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
527 | } |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
528 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
529 | static void |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
530 | purple_trie_finalize(GObject *obj) |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
531 | { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
532 | PurpleTriePrivate *priv = PURPLE_TRIE_GET_PRIVATE(obj); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
533 | |
|
35653
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
534 | g_object_unref(priv->records_obj_mempool); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
535 | g_object_unref(priv->records_str_mempool); |
|
b4a35c405e95
Trie: states allocation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35652
diff
changeset
|
536 | g_object_unref(priv->states_mempool); |
|
35651
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
537 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
538 | G_OBJECT_CLASS(parent_class)->finalize(obj); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
539 | } |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
540 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
541 | static void |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
542 | purple_trie_get_property(GObject *obj, guint param_id, GValue *value, |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
543 | GParamSpec *pspec) |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
544 | { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
545 | PurpleTrie *trie = PURPLE_TRIE(obj); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
546 | PurpleTriePrivate *priv = PURPLE_TRIE_GET_PRIVATE(trie); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
547 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
548 | switch (param_id) { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
549 | case PROP_RESET_ON_MATCH: |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
550 | g_value_set_boolean(value, priv->reset_on_match); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
551 | break; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
552 | default: |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
553 | G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
554 | } |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
555 | } |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
556 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
557 | static void |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
558 | purple_trie_set_property(GObject *obj, guint param_id, |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
559 | const GValue *value, GParamSpec *pspec) |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
560 | { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
561 | PurpleTrie *trie = PURPLE_TRIE(obj); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
562 | PurpleTriePrivate *priv = PURPLE_TRIE_GET_PRIVATE(trie); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
563 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
564 | switch (param_id) { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
565 | case PROP_RESET_ON_MATCH: |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
566 | priv->reset_on_match = g_value_get_boolean(value); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
567 | break; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
568 | default: |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
569 | G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
570 | } |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
571 | } |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
572 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
573 | static void |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
574 | purple_trie_class_init(PurpleTrieClass *klass) |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
575 | { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
576 | GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
577 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
578 | parent_class = g_type_class_peek_parent(klass); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
579 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
580 | g_type_class_add_private(klass, sizeof(PurpleTriePrivate)); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
581 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
582 | obj_class->finalize = purple_trie_finalize; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
583 | obj_class->get_property = purple_trie_get_property; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
584 | obj_class->set_property = purple_trie_set_property; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
585 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
586 | properties[PROP_RESET_ON_MATCH] = g_param_spec_boolean("reset-on-match", |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
587 | "Reset on match", "Determines, if the search state machine " |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
588 | "should be reset to the initial state on every match. This " |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
589 | "ensures, that every match is distinct from each other.", TRUE, |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
590 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
591 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
592 | g_object_class_install_properties(obj_class, PROP_LAST, properties); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
593 | } |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
594 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
595 | GType |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
596 | purple_trie_get_type(void) |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
597 | { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
598 | static GType type = 0; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
599 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
600 | if (G_UNLIKELY(type == 0)) { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
601 | static const GTypeInfo info = { |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
602 | .class_size = sizeof(PurpleTrieClass), |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
603 | .class_init = (GClassInitFunc)purple_trie_class_init, |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
604 | .instance_size = sizeof(PurpleTrie), |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
605 | .instance_init = purple_trie_init, |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
606 | }; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
607 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
608 | type = g_type_register_static(G_TYPE_OBJECT, |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
609 | "PurpleTrie", &info, 0); |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
610 | } |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
611 | |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
612 | return type; |
|
95f34a3f4172
Initial trie class implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff
changeset
|
613 | } |