MCPcopy Create free account
hub / github.com/catboost/catboost / TestFindTailsImpl

Method TestFindTailsImpl

library/cpp/containers/comptrie/comptrie_ut.cpp:732–776  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

730}
731
732void TCompactTrieTest::TestFindTailsImpl(const TString& prefix) {
733 TCompactTrieBuilder<> builder;
734
735 TMap<TString, ui64> input;
736
737 for (auto& i : SampleData) {
738 TString temp = i;
739 ui64 val = temp.size() * 2;
740 builder.Add(temp.data(), temp.size(), val);
741 if (temp.StartsWith(prefix)) {
742 input[temp.substr(prefix.size())] = val;
743 }
744 }
745
746 typedef TCompactTrie<> TTrie;
747
748 TBufferStream stream;
749 size_t len = builder.Save(stream);
750 TTrie trie(stream.Buffer().Data(), len);
751
752 TTrie subtrie = trie.FindTails(prefix.data(), prefix.size());
753
754 TMap<TString, ui64> output;
755
756 for (TTrie::TConstIterator i = subtrie.Begin(), mi = subtrie.End(); i != mi; ++i) {
757 TTrie::TValueType val = *i;
758 output[TString(val.first.data(), val.first.size())] = val.second;
759 }
760 UNIT_ASSERT(input.size() == output.size());
761 UNIT_ASSERT(input == output);
762
763 TBufferStream buftmp;
764 CompactTrieMinimize<TTrie::TPacker>(buftmp, stream.Buffer().Data(), len, false);
765 TTrie trieMin(buftmp.Buffer().Data(), buftmp.Buffer().Size());
766
767 subtrie = trieMin.FindTails(prefix.data(), prefix.size());
768 output.clear();
769
770 for (TTrie::TConstIterator i = subtrie.Begin(), mi = subtrie.End(); i != mi; ++i) {
771 TTrie::TValueType val = *i;
772 output[TString(val.first.data(), val.first.size())] = val.second;
773 }
774 UNIT_ASSERT(input.size() == output.size());
775 UNIT_ASSERT(input == output);
776}
777
778void TCompactTrieTest::TestPrefixGrouped() {
779 TBuffer b1b;

Callers

nothing calls this directly

Calls 12

sizeMethod · 0.45
AddMethod · 0.45
dataMethod · 0.45
StartsWithMethod · 0.45
substrMethod · 0.45
SaveMethod · 0.45
DataMethod · 0.45
FindTailsMethod · 0.45
BeginMethod · 0.45
EndMethod · 0.45
SizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected