Example #1
0
bool trie_prefix(trie TR, char *s) {
  REQUIRES(is_trie(TR));
  REQUIRES(s != NULL && strlen(s) > 0);

  tnode *T = tnode_lookup(TR->root, s, 0);

  return T != NULL && T->middle != NULL;
}
Example #2
0
// RETURNS: true iff the given trie TR contains a member that equal to s
bool trie_member(trie TR, char *s) {
  REQUIRES(is_trie(TR));
  REQUIRES(s != NULL && strlen(s) > 0);

  tnode *T = tnode_lookup(TR->root, s, 0);

  return T != NULL && T->is_end;
}
Example #3
0
// DETAILS: s might contains '*' which representa arbitrary number of arbitrary
// character
// EFFECT: add all members in the given T that match the given string
// s to q
void trie_member_generalized(trie T, char *s, Queue q) {
  REQUIRES(is_trie(T));
  REQUIRES(s != NULL);
  REQUIRES(is_Queue(q));

  struct strbuf *sb = strbuf_new(8);
  tnode_lookup_generalized(T->root, s, 0, strlen(s), sb, q);
  free(strbuf_dealloc(sb));

  ENSURES(is_Queue(q));
  return;

}
Example #4
0
	TrieNode* get_node(unsigned index) const
	{
		assert(is_trie(index));
		return reinterpret_cast<TrieNode*>(
		       static_cast<char*>(_buckets[index])-1);
	}
Example #5
0
trie trie_new() {
  trie TR = xmalloc(sizeof(struct trie_header));
  TR->root = NULL;
  ENSURES(is_trie(TR));
  return TR;
}
Example #6
0
void trie_free(trie TR) {
  REQUIRES(is_trie(TR));
  tnode_free(TR->root);
  free(TR);
}
Example #7
0
void trie_insert(trie TR, char *s) {
  REQUIRES(is_trie(TR));
  REQUIRES(s != NULL);
  TR->root = tnode_insert(TR->root, s, 0);
}