]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/colldata.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
5 * Copyright (C) 1996-2012, International Business Machines *
6 * Corporation and others. All Rights Reserved. *
7 ******************************************************************************
12 * \brief Originally, added as C++ API for Collation data used to compute minLengthInChars
17 * Note: This module was incldued in ICU 4.0.1 as @internal technology preview for supporting
18 * Boyer-Moore string search API. For now, only SSearchTest depends on this module. I temporaly
19 * moved the module from i18n directory to intltest, because we have no plan to publish this
20 * as public API. (2012-12-18 yoshito)
26 #include "unicode/utypes.h"
28 #if !UCONFIG_NO_COLLATION
30 #include "unicode/ucol.h"
31 #include "unicode/unistr.h"
34 * The size of the internal CE buffer in a <code>CEList</code> object
36 #define CELIST_BUFFER_SIZE 4
39 * \def INSTRUMENT_CELIST
40 * Define this to enable the <code>CEList</code> objects to collect
45 * The size of the initial list in a <code>StringList</code> object.
47 #define STRING_LIST_BUFFER_SIZE 16
52 * This object holds a list of CEs generated from a particular
53 * <code>UnicodeString</code>
60 * Construct a <code>CEList</code> object.
62 * @param coll - the Collator used to collect the CEs.
63 * @param string - the string for which to collect the CEs.
64 * @param status - will be set if any errors occur.
66 * Note: if on return, status is set to an error code,
67 * the only safe thing to do with this object is to call
70 CEList(UCollator
*coll
, const UnicodeString
&string
, UErrorCode
&status
);
78 * Return the number of CEs in the list.
80 * @return the number of CEs in the list.
85 * Get a particular CE from the list.
87 * @param index - the index of the CE to return
89 * @return the CE, or <code>0</code> if <code>index</code> is out of range
91 uint32_t get(int32_t index
) const;
94 * Check if the CEs in another <code>CEList</code> match the
95 * suffix of this list starting at a give offset.
97 * @param offset - the offset of the suffix
98 * @param other - the other <code>CEList</code>
100 * @return <code>TRUE</code> if the CEs match, <code>FALSE</code> otherwise.
102 UBool
matchesAt(int32_t offset
, const CEList
*other
) const;
105 * The index operator.
107 * @param index - the index
109 * @return a reference to the given CE in the list
111 uint32_t &operator[](int32_t index
) const;
114 void add(uint32_t ce
, UErrorCode
&status
);
116 uint32_t ceBuffer
[CELIST_BUFFER_SIZE
];
125 * This object holds a list of <code>UnicodeString</code> objects.
131 * Construct an empty <code>StringList</code>
133 * @param status - will be set if any errors occur.
135 * Note: if on return, status is set to an error code,
136 * the only safe thing to do with this object is to call
139 StringList(UErrorCode
&status
);
147 * Add a string to the list.
149 * @param string - the string to add
150 * @param status - will be set if any errors occur.
152 void add(const UnicodeString
*string
, UErrorCode
&status
);
155 * Add an array of Unicode code points to the list.
157 * @param chars - the address of the array of code points
158 * @param count - the number of code points in the array
159 * @param status - will be set if any errors occur.
161 void add(const UChar
*chars
, int32_t count
, UErrorCode
&status
);
164 * Get a particular string from the list.
166 * @param index - the index of the string
168 * @return a pointer to the <code>UnicodeString</code> or <code>NULL</code>
169 * if <code>index</code> is out of bounds.
171 const UnicodeString
*get(int32_t index
) const;
174 * Get the number of stings in the list.
176 * @return the number of strings in the list.
178 int32_t size() const;
181 UnicodeString
*strings
;
188 * Forward references to internal classes.
190 class StringToCEsMap
;
191 class CEToStringsMap
;
196 * This class holds the Collator-specific data needed to
197 * compute the length of the shortest string that can
198 * generate a partcular list of CEs.
200 * <code>CollData</code> objects are quite expensive to compute. Because
201 * of this, they are cached. When you call <code>CollData::open</code> it
202 * returns a reference counted cached object. When you call <code>CollData::close</code>
203 * the reference count on the object is decremented but the object is not deleted.
205 * If you do not need to reuse any unreferenced objects in the cache, you can call
206 * <code>CollData::flushCollDataCache</code>. If you no longer need any <code>CollData</code>
207 * objects, you can call <code>CollData::freeCollDataCache</code>
213 * Construct a <code>CollData</code> object.
215 * @param collator - the collator
216 * @param status - will be set if any errors occur.
218 CollData(UCollator
*collator
, UErrorCode
&status
);
226 * Get the <code>UCollator</code> object used to create this object.
227 * The object returned may not be the exact object that was used to
228 * create this object, but it will have the same behavior.
230 UCollator
*getCollator() const;
233 * Get a list of all the strings which generate a list
234 * of CEs starting with a given CE.
238 * return a <code>StringList</code> object containing all
239 * the stirngs, or <code>NULL</code> if there are
242 const StringList
*getStringList(int32_t ce
) const;
245 * Get a list of the CEs generated by a partcular stirng.
247 * @param string - the string
249 * @return a <code>CEList</code> object containt the CEs. You
250 * must call <code>freeCEList</code> when you are finished
251 * using the <code>CEList</code>/
253 const CEList
*getCEList(const UnicodeString
*string
) const;
256 * Release a <code>CEList</code> returned by <code>getCEList</code>.
258 * @param list - the <code>CEList</code> to free.
260 void freeCEList(const CEList
*list
);
263 * Return the length of the shortest string that will generate
264 * the given list of CEs.
266 * @param ces - the CEs
267 * @param offset - the offset of the first CE in the list to use.
269 * @return the length of the shortest string.
271 int32_t minLengthInChars(const CEList
*ces
, int32_t offset
) const;
275 * Return the length of the shortest string that will generate
276 * the given list of CEs.
278 * Note: the algorithm used to do this computation is recursive. To
279 * limit the amount of recursion, a "history" list is used to record
280 * the best answer starting at a particular offset in the list of CEs.
281 * If the same offset is visited again during the recursion, the answer
282 * in the history list is used.
284 * @param ces - the CEs
285 * @param offset - the offset of the first CE in the list to use.
286 * @param history - the history list. Must be at least as long as
287 * the number of cEs in the <code>CEList</code>
289 * @return the length of the shortest string.
291 int32_t minLengthInChars(const CEList
*ces
, int32_t offset
, int32_t *history
) const;
295 CEToStringsMap
*ceToCharsStartingWith
;
300 uint32_t jamoLimits
[4];
303 #endif // #if !UCONFIG_NO_COLLATION
304 #endif // #ifndef COLL_DATA_H