1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * libdatrie - Double-Array Trie Library
4 * Copyright (C) 2006 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 * darray.h - Double-array trie structure
24 * Author: Theppitak Karoonboonyanan <theppitak@gmail.com>
31 #include "trie-string.h"
35 * @brief Double-array trie structure
39 * @brief Symbol set structure type
41 typedef struct _Symbols Symbols;
43 void symbols_free (Symbols *syms);
44 int symbols_num (const Symbols *syms);
45 TrieChar symbols_get (const Symbols *syms, int index);
48 * @brief Double-array structure type
50 typedef struct _DArray DArray;
55 DArray * da_fread (FILE *file);
57 void da_free (DArray *d);
59 int da_fwrite (const DArray *d, FILE *file);
62 TrieIndex da_get_root (const DArray *d);
65 TrieIndex da_get_base (const DArray *d, TrieIndex s);
67 TrieIndex da_get_check (const DArray *d, TrieIndex s);
70 void da_set_base (DArray *d, TrieIndex s, TrieIndex val);
72 void da_set_check (DArray *d, TrieIndex s, TrieIndex val);
74 Bool da_walk (const DArray *d, TrieIndex *s, TrieChar c);
76 Symbols * da_output_symbols (const DArray *d, TrieIndex s);
79 * @brief Test walkability in double-array structure
81 * @param d : the double-array structure
82 * @param s : current state
83 * @param c : the input character
85 * @return boolean indicating walkability
87 * Test if there is a transition from state @a s with input character @a c.
90 Bool da_is_walkable (DArray *d, TrieIndex s, TrieChar c);
92 #define da_is_walkable(d,s,c) \
93 (da_get_check ((d), da_get_base ((d), (s)) + (c)) == (s))
95 TrieIndex da_insert_branch (DArray *d, TrieIndex s, TrieChar c);
97 void da_prune (DArray *d, TrieIndex s);
99 void da_prune_upto (DArray *d, TrieIndex p, TrieIndex s);
101 TrieIndex da_first_separate (DArray *d, TrieIndex root, TrieString *keybuff);
103 TrieIndex da_next_separate (DArray *d,
106 TrieString *keybuff);
108 #endif /* __DARRAY_H */