alphaindex.h 26 KB

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