22 }
else if (_count > 1) {
23 for (
unsigned short i = 0;
i != _count; ++
i) {
38 const unsigned char c = *
prefix_;
39 if (c < _min || c >= _min + _count) {
46 }
else if (_count == 1) {
47 const unsigned char oldc = _min;
49 _count = (_min < c ? c - _min : _min - c) + 1;
51 static_cast<trie_t **
> (malloc (
sizeof (
trie_t *) * _count));
53 for (
unsigned short i = 0;
i != _count; ++
i)
55 _min = std::min (_min, c);
56 _next.table[oldc - _min] = oldp;
57 }
else if (_min < c) {
59 const unsigned short old_count = _count;
60 _count = c - _min + 1;
62 realloc (_next.table, sizeof (
trie_t *) * _count));
64 for (
unsigned short i = old_count;
i != _count;
i++)
65 _next.table[
i] =
NULL;
68 const unsigned short old_count = _count;
69 _count = (_min + old_count) - c;
70 _next.table =
static_cast<trie_t **
> (
71 realloc (_next.table, sizeof (
trie_t *) * _count));
73 memmove (_next.table + _min - c, _next.table,
74 old_count * sizeof (
trie_t *));
75 for (
unsigned short i = 0;
i != _min - c;
i++)
76 _next.table[
i] =
NULL;
84 _next.node =
new (std::nothrow)
trie_t;
89 return _next.node->add (
prefix_ + 1, size_ - 1);
91 if (!_next.table[c - _min]) {
92 _next.table[c - _min] =
new (std::nothrow)
trie_t;
97 return _next.table[c - _min]->add (
prefix_ + 1, size_ - 1);
109 const unsigned char c = *
prefix_;
110 if (!_count || c < _min || c >= _min + _count)
118 const bool ret = next_node->
rm (
prefix_ + 1, size_ - 1);
132 _next.table[c - _min] = 0;
137 if (_live_nodes == 1) {
147 node = _next.
table[_count - 1];
149 }
else if (c == _min + _count - 1) {
152 node = _next.
table[0];
158 }
else if (c == _min) {
162 unsigned char new_min = _min;
163 for (
unsigned short i = 1;
i < _count; ++
i) {
164 if (_next.table[
i]) {
175 _count = _count - (new_min - _min);
177 static_cast<trie_t **
> (malloc (
sizeof (
trie_t *) * _count));
180 memmove (_next.table, old_table + (new_min - _min),
181 sizeof (
trie_t *) * _count);
185 }
else if (c == _min + _count - 1) {
189 unsigned short new_count = _count;
190 for (
unsigned short i = 1;
i < _count; ++
i) {
191 if (_next.table[_count - 1 -
i]) {
192 new_count = _count -
i;
201 static_cast<trie_t **
> (malloc (
sizeof (
trie_t *) * _count));
204 memmove (_next.table, old_table, sizeof (
trie_t *) * _count);
216 const trie_t *current =
this;
228 const unsigned char c = *
data_;
229 if (c < current->_min || c >= current->
_min + current->
_count)
246 void (*func_) (
unsigned char *
data_,
size_t size_,
void *arg_),
void *arg_)
248 unsigned char *buff =
NULL;
249 apply_helper (&buff, 0, 0, func_, arg_);
256 void (*func_) (
unsigned char *
data_,
263 func_ (*buff_, buffsize_, arg_);
266 if (buffsize_ >= maxbuffsize_) {
267 maxbuffsize_ = buffsize_ + 256;
268 *buff_ =
static_cast<unsigned char *
> (realloc (*buff_, maxbuffsize_));
278 (*buff_)[buffsize_] = _min;
280 _next.node->apply_helper (buff_, buffsize_, maxbuffsize_, func_, arg_);
285 for (
unsigned short c = 0; c != _count; c++) {
286 (*buff_)[buffsize_] = _min + c;
288 _next.table[c]->apply_helper (buff_, buffsize_ + 1, maxbuffsize_,
295 return _refcnt == 0 && _live_nodes == 0;