Collation keys are generated by the Collator class.
Use the CollationKey objects instead of Collator to compare strings multiple times. A CollationKey preprocesses the comparison information from the Collator object to make the comparison faster. If you are not going to comparing strings multiple times, then using the Collator object is generally faster, since it only processes as much of the string as needed to make a comparison.
For example (with strength == tertiary)
When comparing "Abernathy" to "Baggins-Smythworthy", Collator only needs to process a couple of characters, while a comparison with CollationKeys will process all of the characters. On the other hand, if you are doing a sort of a number of fields, it is much faster to use CollationKeys, since you will be comparing strings multiple times.
Typical use of CollationKeys are in databases, where you store a CollationKey in a hidden field, and use it for sorting or indexing.
Example of use:
myCollator->getCollationKey("Tom", keys[0], success );
myCollator->getCollationKey("Dick", keys[1], success );
myCollator->getCollationKey("Harry", keys[2], success );
tmp = keys[0]; keys[0] = keys[1]; keys[1] = tmp;
}
Collator::EComparisonResult compareTo(const CollationKey &target) const
Convenience method which does a string(bit-wise) comparison of the two collation keys.
CollationKey()
This creates an empty collation key based on the null string.
static Collator * createInstance(UErrorCode &err)
Creates the Collator object for the current default locale.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
@ U_ZERO_ERROR
No error, no warning.
Because Collator::compare()'s algorithm is complex, it is faster to sort long lists of words by retrieving collation keys with Collator::getCollationKey(). You can then cache the collation keys and compare them using CollationKey::compareTo().
Note: Collator
s with different Locale, CollationStrength and DecompositionMode settings will return different CollationKeys for the same set of strings. Locales have specific collation rules, and the way in which secondary and tertiary differences are taken into account, for example, will result in different CollationKeys for same strings.
Definition at line 101 of file sortkey.h.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4