Home | History | Annotate | Download | only in tests

Lines Matching refs:trie

56   marisa_alpha::Trie trie;
58 ASSERT(trie.num_tries() == 0);
59 ASSERT(trie.num_keys() == 0);
60 ASSERT(trie.num_nodes() == 0);
61 ASSERT(trie.total_size() == (sizeof(marisa_alpha::UInt32) * 23));
64 trie.build(keys);
65 ASSERT(trie.num_tries() == 1);
66 ASSERT(trie.num_keys() == 0);
67 ASSERT(trie.num_nodes() == 1);
76 trie.build(keys, &key_ids,
79 ASSERT(trie.num_tries() == 1);
80 ASSERT(trie.num_keys() == 4);
81 ASSERT(trie.num_nodes() == 11);
93 key_length = trie.restore(key_ids[i], key_buf, sizeof(key_buf));
95 ASSERT(trie[keys[i]] == key_ids[i]);
96 ASSERT(trie[key_ids[i]] == keys[i]);
101 trie.clear();
103 ASSERT(trie.num_tries() == 0);
104 ASSERT(trie.num_keys() == 0);
105 ASSERT(trie.num_nodes() == 0);
106 ASSERT(trie.total_size() == (sizeof(marisa_alpha::UInt32) * 23));
108 trie.build(keys, &key_ids,
111 ASSERT(trie.num_tries() == 1);
112 ASSERT(trie.num_keys() == 4);
113 ASSERT(trie.num_nodes() == 11);
123 ASSERT(trie[keys[i]] == key_ids[i]);
124 ASSERT(trie[key_ids[i]] == keys[i]);
127 ASSERT(trie["appl"] == trie.notfound());
128 ASSERT(trie["applex"] == trie.notfound());
129 ASSERT(trie.find_first("ap") == trie.notfound());
130 ASSERT(trie.find_first("applex") == trie["app"]);
131 ASSERT(trie.find_last("ap") == trie.notfound());
132 ASSERT(trie.find_last("applex") == trie["apple"]);
135 ASSERT(trie.find("ap", &ids) == 0);
136 ASSERT(trie.find("applex", &ids) == 2);
138 ASSERT(ids[0] == trie["app"]);
139 ASSERT(ids[1] == trie["apple"]);
142 ASSERT(trie.find("Baddie", &ids, &lengths) == 1);
144 ASSERT(ids[2] == trie["Bad"]);
148 ASSERT(trie.find_callback("anderson", FindCallback(&ids, &lengths)) == 1);
150 ASSERT(ids[3] == trie["and"]);
154 ASSERT(trie.predict("") == 4);
155 ASSERT(trie.predict("a") == 3);
156 ASSERT(trie.predict("ap") == 2);
157 ASSERT(trie.predict("app") == 2);
158 ASSERT(trie.predict("appl") == 1);
159 ASSERT(trie.predict("apple") == 1);
160 ASSERT(trie.predict("appleX") == 0);
161 ASSERT(trie.predict("X") == 0);
164 ASSERT(trie.predict("a", &ids) == 3);
166 ASSERT(ids[0] == trie["app"]);
167 ASSERT(ids[1] == trie["and"]);
168 ASSERT(ids[2] == trie["apple"]);
171 ASSERT(trie.predict("a", &ids, &strs) == 3);
173 ASSERT(ids[3] == trie["app"]);
174 ASSERT(ids[4] == trie["apple"]);
175 ASSERT(ids[5] == trie["and"]);
192 marisa_alpha::Trie trie;
194 trie.build(keys, &key_ids, 1 | MARISA_ALPHA_PREFIX_TRIE
197 ASSERT(trie.num_tries() == 1);
198 ASSERT(trie.num_keys() == 4);
199 ASSERT(trie.num_nodes() == 7);
204 key_length = trie.restore(key_ids[i], key_buf, sizeof(key_buf));
206 ASSERT(trie[keys[i]] == key_ids[i]);
207 ASSERT(trie[key_ids[i]] == keys[i]);
212 key_length = trie.restore(key_ids[0], NULL, 0);
215 EXCEPT(trie.restore(key_ids[0], NULL, 5), MARISA_ALPHA_PARAM_ERROR);
217 key_length = trie.restore(key_ids[0], key_buf, 5);
221 key_length = trie.restore(key_ids[0], key_buf, 6);
225 trie.build(keys, &key_ids, 2 | MARISA_ALPHA_PREFIX_TRIE
228 ASSERT(trie.num_tries() == 2);
229 ASSERT(trie.num_keys() == 4);
230 ASSERT(trie.num_nodes() == 16);
233 key_length = trie.restore(key_ids[i], key_buf, sizeof(key_buf));
235 ASSERT(trie[keys[i]] == key_ids[i]);
236 ASSERT(trie[key_ids[i]] == keys[i]);
241 key_length = trie.restore(key_ids[0], NULL, 0);
244 EXCEPT(trie.restore(key_ids[0], NULL, 5), MARISA_ALPHA_PARAM_ERROR);
246 key_length = trie.restore(key_ids[0], key_buf, 5);
250 key_length = trie.restore(key_ids[0], key_buf, 6);
254 trie.build(keys, &key_ids, 2 | MARISA_ALPHA_PREFIX_TRIE
257 ASSERT(trie.num_tries() == 2);
258 ASSERT(trie.num_keys() == 4);
259 ASSERT(trie.num_nodes() == 14);
262 key_length = trie.restore(key_ids[i], key_buf, sizeof(key_buf));
264 ASSERT(trie[keys[i]] == key_ids[i]);
265 ASSERT(trie[key_ids[i]] == keys[i]);
270 trie.save("trie-test.dat");
271 trie.clear();
273 trie.mmap(&mapper, "trie-test.dat");
276 ASSERT(trie.num_tries() == 2);
277 ASSERT(trie.num_keys() == 4);
278 ASSERT(trie.num_nodes() == 14);
281 key_length = trie.restore(key_ids[i], key_buf, sizeof(key_buf));
283 ASSERT(trie[keys[i]] == key_ids[i]);
284 ASSERT(trie[key_ids[i]] == keys[i]);
290 trie.write(stream);
291 trie.clear();
292 trie.read(stream);
294 ASSERT(trie.num_tries() == 2);
295 ASSERT(trie.num_keys() == 4);
296 ASSERT(trie.num_nodes() == 14);
299 key_length = trie.restore(key_ids[i], key_buf, sizeof(key_buf));
301 ASSERT(trie[keys[i]] == key_ids[i]);
302 ASSERT(trie[key_ids[i]] == keys[i]);
307 trie.build(keys, &key_ids, 3 | MARISA_ALPHA_PREFIX_TRIE
310 ASSERT(trie.num_tries() == 3);
311 ASSERT(trie.num_keys() == 4);
312 ASSERT(trie.num_nodes() == 19);
315 key_length = trie.restore(key_ids[i], key_buf, sizeof(key_buf));
317 ASSERT(trie[keys[i]] == key_ids[i]);
318 ASSERT(trie[key_ids[i]] == keys[i]);
323 ASSERT(trie["ca"] == trie.notfound());
324 ASSERT(trie["card"] == trie.notfound());
327 ASSERT(trie.find_first("ca") == trie.notfound());
328 ASSERT(trie.find_first("car") == trie["car"]);
329 ASSERT(trie.find_first("card", &length) == trie["car"]);
332 ASSERT(trie.find_last("afte") == trie.notfound());
333 ASSERT(trie.find_last("after") == trie["after"]);
334 ASSERT(trie.find_last("afternoon", &length) == trie["after"]);
340 ASSERT(trie.find("card", &ids, &lengths) == 1);
342 ASSERT(ids[0] == trie["car"]);
346 ASSERT(trie.predict("ca", &ids) == 2);
348 ASSERT(ids[1] == trie["car"]);
349 ASSERT(ids[2] == trie["caster"]);
351 ASSERT(trie.predict("ca", &ids, NULL, 1) == 1);
353 ASSERT(ids[3] == trie["car"]);
356 ASSERT(trie.predict("ca", &ids, &strs, 1) == 1);
358 ASSERT(ids[4] == trie["car"]);
362 ASSERT(trie.predict_callback("", PredictCallback(&ids, &strs)) == 4);
364 ASSERT(ids[5] == trie["car"]);
365 ASSERT(ids[6] == trie["caster"]);
366 ASSERT(ids[7] == trie["after"]);
367 ASSERT(ids[8] == trie["bar"]);
378 ASSERT(trie.find("card", ids, lengths, 10) == 1);
379 ASSERT(ids[0] == trie["car"]);
382 ASSERT(trie.predict("ca", ids, NULL, 10) == 2);
383 ASSERT(ids[0] == trie["car"]);
384 ASSERT(ids[1] == trie["caster"]);
386 ASSERT(trie.predict("ca", ids, NULL, 1) == 1);
387 ASSERT(ids[0] == trie["car"]);
390 ASSERT(trie.predict("ca", ids, strs, 1) == 1);
391 ASSERT(ids[0] == trie["car"]);
394 ASSERT(trie.predict("", ids, strs, 10) == 4);
395 ASSERT(ids[0] == trie["car"]);
396 ASSERT(ids[1] == trie["caster"]);
397 ASSERT(ids[2] == trie["after"]);
398 ASSERT(ids[3] == trie["bar"]);
406 trie.map(trie_data.c_str(), trie_data.length());
408 ASSERT(trie.num_tries() == 2);
409 ASSERT(trie.num_keys() == 4);
410 ASSERT(trie.num_nodes() == 14);
413 key_length = trie.restore(key_ids[i], key_buf, sizeof(key_buf));
415 ASSERT(trie[keys[i]] == key_ids[i]);
416 ASSERT(trie[key_ids[i]] == keys[i]);
434 marisa_alpha::Trie trie;
436 trie.build(keys, &key_ids, 1);
438 ASSERT(trie.num_tries() == 1);
439 ASSERT(trie.num_keys() == 4);
440 ASSERT(trie.num_nodes() == 7);
452 key_length = trie.restore(key_ids[i], key_buf, sizeof(key_buf));
454 ASSERT(trie[keys[i]] == key_ids[i]);
455 ASSERT(trie[key_ids[i]] == keys[i]);
460 trie.build(keys, &key_ids, 2 | MARISA_ALPHA_WITHOUT_TAIL);
462 ASSERT(trie.num_tries() == 2);
463 ASSERT(trie.num_keys() == 4);
464 ASSERT(trie.num_nodes() == 17);
467 key_length = trie.restore(key_ids[i], key_buf, sizeof(key_buf));
469 ASSERT(trie[keys[i]] == key_ids[i]);
470 ASSERT(trie[key_ids[i]] == keys[i]);
475 trie.build(keys, &key_ids, 2);
477 ASSERT(trie.num_tries() == 2);
478 ASSERT(trie.num_keys() == 4);
479 ASSERT(trie.num_nodes() == 14);
482 key_length = trie.restore(key_ids[i], key_buf, sizeof(key_buf));
484 ASSERT(trie[keys[i]] == key_ids[i]);
485 ASSERT(trie[key_ids[i]] == keys[i]);
490 trie.build(keys, &key_ids, 3 | MARISA_ALPHA_WITHOUT_TAIL);
492 ASSERT(trie.num_tries() == 3);
493 ASSERT(trie.num_keys() == 4);
494 ASSERT(trie.num_nodes() == 20);
497 key_length = trie.restore(key_ids[i], key_buf, sizeof(key_buf));
499 ASSERT(trie[keys[i]] == key_ids[i]);
500 ASSERT(trie[key_ids[i]] == keys[i]);
506 trie.write(stream);
507 trie.clear();
508 trie.read(stream);
510 ASSERT(trie.num_tries() == 3);
511 ASSERT(trie.num_keys() == 4);
512 ASSERT(trie.num_nodes() == 20);
515 key_length = trie.restore(key_ids[i], key_buf, sizeof(key_buf));
517 ASSERT(trie[keys[i]] == key_ids[i]);
518 ASSERT(trie[key_ids[i]] == keys[i]);
532 marisa_alpha::Trie trie;
534 trie.build(keys, &key_ids);
536 ASSERT(trie.num_tries() == 1);
537 ASSERT(trie.num_keys() == 1);
538 ASSERT(trie.num_nodes() == 1);
543 ASSERT(trie[""] == 0);
544 ASSERT(trie[(marisa_alpha::UInt32)0] == "");
546 ASSERT(trie["x"] == trie.notfound());
547 ASSERT(trie.find_first("") == 0);
548 ASSERT(trie.find_first("x") == 0);
549 ASSERT(trie.find_last("") == 0);
550 ASSERT(trie.find_last("x") == 0);
553 ASSERT(trie.find("xyz", &ids) == 1);
555 ASSERT(ids[0] == trie[""]);
558 ASSERT(trie.find("xyz", &ids, &lengths) == 1);
560 ASSERT(ids[0] == trie[""]);
561 ASSERT(ids[1] == trie[""]);
565 ASSERT(trie.find_callback("xyz", FindCallback(&ids, &lengths)) == 1);
567 ASSERT(ids[2] == trie[""]);
571 ASSERT(trie.predict("xyz", &ids) == 0);
573 ASSERT(trie.predict("", &ids) == 1);
575 ASSERT(ids[3] == trie[""]);
578 ASSERT(trie.predict("", &ids, &strs) == 1);
580 ASSERT(ids[4] == trie[""]);
591 binary_key += "Trie";
596 marisa_alpha::Trie trie;
598 trie.build(keys, &key_ids, 1 | MARISA_ALPHA_WITHOUT_TAIL);
600 ASSERT(trie.num_tries() == 1);
601 ASSERT(trie.num_keys() == 1);
602 ASSERT(trie.num_nodes() == 8);
607 key_length = trie.restore(0, key_buf, sizeof(key_buf));
609 ASSERT(trie[keys[0]] == key_ids[0]);
610 ASSERT(trie[key_ids[0]] == keys[0]);
613 trie.build(keys, &key_ids,
616 ASSERT(trie.num_tries() == 1);
617 ASSERT(trie.num_keys() == 1);
618 ASSERT(trie.num_nodes() == 2);
621 key_length = trie.restore(0, key_buf, sizeof(key_buf));
623 ASSERT(trie[keys[0]] == key_ids[0]);
624 ASSERT(trie[key_ids[0]] == keys[0]);
627 trie.build(keys, &key_ids,
630 ASSERT(trie.num_tries() == 1);
631 ASSERT(trie.num_keys() == 1);
632 ASSERT(trie.num_nodes() == 2);
635 key_length = trie.restore(0, key_buf, sizeof(key_buf));
637 ASSERT(trie[keys[0]] == key_ids[0]);
638 ASSERT(trie[key_ids[0]] == keys[0]);
642 ASSERT(trie.predict_breadth_first("", &ids) == 1);
647 ASSERT(trie.predict_depth_first("NP", &ids, &strs) == 1);