Collation keys are generated by the Collator class
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:
. UErrorCode success = U_ZERO_ERROR; . Collator* myCollator = Collator::createInstance(success); . CollationKey* keys = new CollationKey [3]; . myCollator->getCollationKey("Tom", keys[0], success ); . myCollator->getCollationKey("Dick", keys[1], success ); . myCollator->getCollationKey("Harry", keys[2], success ); . . // Inside body of sort routine, compare keys this way: . CollationKey tmp; . if(keys[0].compareTo( keys[1] ) > 0 ) { . tmp = keys[0]; keys[0] = keys[1]; keys[1] = tmp; . } . //...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.
alphabetic index hierarchy of classes
this page has been generated automatically by doc++
(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de