~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/trie.c

  • Committer: Brian Aker
  • Date: 2008-07-18 20:10:26 UTC
  • mfrom: (51.3.29 remove-dbug)
  • Revision ID: brian@tangent.org-20080718201026-tto5golt0xhwqe4a
Merging in Jay's final patch on dbug.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
TRIE *trie_init (TRIE *trie, CHARSET_INFO *charset)
50
50
{
51
51
  MEM_ROOT mem_root;
52
 
  DBUG_ENTER("trie_init");
53
 
  DBUG_ASSERT(charset);
 
52
  assert(charset);
54
53
  init_alloc_root(&mem_root,
55
54
                  (sizeof(TRIE_NODE) * 128) + ALLOC_ROOT_MIN_BLOCK_SIZE,
56
55
                  sizeof(TRIE_NODE) * 128);
59
58
    if (! (trie= (TRIE *)alloc_root(&mem_root, sizeof(TRIE))))
60
59
    {
61
60
      free_root(&mem_root, MYF(0));
62
 
      DBUG_RETURN(NULL);
 
61
      return(NULL);
63
62
    }
64
63
  }
65
64
 
72
71
  trie->charset= charset;
73
72
  trie->nnodes= 0;
74
73
  trie->nwords= 0;
75
 
  DBUG_RETURN(trie);
 
74
  return(trie);
76
75
}
77
76
 
78
77
 
91
90
void trie_free (TRIE *trie)
92
91
{
93
92
  MEM_ROOT mem_root;
94
 
  DBUG_ENTER("trie_free");
95
 
  DBUG_ASSERT(trie);
 
93
  assert(trie);
96
94
  memcpy(&mem_root, &trie->mem_root, sizeof(MEM_ROOT));
97
95
  free_root(&mem_root, MYF(0));
98
 
  DBUG_VOID_RETURN;
 
96
  return;
99
97
}
100
98
 
101
99
 
124
122
  TRIE_NODE *next;
125
123
  uchar p;
126
124
  uint k;
127
 
  DBUG_ENTER("trie_insert");
128
 
  DBUG_ASSERT(trie && key && keylen);
 
125
  assert(trie && key && keylen);
129
126
  node= &trie->root;
130
127
  trie->root.fail= NULL;
131
128
  for (k= 0; k < keylen; k++)
140
137
      TRIE_NODE *tmp= (TRIE_NODE *)alloc_root(&trie->mem_root,
141
138
                                              sizeof(TRIE_NODE));
142
139
      if (! tmp)
143
 
        DBUG_RETURN(true);
 
140
        return(true);
144
141
      tmp->leaf= 0;
145
142
      tmp->c= p;
146
143
      tmp->links= tmp->fail= tmp->next= NULL;
163
160
  }
164
161
  node->leaf= keylen;
165
162
  trie->nwords++;
166
 
  DBUG_RETURN(false);
 
163
  return(false);
167
164
}
168
165
 
169
166
 
186
183
  TRIE_NODE *node;
187
184
  uint32 fnode= 0;
188
185
  uint32 lnode= 0;
189
 
  DBUG_ENTER("trie_prepare");
190
 
  DBUG_ASSERT(trie);
 
186
  assert(trie);
191
187
 
192
188
  tmp_nodes= (TRIE_NODE **)my_malloc(trie->nnodes * sizeof(TRIE_NODE *), MYF(0));
193
189
  if (! tmp_nodes)
194
 
    DBUG_RETURN(true);
 
190
    return(true);
195
191
 
196
192
  trie->root.fail= &trie->root;
197
193
  for (node= trie->root.links; node; node= node->next)
212
208
    }
213
209
  }
214
210
  my_free((uchar*)tmp_nodes, MYF(0));
215
 
  DBUG_RETURN(false);
 
211
  return(false);
216
212
}
217
213
 
218
214
 
228
224
 
229
225
void ac_trie_init (TRIE *trie, AC_TRIE_STATE *state)
230
226
{
231
 
  DBUG_ENTER("ac_trie_init");
232
 
  DBUG_ASSERT(trie && state);
 
227
  assert(trie && state);
233
228
  state->trie= trie;
234
229
  state->node= &trie->root;
235
 
  DBUG_VOID_RETURN;
 
230
  return;
236
231
}