Imported Upstream version 0.2.12
[platform/upstream/libdatrie.git] / datrie / tail.h
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 <theppitak@gmail.com>
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  * tail.h - trie tail for keeping suffixes
23  * Created: 2006-08-12
24  * Author:  Theppitak Karoonboonyanan <theppitak@gmail.com>
25  */
26
27 #ifndef __TAIL_H
28 #define __TAIL_H
29
30 #include "triedefs.h"
31
32 /**
33  * @file tail.h
34  * @brief trie tail for keeping suffixes
35  */
36
37 /**
38  * @brief Double-array structure type
39  */
40 typedef struct _Tail  Tail;
41
42 Tail *   tail_new (void);
43
44 Tail *   tail_fread (FILE *file);
45
46 void     tail_free (Tail *t);
47
48 int      tail_fwrite (const Tail *t, FILE *file);
49
50
51 const TrieChar *    tail_get_suffix (const Tail *t, TrieIndex index);
52
53 Bool     tail_set_suffix (Tail *t, TrieIndex index, const TrieChar *suffix);
54
55 TrieIndex tail_add_suffix (Tail *t, const TrieChar *suffix);
56
57 TrieData tail_get_data (const Tail *t, TrieIndex index);
58
59 Bool     tail_set_data (Tail *t, TrieIndex index, TrieData data);
60
61 void     tail_delete (Tail *t, TrieIndex index);
62
63 int      tail_walk_str  (const Tail      *t,
64                          TrieIndex        s,
65                          short           *suffix_idx,
66                          const TrieChar  *str,
67                          int              len);
68
69 Bool     tail_walk_char (const Tail      *t,
70                          TrieIndex        s,
71                          short           *suffix_idx,
72                          TrieChar         c);
73
74 /**
75  * @brief Test walkability in tail with a character
76  *
77  * @param t          : the tail data
78  * @param s          : the tail data index
79  * @param suffix_idx : current character index in suffix
80  * @param c          : the character to test walkability
81  *
82  * @return boolean indicating walkability
83  *
84  * Test if the character @a c can be used to walk from given character
85  * position @a suffix_idx of entry @a s of the tail data @a t.
86  */
87 /*
88 Bool     tail_is_walkable_char (Tail            *t,
89                                 TrieIndex        s,
90                                 short            suffix_idx,
91                                 const TrieChar   c);
92 */
93 #define  tail_is_walkable_char(t,s,suffix_idx,c) \
94     (tail_get_suffix ((t), (s)) [suffix_idx] == (c))
95
96 #endif  /* __TAIL_H */
97
98 /*
99 vi:ts=4:ai:expandtab
100 */