| 561 | } |
| 562 | |
| 563 | void TCompactTrieTest::TestPhraseSearch() { |
| 564 | static const char* phrases[] = {"ab", "ab cd", "ab cd ef"}; |
| 565 | static const char* const goodphrase = "ab cd ef gh"; |
| 566 | static const char* const badphrase = "cd ef gh ab"; |
| 567 | TBufferOutput bufout; |
| 568 | |
| 569 | TCompactTrieBuilder<char> builder; |
| 570 | for (size_t i = 0; i < Y_ARRAY_SIZE(phrases); i++) { |
| 571 | builder.Add(phrases[i], strlen(phrases[i]), i); |
| 572 | } |
| 573 | builder.Save(bufout); |
| 574 | |
| 575 | TCompactTrie<char> trie(bufout.Buffer().Data(), bufout.Buffer().Size()); |
| 576 | TVector<TCompactTrie<char>::TPhraseMatch> matches; |
| 577 | trie.FindPhrases(goodphrase, strlen(goodphrase), matches); |
| 578 | |
| 579 | UNIT_ASSERT(matches.size() == Y_ARRAY_SIZE(phrases)); |
| 580 | for (size_t i = 0; i < Y_ARRAY_SIZE(phrases); i++) { |
| 581 | UNIT_ASSERT(matches[i].first == strlen(phrases[i])); |
| 582 | UNIT_ASSERT(matches[i].second == i); |
| 583 | } |
| 584 | |
| 585 | trie.FindPhrases(badphrase, strlen(badphrase), matches); |
| 586 | UNIT_ASSERT(matches.size() == 0); |
| 587 | } |
| 588 | |
| 589 | void TCompactTrieTest::TestAddGet() { |
| 590 | TCompactTrieBuilder<char> builder; |