* ... A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ... * * A * Addison * Albertson * Azensky * B * Baker * ... *
* The class also supports having buckets for strings before the first (underflow), * after the last (overflow), and between scripts (inflow). For example, if the index * is constructed with labels for Russian and English, Greek characters would fall * into an inflow bucket between the other two scripts. *
* The AlphabeticIndex class is not intended for public subclassing. * *
Note: If you expect to have a lot of ASCII or Latin characters * as well as characters from the user's language, * then it is a good idea to call addLabels(Locale::getEnglish(), status).
The following shows an example of building an index directly. * The "show..." methods below are just to illustrate usage. * *
* // Create a simple index. "Item" is assumed to be an application * // defined type that the application's UI and other processing knows about, * // and that has a name. * * UErrorCode status = U_ZERO_ERROR; * AlphabeticIndex index = new AlphabeticIndex(desiredLocale, status); * index->addLabels(additionalLocale, status); * for (Item *item in some source of Items ) { * index->addRecord(item->name(), item, status); * } * ... * // Show index at top. We could skip or gray out empty buckets * * while (index->nextBucket(status)) { * if (showAll || index->getBucketRecordCount() != 0) { * showLabelAtTop(UI, index->getBucketLabel()); * } * } * ... * // Show the buckets with their contents, skipping empty buckets * * index->resetBucketIterator(status); * while (index->nextBucket(status)) { * if (index->getBucketRecordCount() != 0) { * showLabelInList(UI, index->getBucketLabel()); * while (index->nextRecord(status)) { * showIndexedItem(UI, static_cast(index->getRecordData())) *
* ... A-F G-N O-Z ... *
Callers can also use the AlphabeticIndex::ImmutableIndex, or the AlphabeticIndex itself, * to support sorting on a client that doesn't support AlphabeticIndex functionality. * *
The ImmutableIndex is both immutable and thread-safe. * The corresponding AlphabeticIndex methods are not thread-safe because * they "lazily" build the index buckets. *
* int32_t bucketIndex = index.getBucketIndex(name, status); * const UnicodeString &label = immutableIndex.getBucket(bucketIndex)->getLabel(); // optional * int32_t skLength = collator.getSortKey(name, sk, skCapacity); *