Lines Matching full:trie
69 void checkFirst(UCharsTrie &trie, const StringAndValue data[], int32_t dataLength);
70 void checkNext(UCharsTrie &trie, const StringAndValue data[], int32_t dataLength);
71 void checkNextWithState(UCharsTrie &trie, const StringAndValue data[], int32_t dataLength);
72 void checkNextString(UCharsTrie &trie, const StringAndValue data[], int32_t dataLength);
73 void checkIterator(UCharsTrie &trie, const StringAndValue data[], int32_t dataLength);
296 LocalPointer<UCharsTrie> trie(buildTrie(data, LENGTHOF(data), USTRINGTRIE_BUILD_FAST));
297 if(trie.isNull()) {
301 if( (result=trie->nextForCodePoint(0x4dff))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
302 (result=trie->nextForCodePoint(0x10000))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
303 (result=trie->nextForCodePoint(0x9999))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
304 (result=trie->nextForCodePoint(0x20000))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
305 (result=trie->nextForCodePoint(0xdfff))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
306 (result=trie->nextForCodePoint(0x10ffff))!=USTRINGTRIE_FINAL_VALUE || result!=trie->current() ||
307 trie->getValue()!=2000000000
311 if( (result=trie->firstForCodePoint(0x4dff))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
312 (result=trie->nextForCodePoint(0x10000))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
313 (result=trie->nextForCodePoint(0x9999))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
314 (result=trie->nextForCodePoint(0x20002))!=USTRINGTRIE_FINAL_VALUE || result!=trie->current() ||
315 trie->getValue()!=44444
319 if( (result=trie->reset().nextForCodePoint(0x4dff))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
320 (result=trie->nextForCodePoint(0x10000))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
321 (result=trie->nextForCodePoint(0x9999))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
322 (result=trie->nextForCodePoint(0x20222))!=USTRINGTRIE_NO_MATCH || result!=trie->current() // no match for trail surrogate
326 if( (result=trie->reset().nextForCodePoint(0x4dff))!=USTRINGTRIE_NO_VALUE || result!=trie->current() ||
327 (result=trie->nextForCodePoint(0x103ff))!=USTRINGTRIE_FINAL_VALUE || result!=trie->current() ||
328 trie->getValue()!=99999
379 logln("serialized trie size: %ld UChars\n", (long)trieUChars.length());
385 LocalPointer<UCharsTrie> trie(buildLargeTrie(1111));
386 if(trie.isNull()) {
394 if(trie->first(x[0])==USTRINGTRIE_NO_MATCH) {
401 UStringTrieResult result=trie->next(x.getBuffer(), x.length());
402 if(!USTRINGTRIE_HAS_VALUE(result) || result!=trie->current() || value!=trie->getValue()) {
464 LocalPointer<UCharsTrie> trie(buildMonthsTrie(USTRINGTRIE_BUILD_FAST));
465 if(trie.isNull()) {
469 if(trie->hasUniqueValue(uniqueValue)) {
472 trie->next(u_j);
473 trie->next(u_a);
474 trie->next(u_n);
476 if(!trie->hasUniqueValue(uniqueValue) || uniqueValue!=1) {
479 trie->first(u_j);
480 trie->next(u_u);
481 if(trie->hasUniqueValue(uniqueValue)) {
484 if(trietrie->getValue()) {
488 if(!trie->hasUniqueValue(uniqueValue) || uniqueValue!=6) {
492 trie->first(u_a);
493 trie->next(u_u);
494 if(!trie->hasUniqueValue(uniqueValue) || uniqueValue!=8) {
500 LocalPointer<UCharsTrie> trie(buildMonthsTrie(USTRINGTRIE_BUILD_SMALL));
501 if(trie.isNull()) {
506 int32_t count=trie->getNextUChars(app);
510 trie->next(u_j);
511 trie->next(u_a);
512 trie->next(u_n);
515 count=trie->getNextUChars(app);
520 trie->getValue(); // next() had returned USTRINGTRIE_INTERMEDIATE_VALUE.
522 count=trie->getNextUChars(app);
527 trie->next(u_u);
529 count=trie->getNextUChars(app);
533 trie->next(u_a);
535 count=trie->getNextUChars(app);
539 trie->next(u_r);
540 trie->next(u_y);
543 count=trie->getNextUChars(app);
550 LocalPointer<UCharsTrie> trie(buildMonthsTrie(USTRINGTRIE_BUILD_FAST));
551 if(trie.isNull()) {
555 trie->next(u_j);
556 trie->next(u_a);
557 trie->next(u_n);
559 UCharsTrie::Iterator iter(*trie, 0, errorCode);
560 if(errorCode.logIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
599 LocalPointer<UCharsTrie> trie(buildMonthsTrie(USTRINGTRIE_BUILD_SMALL));
600 if(trie.isNull()) {
604 trie->next(u_j);
605 trie->next(u_a);
606 trie->next(u_n);
607 trie->next(u_u);
608 trie->next(u_a);
610 UCharsTrie::Iterator iter(*trie, 0, errorCode);
611 if(errorCode.logIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
627 LocalPointer<UCharsTrie> trie(buildMonthsTrie(USTRINGTRIE_BUILD_FAST));
628 if(trie.isNull()) {
632 UCharsTrie::Iterator iter(*trie, 4, errorCode);
633 if(errorCode.logIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
678 LocalPointer<UCharsTrie> trie(buildTrie(data, LENGTHOF(data), USTRINGTRIE_BUILD_FAST));
679 if(trie.isNull()) {
683 trie->next(u_a);
684 trie->next(u_b);
687 UCharsTrie::Iterator iter(*trie, 2, errorCode);
688 if(errorCode.logIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
706 LocalPointer<UCharsTrie> trie(buildTrie(data, LENGTHOF(data), USTRINGTRIE_BUILD_FAST));
707 if(trie.isNull()) {
711 trie->next(u_a);
712 trie->next(u_b);
713 trie->next(u_c);
716 UCharsTrie::Iterator iter(*trie, 3, errorCode);
717 if(errorCode.logIfFailureAndReset("UCharsTrie::Iterator(trie) constructor")) {
756 LocalPointer<UCharsTrie> trie(buildTrie(data, dataLength, buildOption));
757 if(trie.isNull()) {
760 checkFirst(*trie, data, dataLength);
761 checkNext(*trie, data, dataLength);
762 checkNextWithState(*trie, data, dataLength);
763 checkNextString(*trie, data, dataLength);
764 checkIterator(*trie, data, dataLength);
770 // Add the items to the trie builder in an interesting (not trivial, not random) order.
792 LocalPointer<UCharsTrie> trie(builder_->build(buildOption, errorCode));
799 logln("serialized trie size: %ld UChars\n", (long)trieUChars.length());
812 return trie.orphan();
818 void UCharsTrieTest::checkFirst(UCharsTrie &trie,
827 UStringTrieResult firstResult=trie.first(c);
828 int32_t firstValue=USTRINGTRIE_HAS_VALUE(firstResult) ? trie.getValue() : -1;
829 UStringTrieResult nextResult=trie.next(nextCp);
830 if(firstResult!=trie.reset().next(c) ||
831 firstResult!=trie.current() ||
832 firstValue!=(USTRINGTRIE_HAS_VALUE(firstResult) ? trie.getValue() : -1) ||
833 nextResult!=trie.next(nextCp)
835 errln("trie.first(U+%04X)!=trie.reset().next(same) for %s",
841 firstResult=trie.firstForCodePoint(c);
842 firstValue=USTRINGTRIE_HAS_VALUE(firstResult) ? trie.getValue() : -1;
843 nextResult=trie.nextForCodePoint(nextCp);
844 if(firstResult!=trie.reset().nextForCodePoint(c) ||
845 firstResult!=trie.current() ||
846 firstValue!=(USTRINGTRIE_HAS_VALUE(firstResult) ? trie.getValue() : -1) ||
847 nextResult!=trie.nextForCodePoint(nextCp)
849 errln("trie.firstForCodePoint(U+%04X)!=trie.reset().nextForCodePoint(same) for %s",
853 trie.reset();
856 void UCharsTrieTest::checkNext(UCharsTrie &trie,
864 result=trie.next(expectedString.getTerminatedBuffer(), stringLength)) ||
865 result!=trie.current()
867 errln("trie does not seem to contain %s", data[i].s);
868 } else if(trie.getValue()!=data[i].value) {
869 errln("trie value for %s is %ld=0x%lx instead of expected %ld=0x%lx",
871 (long)trie.getValue(), (long)trie.getValue(),
873 } else if(result!=trie.current() || trie.getValue()!=data[i].value) {
874 errln("trie value for %s changes when repeating current()/getValue()", data[i].s);
876 trie.reset();
878 result=trie.current();
881 errln("trie.current()!=hasNext before end of %s (at index %d)", data[i].s, j);
885 trie.getValue();
886 if(trie.current()!=USTRINGTRIE_INTERMEDIATE_VALUE) {
887 errln("trie.getValue().current()!=USTRINGTRIE_INTERMEDIATE_VALUE before end of %s (at index %d)", data[i].s, j);
891 result=trie.next(expectedString[j]);
893 errln("trie.next()=USTRINGTRIE_NO_MATCH before end of %s (at index %d)", data[i].s, j);
896 if(result!=trie.current()) {
897 errln("trie.next()!=following current() before end of %s (at index %d)", data[i].s, j);
902 errln("trie.next()!=hasValue at the end of %s", data[i].s);
905 trie.getValue();
906 if(result!=trie.current()) {
907 errln("trie.current() != current()+getValue()+current() after end of %s",
911 trie.saveState(state);
917 if(trie.resetToState(state).next(c)) {
923 errln("(trie.current()==USTRINGTRIE_INTERMEDIATE_VALUE) contradicts "
924 "(trie.next(some UChar)!=USTRINGTRIE_NO_MATCH) after end of %s", data[i].s);
926 trie.reset();
930 void UCharsTrieTest::checkNextWithState(UCharsTrie &trie,
936 trie.resetToState(noState);
942 if(!USTRINGTRIE_MATCHES(trie.next(expectedString[j]))) {
943 errln("trie.next()=USTRINGTRIE_NO_MATCH for a prefix of %s", data[i].s);
947 trie.saveState(state);
948 UStringTrieResult resultAtState=trie.current();
952 valueAtState=trie.getValue();
954 result=trie.next(0); // mismatch
955 if(result!=USTRINGTRIE_NO_MATCH || result!=trie.current()) {
956 errln("trie.next(0) matched after part of %s", data[i].s);
958 if( resultAtState!=trie.resetToState(state).current() ||
959 (USTRINGTRIE_HAS_VALUE(resultAtState) && valueAtState!=trie.getValue())
961 errln("trie.next(part of %s) changes current()/getValue() after "
965 result=trie.next(expectedString.getTerminatedBuffer()+partialLength,
967 result!=trie.current()) {
968 errln("trie.next(rest of %s) does not seem to contain %s after "
972 result=trie.resetToState(state).
975 result!=trie.current()) {
976 errln("trie does not seem to contain %s after saveState/next(rest)/resetToState",
978 } else if(trie.getValue()!=data[i].value) {
979 errln("trie value for %s is %ld=0x%lx instead of expected %ld=0x%lx",
981 (long)trie.getValue(), (long)trie.getValue(),
984 trie.reset();
990 void UCharsTrieTest::checkNextString(UCharsTrie &trie,
995 if(!trie.next(expectedString.getTerminatedBuffer(), stringLength/2)) {
996 errln("trie.next(up to middle of string)=USTRINGTRIE_NO_MATCH for %s", data[i].s);
1000 if(trie.next(expectedString.getTerminatedBuffer()+stringLength/2,
1002 errln("trie.next(string+NUL)!=USTRINGTRIE_NO_MATCH for %s", data[i].s);
1004 trie.reset();
1008 void UCharsTrieTest::checkIterator(UCharsTrie &trie,
1011 UCharsTrie::Iterator iter(trie, 0, errorCode);
1023 errln("trie iterator hasNext()=FALSE for item %d: %s", (int)i, data[i].s);
1027 if(errorCode.logIfFailureAndReset("trie iterator next() for item %d: %s", (int)i, data[i].s)) {
1031 errln("trie iterator next()=FALSE for item %d: %s", (int)i, data[i].s);
1039 errln("trie iterator next().getString()=%s but expected %s for item %d",
1043 errln("trie iterator next().getValue()=%ld=0x%lx but expected %ld=0x%lx for item %d: %s",
1050 errln("trie iterator hasNext()=TRUE after all items");
1053 errorCode.logIfFailureAndReset("trie iterator next() after all items");
1055 errln("trie iterator next()=TRUE after all items");