Debian Codegraph @

datrie/darray.h

raw
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * libdatrie - Double-Array Trie Library
4 * Copyright (C) 2006 Theppitak Karoonboonyanan <[email protected]>
5 *
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.
10 *
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.
15 *
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
19 */
20
21 /*
22 * darray.h - Double-array trie structure
23 * Created: 2006-08-11
24 * Author: Theppitak Karoonboonyanan <[email protected]>
25 */
26
27 #ifndef __DARRAY_H
28 #define __DARRAY_H
29
30 #include "triedefs.h"
31 #include "trie-string.h"
32
33 /**
34 * @file darray.h
35 * @brief Double-array trie structure
36 */
37
38 /**
39 * @brief Symbol set structure type
40 */
41 typedef struct _Symbols Symbols;
42
43 void symbols_free (Symbols *syms);
44 int symbols_num (const Symbols *syms);
45 TrieChar symbols_get (const Symbols *syms, int index);
46
47 /**
48 * @brief Double-array structure type
49 */
50 typedef struct _DArray DArray;
51
52
53 DArray * da_new (void);
54
55 DArray * da_fread (FILE *file);
56
57 void da_free (DArray *d);
58
59 size_t da_get_serialized_size (const DArray *d);
60
61 void da_serialize (const DArray *d, uint8 **ptr);
62
63 int da_fwrite (const DArray *d, FILE *file);
64
65
66 TrieIndex da_get_root (const DArray *d);
67
68
69 TrieIndex da_get_base (const DArray *d, TrieIndex s);
70
71 TrieIndex da_get_check (const DArray *d, TrieIndex s);
72
73
74 void da_set_base (DArray *d, TrieIndex s, TrieIndex val);
75
76 void da_set_check (DArray *d, TrieIndex s, TrieIndex val);
77
78 Bool da_walk (const DArray *d, TrieIndex *s, TrieChar c);
79
80 Symbols * da_output_symbols (const DArray *d, TrieIndex s);
81
82 /**
83 * @brief Test walkability in double-array structure
84 *
85 * @param d : the double-array structure
86 * @param s : current state
87 * @param c : the input character
88 *
89 * @return boolean indicating walkability
90 *
91 * Test if there is a transition from state @a s with input character @a c.
92 */
93 /*
94 Bool da_is_walkable (DArray *d, TrieIndex s, TrieChar c);
95 */
96 #define da_is_walkable(d,s,c) \
97 (da_get_check ((d), da_get_base ((d), (s)) + (c)) == (s))
98
99 TrieIndex da_insert_branch (DArray *d, TrieIndex s, TrieChar c);
100
101 void da_prune (DArray *d, TrieIndex s);
102
103 void da_prune_upto (DArray *d, TrieIndex p, TrieIndex s);
104
105 TrieIndex da_first_separate (DArray *d, TrieIndex root, TrieString *keybuff);
106
107 TrieIndex da_next_separate (DArray *d,
108 TrieIndex root,
109 TrieIndex sep,
110 TrieString *keybuff);
111
112 #endif /* __DARRAY_H */
113
114 /*
115 vi:ts=4:ai:expandtab
116 */