18 #ifndef GRN_DAT_TRIE_HPP_
19 #define GRN_DAT_TRIE_HPP_
37 void create(
const char *file_name = NULL,
40 double num_nodes_per_key = 0.0,
41 double average_key_length = 0.0);
43 void create(
const Trie &trie,
44 const char *file_name = NULL,
47 double num_nodes_per_key = 0.0,
48 double average_key_length = 0.0);
50 void repair(
const Trie &trie,
const char *file_name = NULL);
52 void open(
const char *file_name);
55 void swap(
Trie *trie);
60 return *
reinterpret_cast<const Key *
>(key_buf_.ptr() + key_pos);
66 if ((key_id >= min_key_id()) && (key_id <= max_key_id()) &&
67 ith_entry(key_id).is_valid()) {
68 return get_key(ith_entry(key_id).key_pos());
74 return search_key(static_cast<const UInt8 *>(ptr), length, key_pos);
77 bool lcp_search(
const void *ptr,
UInt32 length,
78 UInt32 *key_pos = NULL)
const {
79 return lcp_search_key(static_cast<const UInt8 *>(ptr), length, key_pos);
83 const Key &key = ith_key(key_id);
89 bool remove(
const void *ptr,
UInt32 length) {
90 return remove_key(static_cast<const UInt8 *>(ptr), length);
94 return insert_key(static_cast<const UInt8 *>(ptr), length, key_pos);
99 return update_key(ith_key(key_id), static_cast<const UInt8 *>(ptr),
102 bool update(
const void *src_ptr,
UInt32 src_length,
103 const void *dest_ptr,
UInt32 dest_length,
106 if (!search(src_ptr, src_length, &src_key_pos)) {
109 const Key &src_key = get_key(src_key_pos);
110 return update_key(src_key, static_cast<const UInt8 *>(dest_ptr),
111 dest_length, key_pos);
137 + (
sizeof(
Entry) * num_keys())
138 + (
sizeof(
Block) * num_blocks())
139 + (
sizeof(
Node) * num_nodes())
140 + total_key_length();
143 return header_->total_key_length();
158 return header_->max_num_keys();
164 return header_->num_phantoms();
170 return header_->max_num_nodes();
176 return header_->max_num_blocks();
179 return header_->next_key_pos();
182 return header_->key_buf_size();
185 return header_->status_flags();
200 void create_file(
const char *file_name,
203 double num_nodes_per_key,
204 double average_key_length);
205 void create_file(
const char *file_name,
211 void open_file(
const char *file_name);
213 void map_address(
void *address);
215 void build_from_trie(
const Trie &trie);
218 void repair_trie(
const Trie &trie);
219 void build_from_keys(
const UInt32 *begin,
const UInt32 *end,
225 inline int get_label(
UInt32 key_id,
UInt32 depth)
const;
231 bool search_linker(
const UInt8 *ptr,
UInt32 length,
239 bool insert_linker(
const UInt8 *ptr,
UInt32 length,
256 void reserve_node(
UInt32 node_id);
257 void reserve_block(
UInt32 block_id);
261 void unset_block_level(
UInt32 block_id);
267 Block &ith_block(
UInt32 i) {
271 Entry &ith_entry(
UInt32 i) {
279 Trie &operator=(
const Trie &);
285 #endif // GRN_DAT_TRIE_HPP_