1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * libdatrie - Double-Array Trie Library
4 * Copyright (C) 2013 Theppitak Karoonboonyanan <theppitak@gmail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * utils.c - Utility functions for datrie test cases
24 * Author: Theppitak Karoonboonyanan <theppitak@gmail.com>
27 #include <datrie/trie.h>
30 /*---------------------*
32 *---------------------*/
34 msg_step (const char *msg)
36 printf ("=> %s...\n", msg);
39 /*-------------------------*
40 * Trie creation helpers *
41 *-------------------------*/
43 en_alpha_map_new (void)
47 en_map = alpha_map_new ();
49 goto err_map_not_created;
51 if (alpha_map_add_range (en_map, 0x0061, 0x007a) != 0)
57 alpha_map_free (en_map);
68 en_map = en_alpha_map_new ();
70 goto err_map_not_created;
72 en_trie = trie_new (en_map);
76 alpha_map_free (en_map);
80 alpha_map_free (en_map);
85 /*---------------------------*
86 * Dict source for testing *
87 *---------------------------*/
88 DictRec dict_src[] = {
89 {(AlphaChar *)L"a", TRIE_DATA_UNREAD},
90 {(AlphaChar *)L"abacus", TRIE_DATA_UNREAD},
91 {(AlphaChar *)L"abandon", TRIE_DATA_UNREAD},
92 {(AlphaChar *)L"accident", TRIE_DATA_UNREAD},
93 {(AlphaChar *)L"accredit", TRIE_DATA_UNREAD},
94 {(AlphaChar *)L"algorithm", TRIE_DATA_UNREAD},
95 {(AlphaChar *)L"ammonia", TRIE_DATA_UNREAD},
96 {(AlphaChar *)L"angel", TRIE_DATA_UNREAD},
97 {(AlphaChar *)L"angle", TRIE_DATA_UNREAD},
98 {(AlphaChar *)L"azure", TRIE_DATA_UNREAD},
99 {(AlphaChar *)L"bat", TRIE_DATA_UNREAD},
100 {(AlphaChar *)L"bet", TRIE_DATA_UNREAD},
101 {(AlphaChar *)L"best", TRIE_DATA_UNREAD},
102 {(AlphaChar *)L"home", TRIE_DATA_UNREAD},
103 {(AlphaChar *)L"house", TRIE_DATA_UNREAD},
104 {(AlphaChar *)L"hut", TRIE_DATA_UNREAD},
105 {(AlphaChar *)L"king", TRIE_DATA_UNREAD},
106 {(AlphaChar *)L"kite", TRIE_DATA_UNREAD},
107 {(AlphaChar *)L"name", TRIE_DATA_UNREAD},
108 {(AlphaChar *)L"net", TRIE_DATA_UNREAD},
109 {(AlphaChar *)L"network", TRIE_DATA_UNREAD},
110 {(AlphaChar *)L"nut", TRIE_DATA_UNREAD},
111 {(AlphaChar *)L"nutshell", TRIE_DATA_UNREAD},
112 {(AlphaChar *)L"quality", TRIE_DATA_UNREAD},
113 {(AlphaChar *)L"quantum", TRIE_DATA_UNREAD},
114 {(AlphaChar *)L"quantity", TRIE_DATA_UNREAD},
115 {(AlphaChar *)L"quartz", TRIE_DATA_UNREAD},
116 {(AlphaChar *)L"quick", TRIE_DATA_UNREAD},
117 {(AlphaChar *)L"quiz", TRIE_DATA_UNREAD},
118 {(AlphaChar *)L"run", TRIE_DATA_UNREAD},
119 {(AlphaChar *)L"tape", TRIE_DATA_UNREAD},
120 {(AlphaChar *)L"test", TRIE_DATA_UNREAD},
121 {(AlphaChar *)L"what", TRIE_DATA_UNREAD},
122 {(AlphaChar *)L"when", TRIE_DATA_UNREAD},
123 {(AlphaChar *)L"where", TRIE_DATA_UNREAD},
124 {(AlphaChar *)L"which", TRIE_DATA_UNREAD},
125 {(AlphaChar *)L"who", TRIE_DATA_UNREAD},
126 {(AlphaChar *)L"why", TRIE_DATA_UNREAD},
127 {(AlphaChar *)L"zebra", TRIE_DATA_UNREAD},
128 {(AlphaChar *)NULL, TRIE_DATA_ERROR},
132 dict_src_n_entries (void)
134 return sizeof (dict_src) / sizeof (dict_src[0]) - 1;
138 dict_src_get_data (const AlphaChar *key)
140 const DictRec *dict_p;
142 for (dict_p = dict_src; dict_p->key; dict_p++) {
143 if (alpha_char_strcmp (dict_p->key, key) == 0) {
148 return TRIE_DATA_ERROR;
152 dict_src_set_data (const AlphaChar *key, TrieData data)
156 for (dict_p = dict_src; dict_p->key; dict_p++) {
157 if (alpha_char_strcmp (dict_p->key, key) == 0) {