Home | History | Annotate | Download | only in unicode
      1 /*
      2 *******************************************************************************
      3 *
      4 *   Copyright (C) 2011-2013 International Business Machines
      5 *   Corporation and others.  All Rights Reserved.
      6 *
      7 *******************************************************************************
      8 */
      9 
     10 #ifndef INDEXCHARS_H
     11 #define INDEXCHARS_H
     12 
     13 #include "unicode/utypes.h"
     14 #include "unicode/uobject.h"
     15 #include "unicode/locid.h"
     16 
     17 
     18 #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_NORMALIZATION
     19 
     20 /**
     21  * \file
     22  * \brief C++ API: Index Characters
     23  */
     24 
     25 U_CDECL_BEGIN
     26 
     27 /**
     28  * Constants for Alphabetic Index Label Types.
     29  * The form of these enum constants anticipates having a plain C API
     30  * for Alphabetic Indexes that will also use them.
     31  * @stable ICU 4.8
     32  */
     33 typedef enum UAlphabeticIndexLabelType {
     34     /**
     35      *  Normal Label, typically the starting letter of the names
     36      *  in the bucket with this label.
     37      * @stable ICU 4.8
     38      */
     39     U_ALPHAINDEX_NORMAL    = 0,
     40 
     41     /**
     42      * Undeflow Label.  The bucket with this label contains names
     43      * in scripts that sort before any of the bucket labels in this index.
     44      * @stable ICU 4.8
     45      */
     46     U_ALPHAINDEX_UNDERFLOW = 1,
     47 
     48     /**
     49      * Inflow Label.  The bucket with this label contains names
     50      * in scripts that sort between two of the bucket labels in this index.
     51      * Inflow labels are created when an index contains normal labels for
     52      * multiple scripts, and skips other scripts that sort between some of the
     53      * included scripts.
     54      * @stable ICU 4.8
     55      */
     56     U_ALPHAINDEX_INFLOW    = 2,
     57 
     58     /**
     59      * Overflow Label. Te bucket with this label contains names in scripts
     60      * that sort after all of the bucket labels in this index.
     61      * @stable ICU 4.8
     62      */
     63     U_ALPHAINDEX_OVERFLOW  = 3
     64 } UAlphabeticIndexLabelType;
     65 
     66 
     67 struct UHashtable;
     68 U_CDECL_END
     69 
     70 U_NAMESPACE_BEGIN
     71 
     72 // Forward Declarations
     73 
     74 class BucketList;
     75 class Collator;
     76 class RuleBasedCollator;
     77 class StringEnumeration;
     78 class UnicodeSet;
     79 class UVector;
     80 
     81 /**
     82  * AlphabeticIndex supports the creation of a UI index appropriate for a given language.
     83  * It can support either direct use, or use with a client that doesn't support localized collation.
     84  * The following is an example of what an index might look like in a UI:
     85  *
     86  * <pre>
     87  *  <b>... 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  ...</b>
     88  *
     89  *  <b>A</b>
     90  *     Addison
     91  *     Albertson
     92  *     Azensky
     93  *  <b>B</b>
     94  *     Baker
     95  *  ...
     96  * </pre>
     97  *
     98  * The class can generate a list of labels for use as a UI "index", that is, a list of
     99  * clickable characters (or character sequences) that allow the user to see a segment
    100  * (bucket) of a larger "target" list. That is, each label corresponds to a bucket in
    101  * the target list, where everything in the bucket is greater than or equal to the character
    102  * (according to the locale's collation). Strings can be added to the index;
    103  * they will be in sorted order in the right bucket.
    104  * <p>
    105  * The class also supports having buckets for strings before the first (underflow),
    106  * after the last (overflow), and between scripts (inflow). For example, if the index
    107  * is constructed with labels for Russian and English, Greek characters would fall
    108  * into an inflow bucket between the other two scripts.
    109  * <p>
    110  * The AlphabeticIndex class is not intended for public subclassing.
    111  *
    112  * <p><em>Note:</em> If you expect to have a lot of ASCII or Latin characters
    113  * as well as characters from the user's language,
    114  * then it is a good idea to call addLabels(Locale::getEnglish(), status).</p>
    115  *
    116  * <h2>Direct Use</h2>
    117  * <p>The following shows an example of building an index directly.
    118  *  The "show..." methods below are just to illustrate usage.
    119  *
    120  * <pre>
    121  * // Create a simple index.  "Item" is assumed to be an application
    122  * // defined type that the application's UI and other processing knows about,
    123  * //  and that has a name.
    124  *
    125  * UErrorCode status = U_ZERO_ERROR;
    126  * AlphabeticIndex index = new AlphabeticIndex(desiredLocale, status);
    127  * index->addLabels(additionalLocale, status);
    128  * for (Item *item in some source of Items ) {
    129  *     index->addRecord(item->name(), item, status);
    130  * }
    131  * ...
    132  * // Show index at top. We could skip or gray out empty buckets
    133  *
    134  * while (index->nextBucket(status)) {
    135  *     if (showAll || index->getBucketRecordCount() != 0) {
    136  *         showLabelAtTop(UI, index->getBucketLabel());
    137  *     }
    138  * }
    139  *  ...
    140  * // Show the buckets with their contents, skipping empty buckets
    141  *
    142  * index->resetBucketIterator(status);
    143  * while (index->nextBucket(status)) {
    144  *    if (index->getBucketRecordCount() != 0) {
    145  *        showLabelInList(UI, index->getBucketLabel());
    146  *        while (index->nextRecord(status)) {
    147  *            showIndexedItem(UI, static_cast<Item *>(index->getRecordData()))
    148  * </pre>
    149  *
    150  * The caller can build different UIs using this class.
    151  * For example, an index character could be omitted or grayed-out
    152  * if its bucket is empty. Small buckets could also be combined based on size, such as:
    153  *
    154  * <pre>
    155  * <b>... A-F G-N O-Z ...</b>
    156  * </pre>
    157  *
    158  * <h2>Client Support</h2>
    159  * <p>Callers can also use the AlphabeticIndex::ImmutableIndex, or the AlphabeticIndex itself,
    160  * to support sorting on a client that doesn't support AlphabeticIndex functionality.
    161  *
    162  * <p>The ImmutableIndex is both immutable and thread-safe.
    163  * The corresponding AlphabeticIndex methods are not thread-safe because
    164  * they "lazily" build the index buckets.
    165  * <ul>
    166  * <li>ImmutableIndex.getBucket(index) provides random access to all
    167  *     buckets and their labels and label types.
    168  * <li>The AlphabeticIndex bucket iterator or ImmutableIndex.getBucket(0..getBucketCount-1)
    169  *     can be used to get a list of the labels,
    170  *     such as "...", "A", "B",..., and send that list to the client.
    171  * <li>When the client has a new name, it sends that name to the server.
    172  * The server needs to call the following methods,
    173  * and communicate the bucketIndex and collationKey back to the client.
    174  *
    175  * <pre>
    176  * int32_t bucketIndex = index.getBucketIndex(name, status);
    177  * const UnicodeString &label = immutableIndex.getBucket(bucketIndex)->getLabel();  // optional
    178  * int32_t skLength = collator.getSortKey(name, sk, skCapacity);
    179  * </pre>
    180  *
    181  * <li>The client would put the name (and associated information) into its bucket for bucketIndex. The sort key sk is a
    182  * sequence of bytes that can be compared with a binary compare, and produce the right localized result.</li>
    183  * </ul>
    184  *
    185  * @stable ICU 4.8
    186  */
    187 class U_I18N_API AlphabeticIndex: public UObject {
    188 public:
    189 #ifdef U_HIDE_DRAFT_API
    190     class Bucket;
    191 #else
    192      /**
    193       * An index "bucket" with a label string and type.
    194       * It is referenced by getBucketIndex(),
    195       * and returned by ImmutableIndex.getBucket().
    196       *
    197       * The Bucket class is not intended for public subclassing.
    198       * @draft ICU 51
    199       */
    200      class U_I18N_API Bucket : public UObject {
    201      public:
    202         /**
    203          * Destructor.
    204          * @draft ICU 51
    205          */
    206         virtual ~Bucket();
    207 
    208         /**
    209          * Returns the label string.
    210          *
    211          * @return the label string for the bucket
    212          * @draft ICU 51
    213          */
    214         const UnicodeString &getLabel() const { return label_; }
    215         /**
    216          * Returns whether this bucket is a normal, underflow, overflow, or inflow bucket.
    217          *
    218          * @return the bucket label type
    219          * @draft ICU 51
    220          */
    221         UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
    222 
    223      private:
    224         friend class AlphabeticIndex;
    225         friend class BucketList;
    226 
    227         UnicodeString label_;
    228         UnicodeString lowerBoundary_;
    229         UAlphabeticIndexLabelType labelType_;
    230         Bucket *displayBucket_;
    231         int32_t displayIndex_;
    232         UVector *records_;  // Records are owned by the inputList_ vector.
    233 
    234         Bucket(const UnicodeString &label,   // Parameter strings are copied.
    235                const UnicodeString &lowerBoundary,
    236                UAlphabeticIndexLabelType type);
    237      };
    238 
    239     /**
    240      * Immutable, thread-safe version of AlphabeticIndex.
    241      * This class provides thread-safe methods for bucketing,
    242      * and random access to buckets and their properties,
    243      * but does not offer adding records to the index.
    244      *
    245      * The ImmutableIndex class is not intended for public subclassing.
    246      *
    247      * @draft ICU 51
    248      */
    249     class U_I18N_API ImmutableIndex : public UObject {
    250     public:
    251         /**
    252          * Destructor.
    253          * @draft ICU 51
    254          */
    255         virtual ~ImmutableIndex();
    256 
    257         /**
    258          * Returns the number of index buckets and labels, including underflow/inflow/overflow.
    259          *
    260          * @return the number of index buckets
    261          * @draft ICU 51
    262          */
    263         int32_t getBucketCount() const;
    264 
    265         /**
    266          * Finds the index bucket for the given name and returns the number of that bucket.
    267          * Use getBucket() to get the bucket's properties.
    268          *
    269          * @param name the string to be sorted into an index bucket
    270          * @return the bucket number for the name
    271          * @draft ICU 51
    272          */
    273         int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
    274 
    275         /**
    276          * Returns the index-th bucket. Returns NULL if the index is out of range.
    277          *
    278          * @param index bucket number
    279          * @return the index-th bucket
    280          * @draft ICU 51
    281          */
    282         const Bucket *getBucket(int32_t index) const;
    283 
    284     private:
    285         friend class AlphabeticIndex;
    286 
    287         ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
    288                 : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
    289 
    290         BucketList *buckets_;
    291         Collator *collatorPrimaryOnly_;
    292     };
    293 #endif  /* U_HIDE_DRAFT_API */
    294 
    295     /**
    296      * Construct an AlphabeticIndex object for the specified locale.  If the locale's
    297      * data does not include index characters, a set of them will be
    298      * synthesized based on the locale's exemplar characters.  The locale
    299      * determines the sorting order for both the index characters and the
    300      * user item names appearing under each Index character.
    301      *
    302      * @param locale the desired locale.
    303      * @param status Error code, will be set with the reason if the construction
    304      *               of the AlphabeticIndex object fails.
    305      * @stable ICU 4.8
    306      */
    307      AlphabeticIndex(const Locale &locale, UErrorCode &status);
    308 
    309 #ifndef U_HIDE_DRAFT_API
    310    /**
    311      * Construct an AlphabeticIndex that uses a specific collator.
    312      *
    313      * The index will be created with no labels; the addLabels() function must be called
    314      * after creation to add the desired labels to the index.
    315      *
    316      * The index adopts the collator, and is responsible for deleting it.
    317      * The caller should make no further use of the collator after creating the index.
    318      *
    319      * @param collator The collator to use to order the contents of this index.
    320      * @param status Error code, will be set with the reason if the
    321      *               operation fails.
    322      * @draft ICU 51
    323      */
    324     AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
    325 #endif  /* U_HIDE_DRAFT_API */
    326 
    327     /**
    328      * Add Labels to this Index.  The labels are additions to those
    329      * that are already in the index; they do not replace the existing
    330      * ones.
    331      * @param additions The additional characters to add to the index, such as A-Z.
    332      * @param status Error code, will be set with the reason if the
    333      *               operation fails.
    334      * @return this, for chaining
    335      * @stable ICU 4.8
    336      */
    337     virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
    338 
    339     /**
    340      * Add the index characters from a Locale to the index.  The labels
    341      * are added to those that are already in the index; they do not replace the
    342      * existing index characters.  The collation order for this index is not
    343      * changed; it remains that of the locale that was originally specified
    344      * when creating this Index.
    345      *
    346      * @param locale The locale whose index characters are to be added.
    347      * @param status Error code, will be set with the reason if the
    348      *               operation fails.
    349      * @return this, for chaining
    350      * @stable ICU 4.8
    351      */
    352     virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
    353 
    354      /**
    355       * Destructor
    356       * @stable ICU 4.8
    357       */
    358     virtual ~AlphabeticIndex();
    359 
    360 #ifndef U_HIDE_DRAFT_API
    361     /**
    362      * Builds an immutable, thread-safe version of this instance, without data records.
    363      *
    364      * @return an immutable index instance
    365      * @draft ICU 51
    366      */
    367     ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
    368 #endif  /* U_HIDE_DRAFT_API */
    369 
    370     /**
    371      * Get the Collator that establishes the ordering of the items in this index.
    372      * Ownership of the collator remains with the AlphabeticIndex instance.
    373      *
    374      * The returned collator is a reference to the internal collator used by this
    375      * index.  It may be safely used to compare the names of items or to get
    376      * sort keys for names.  However if any settings need to be changed,
    377      * or other non-const methods called, a cloned copy must be made first.
    378      *
    379      * @return The collator
    380      * @stable ICU 4.8
    381      */
    382     virtual const RuleBasedCollator &getCollator() const;
    383 
    384 
    385    /**
    386      * Get the default label used for abbreviated buckets <i>between</i> other index characters.
    387      * For example, consider the labels when Latin and Greek are used:
    388      *     X Y Z ... &#x0391; &#x0392; &#x0393;.
    389      *
    390      * @return inflow label
    391      * @stable ICU 4.8
    392      */
    393     virtual const UnicodeString &getInflowLabel() const;
    394 
    395    /**
    396      * Set the default label used for abbreviated buckets <i>between</i> other index characters.
    397      * An inflow label will be automatically inserted if two otherwise-adjacent label characters
    398      * are from different scripts, e.g. Latin and Cyrillic, and a third script, e.g. Greek,
    399      * sorts between the two.  The default inflow character is an ellipsis (...)
    400      *
    401      * @param inflowLabel the new Inflow label.
    402      * @param status Error code, will be set with the reason if the operation fails.
    403      * @return this
    404      * @stable ICU 4.8
    405      */
    406     virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status);
    407 
    408 
    409    /**
    410      * Get the special label used for items that sort after the last normal label,
    411      * and that would not otherwise have an appropriate label.
    412      *
    413      * @return the overflow label
    414      * @stable ICU 4.8
    415      */
    416     virtual const UnicodeString &getOverflowLabel() const;
    417 
    418 
    419    /**
    420      * Set the label used for items that sort after the last normal label,
    421      * and that would not otherwise have an appropriate label.
    422      *
    423      * @param overflowLabel the new overflow label.
    424      * @param status Error code, will be set with the reason if the operation fails.
    425      * @return this
    426      * @stable ICU 4.8
    427      */
    428     virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status);
    429 
    430    /**
    431      * Get the special label used for items that sort before the first normal label,
    432      * and that would not otherwise have an appropriate label.
    433      *
    434      * @return underflow label
    435      * @stable ICU 4.8
    436      */
    437     virtual const UnicodeString &getUnderflowLabel() const;
    438 
    439    /**
    440      * Set the label used for items that sort before the first normal label,
    441      * and that would not otherwise have an appropriate label.
    442      *
    443      * @param underflowLabel the new underflow label.
    444      * @param status Error code, will be set with the reason if the operation fails.
    445      * @return this
    446      * @stable ICU 4.8
    447      */
    448     virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status);
    449 
    450 
    451     /**
    452      * Get the limit on the number of labels permitted in the index.
    453      * The number does not include over, under and inflow labels.
    454      *
    455      * @return maxLabelCount maximum number of labels.
    456      * @stable ICU 4.8
    457      */
    458     virtual int32_t getMaxLabelCount() const;
    459 
    460     /**
    461      * Set a limit on the number of labels permitted in the index.
    462      * The number does not include over, under and inflow labels.
    463      * Currently, if the number is exceeded, then every
    464      * nth item is removed to bring the count down.
    465      * A more sophisticated mechanism may be available in the future.
    466      *
    467      * @param maxLabelCount the maximum number of labels.
    468      * @param status error code
    469      * @return This, for chaining
    470      * @stable ICU 4.8
    471      */
    472     virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status);
    473 
    474 
    475     /**
    476      * Add a record to the index.  Each record will be associated with an index Bucket
    477      *  based on the record's name.  The list of records for each bucket will be sorted
    478      *  based on the collation ordering of the names in the index's locale.
    479      *  Records with duplicate names are permitted; they will be kept in the order
    480      *  that they were added.
    481      *
    482      * @param name The display name for the Record.  The Record will be placed in
    483      *             a bucket based on this name.
    484      * @param data An optional pointer to user data associated with this
    485      *             item.  When iterating the contents of a bucket, both the
    486      *             data pointer the name will be available for each Record.
    487      * @param status  Error code, will be set with the reason if the operation fails.
    488      * @return        This, for chaining.
    489      * @stable ICU 4.8
    490      */
    491     virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
    492 
    493     /**
    494      * Remove all Records from the Index.  The set of Buckets, which define the headings under
    495      * which records are classified, is not altered.
    496      *
    497      * @param status  Error code, will be set with the reason if the operation fails.
    498      * @return        This, for chaining.
    499      * @stable ICU 4.8
    500      */
    501     virtual AlphabeticIndex &clearRecords(UErrorCode &status);
    502 
    503 
    504     /**  Get the number of labels in this index.
    505      *      Note: may trigger lazy index construction.
    506      *
    507      * @param status  Error code, will be set with the reason if the operation fails.
    508      * @return        The number of labels in this index, including any under, over or
    509      *                in-flow labels.
    510      * @stable ICU 4.8
    511      */
    512     virtual int32_t  getBucketCount(UErrorCode &status);
    513 
    514 
    515     /**  Get the total number of Records in this index, that is, the number
    516      *   of <name, data> pairs added.
    517      *
    518      * @param status  Error code, will be set with the reason if the operation fails.
    519      * @return        The number of records in this index, that is, the total number
    520      *                of (name, data) items added with addRecord().
    521      * @stable ICU 4.8
    522      */
    523     virtual int32_t  getRecordCount(UErrorCode &status);
    524 
    525 
    526 
    527     /**
    528      *   Given the name of a record, return the zero-based index of the Bucket
    529      *   in which the item should appear.  The name need not be in the index.
    530      *   A Record will not be added to the index by this function.
    531      *   Bucket numbers are zero-based, in Bucket iteration order.
    532      *
    533      * @param itemName  The name whose bucket position in the index is to be determined.
    534      * @param status  Error code, will be set with the reason if the operation fails.
    535      * @return The bucket number for this name.
    536      * @stable ICU 4.8
    537      *
    538      */
    539     virtual int32_t  getBucketIndex(const UnicodeString &itemName, UErrorCode &status);
    540 
    541 
    542     /**
    543      *   Get the zero based index of the current Bucket from an iteration
    544      *   over the Buckets of this index.  Return -1 if no iteration is in process.
    545      *   @return  the index of the current Bucket
    546      *   @stable ICU 4.8
    547      */
    548     virtual int32_t  getBucketIndex() const;
    549 
    550 
    551     /**
    552      *   Advance the iteration over the Buckets of this index.  Return FALSE if
    553      *   there are no more Buckets.
    554      *
    555      *   @param status  Error code, will be set with the reason if the operation fails.
    556      *   U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while
    557      *   an enumeration of its contents are in process.
    558      *
    559      *   @return TRUE if success, FALSE if at end of iteration
    560      *   @stable ICU 4.8
    561      */
    562     virtual UBool nextBucket(UErrorCode &status);
    563 
    564     /**
    565      *   Return the name of the Label of the current bucket from an iteration over the buckets.
    566      *   If the iteration is before the first Bucket (nextBucket() has not been called),
    567      *   or after the last, return an empty string.
    568      *
    569      *   @return the bucket label.
    570      *   @stable ICU 4.8
    571      */
    572     virtual const UnicodeString &getBucketLabel() const;
    573 
    574     /**
    575      *  Return the type of the label for the current Bucket (selected by the
    576      *  iteration over Buckets.)
    577      *
    578      * @return the label type.
    579      * @stable ICU 4.8
    580      */
    581     virtual UAlphabeticIndexLabelType getBucketLabelType() const;
    582 
    583     /**
    584       * Get the number of <name, data> Records in the current Bucket.
    585       * If the current bucket iteration position is before the first label or after the
    586       * last, return 0.
    587       *
    588       *  @return the number of Records.
    589       *  @stable ICU 4.8
    590       */
    591     virtual int32_t getBucketRecordCount() const;
    592 
    593 
    594     /**
    595      *  Reset the Bucket iteration for this index.  The next call to nextBucket()
    596      *  will restart the iteration at the first label.
    597      *
    598      * @param status  Error code, will be set with the reason if the operation fails.
    599      * @return        this, for chaining.
    600      * @stable ICU 4.8
    601      */
    602     virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status);
    603 
    604     /**
    605      * Advance to the next record in the current Bucket.
    606      * When nextBucket() is called, Record iteration is reset to just before the
    607      * first Record in the new Bucket.
    608      *
    609      *   @param status  Error code, will be set with the reason if the operation fails.
    610      *   U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while
    611      *   an enumeration of its contents are in process.
    612      *   @return TRUE if successful, FALSE when the iteration advances past the last item.
    613      *   @stable ICU 4.8
    614      */
    615     virtual UBool nextRecord(UErrorCode &status);
    616 
    617     /**
    618      * Get the name of the current Record.
    619      * Return an empty string if the Record iteration position is before first
    620      * or after the last.
    621      *
    622      *  @return The name of the current index item.
    623      *  @stable ICU 4.8
    624      */
    625     virtual const UnicodeString &getRecordName() const;
    626 
    627 
    628     /**
    629      * Return the data pointer of the Record currently being iterated over.
    630      * Return NULL if the current iteration position before the first item in this Bucket,
    631      * or after the last.
    632      *
    633      *  @return The current Record's data pointer.
    634      *  @stable ICU 4.8
    635      */
    636     virtual const void *getRecordData() const;
    637 
    638 
    639     /**
    640      * Reset the Record iterator position to before the first Record in the current Bucket.
    641      *
    642      *  @return This, for chaining.
    643      *  @stable ICU 4.8
    644      */
    645     virtual AlphabeticIndex &resetRecordIterator();
    646 
    647 private:
    648      /**
    649       * No Copy constructor.
    650       * @internal
    651       */
    652      AlphabeticIndex(const AlphabeticIndex &other);
    653 
    654      /**
    655       *   No assignment.
    656       */
    657      AlphabeticIndex &operator =(const AlphabeticIndex & /*other*/) { return *this;};
    658 
    659     /**
    660      * No Equality operators.
    661      * @internal
    662      */
    663      virtual UBool operator==(const AlphabeticIndex& other) const;
    664 
    665     /**
    666      * Inequality operator.
    667      * @internal
    668      */
    669      virtual UBool operator!=(const AlphabeticIndex& other) const;
    670 
    671      // Common initialization, for use from all constructors.
    672      void init(const Locale *locale, UErrorCode &status);
    673 
    674     /**
    675      * This method is called to get the index exemplars. Normally these come from the locale directly,
    676      * but if they aren't available, we have to synthesize them.
    677      */
    678     void addIndexExemplars(const Locale &locale, UErrorCode &status);
    679     /**
    680      * Add Chinese index characters from the tailoring.
    681      */
    682     UBool addChineseIndexCharacters(UErrorCode &errorCode);
    683 
    684     UVector *firstStringsInScript(UErrorCode &status);
    685 
    686     static UnicodeString separated(const UnicodeString &item);
    687 
    688     /**
    689      * Determine the best labels to use.
    690      * This is based on the exemplars, but we also process to make sure that they are unique,
    691      * and sort differently, and that the overall list is small enough.
    692      */
    693     void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
    694     BucketList *createBucketList(UErrorCode &errorCode) const;
    695     void initBuckets(UErrorCode &errorCode);
    696     void clearBuckets();
    697     void internalResetBucketIterator();
    698 
    699 public:
    700 
    701     //  The Record is declared public only to allow access from
    702     //  implementation code written in plain C.
    703     //  It is not intended for public use.
    704 
    705 #ifndef U_HIDE_INTERNAL_API
    706     /**
    707      * A (name, data) pair, to be sorted by name into one of the index buckets.
    708      * The user data is not used by the index implementation.
    709      * @internal
    710      */
    711     struct Record: public UMemory {
    712         const UnicodeString  name_;
    713         const void           *data_;
    714         Record(const UnicodeString &name, const void *data);
    715         ~Record();
    716     };
    717 #endif  /* U_HIDE_INTERNAL_API */
    718 
    719 private:
    720 
    721     /**
    722      * Holds all user records before they are distributed into buckets.
    723      * Type of contents is (Record *)
    724      * @internal
    725      */
    726     UVector  *inputList_;
    727 
    728     int32_t  labelsIterIndex_;        // Index of next item to return.
    729     int32_t  itemsIterIndex_;
    730     Bucket   *currentBucket_;         // While an iteration of the index in underway,
    731                                       //   point to the bucket for the current label.
    732                                       // NULL when no iteration underway.
    733 
    734     int32_t    maxLabelCount_;        // Limit on # of labels permitted in the index.
    735 
    736     UnicodeSet *initialLabels_;       // Initial (unprocessed) set of Labels.  Union
    737                                       //   of those explicitly set by the user plus
    738                                       //   those from locales.  Raw values, before
    739                                       //   crunching into bucket labels.
    740 
    741     UVector *firstCharsInScripts_;    // The first character from each script,
    742                                       //   in collation order.
    743 
    744     RuleBasedCollator *collator_;
    745     RuleBasedCollator *collatorPrimaryOnly_;
    746 
    747     // Lazy evaluated: null means that we have not built yet.
    748     BucketList *buckets_;
    749 
    750     UnicodeString  inflowLabel_;
    751     UnicodeString  overflowLabel_;
    752     UnicodeString  underflowLabel_;
    753     UnicodeString  overflowComparisonString_;
    754 
    755     UnicodeString emptyString_;
    756 };
    757 
    758 U_NAMESPACE_END
    759 
    760 #endif /* UCONFIG_NO_COLLATION / UCONFIG_NO_NORMALIZATION */
    761 #endif
    762