f47a5a18baec83f24643ef8732d539883421e34f
[platform/upstream/libdatrie.git] / datrie / alpha-map.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  * alpha-map.h - map between character codes and trie alphabet
23  * Created: 2006-08-19
24  * Author:  Theppitak Karoonboonyanan <theppitak@gmail.com>
25  */
26
27 #ifndef __ALPHA_MAP_H
28 #define __ALPHA_MAP_H
29
30 #include <stdio.h>
31
32 #include "typedefs.h"
33 #include "triedefs.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /**
40  * @file alpha-map.h
41  * @brief AlphaMap data type and functions
42  *
43  * AlphaMap is a mapping between AlphaChar and TrieChar. AlphaChar is the
44  * alphabet character used in words of a target language, while TrieChar
45  * is a small integer with packed range of values and is actually used in
46  * trie state transition calculations.
47  *
48  * Since double-array trie relies on sparse state transition table,
49  * a small set of input characters can make the table small, i.e. with
50  * small number of columns. But in real life, alphabet characters can be
51  * of non-continuous range of values. The unused slots between them can
52  * waste the space in the table, and can increase the chance of unused
53  * array cells.
54  *
55  * AlphaMap is thus defined for mapping between non-continuous ranges of
56  * values of AlphaChar and packed and continuous range of Triechar.
57  *
58  * In this implementation, TrieChar is defined as a single-byte integer,
59  * which means the largest AlphaChar set that is supported is of 255
60  * values, as the special value of 0 is reserved for null-termination code.
61  */
62
63 /**
64  * @brief AlphaMap data type
65  */
66 typedef struct _AlphaMap    AlphaMap;
67
68 AlphaMap *  alpha_map_new ();
69
70 AlphaMap *  alpha_map_clone (const AlphaMap *a_map);
71
72 void        alpha_map_free (AlphaMap *alpha_map);
73
74 int         alpha_map_add_range (AlphaMap  *alpha_map,
75                                  AlphaChar  begin,
76                                  AlphaChar  end);
77
78 int         alpha_char_strlen (const AlphaChar *str);
79 int         alpha_char_strcmp (const AlphaChar *str1, const AlphaChar *str2);
80
81 #ifdef __cplusplus
82 }
83 #endif
84
85 #endif /* __ALPHA_MAP_H */
86
87
88 /*
89 vi:ts=4:ai:expandtab
90 */