ICU 72.1 72.1
sortkey.h
Go to the documentation of this file.
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4 *****************************************************************************
5 * Copyright (C) 1996-2014, International Business Machines Corporation and others.
6 * All Rights Reserved.
7 *****************************************************************************
8 *
9 * File sortkey.h
10 *
11 * Created by: Helena Shih
12 *
13 * Modification History:
14 *
15 * Date Name Description
16 *
17 * 6/20/97 helena Java class name change.
18 * 8/18/97 helena Added internal API documentation.
19 * 6/26/98 erm Changed to use byte arrays and memcmp.
20 *****************************************************************************
21 */
22
23#ifndef SORTKEY_H
24#define SORTKEY_H
25
26#include "unicode/utypes.h"
27
28#if U_SHOW_CPLUSPLUS_API
29
35#if !UCONFIG_NO_COLLATION
36
37#include "unicode/uobject.h"
38#include "unicode/unistr.h"
39#include "unicode/coll.h"
40
41U_NAMESPACE_BEGIN
42
43/* forward declaration */
44class RuleBasedCollator;
45class CollationKeyByteSink;
46
102public:
111
112
119 CollationKey(const uint8_t* values,
120 int32_t count);
121
128
133 virtual ~CollationKey();
134
140 const CollationKey& operator=(const CollationKey& other);
141
148 bool operator==(const CollationKey& source) const;
149
156 bool operator!=(const CollationKey& source) const;
157
158
165 UBool isBogus(void) const;
166
176 const uint8_t* getByteArray(int32_t& count) const;
177
178#ifdef U_USE_COLLATION_KEY_DEPRECATES
186 uint8_t* toByteArray(int32_t& count) const;
187#endif
188
189#ifndef U_HIDE_DEPRECATED_API
200#endif /* U_HIDE_DEPRECATED_API */
201
212 UCollationResult compareTo(const CollationKey& target, UErrorCode &status) const;
213
234 int32_t hashCode(void) const;
235
240 virtual UClassID getDynamicClassID() const override;
241
246 static UClassID U_EXPORT2 getStaticClassID();
247
248private:
254 uint8_t *reallocate(int32_t newCapacity, int32_t length);
258 void setLength(int32_t newLength);
259
260 uint8_t *getBytes() {
261 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
262 }
263 const uint8_t *getBytes() const {
264 return (fFlagAndLength >= 0) ? fUnion.fStackBuffer : fUnion.fFields.fBytes;
265 }
266 int32_t getCapacity() const {
267 return (fFlagAndLength >= 0) ? (int32_t)sizeof(fUnion) : fUnion.fFields.fCapacity;
268 }
269 int32_t getLength() const { return fFlagAndLength & 0x7fffffff; }
270
275 CollationKey& setToBogus(void);
280 CollationKey& reset(void);
281
285 friend class RuleBasedCollator;
286 friend class CollationKeyByteSink;
287
288 // Class fields. sizeof(CollationKey) is intended to be 48 bytes
289 // on a machine with 64-bit pointers.
290 // We use a union to maximize the size of the internal buffer,
291 // similar to UnicodeString but not as tight and complex.
292
293 // (implicit) *vtable;
299 int32_t fFlagAndLength;
304 mutable int32_t fHashCode;
309 union StackBufferOrFields {
311 uint8_t fStackBuffer[32];
312 struct {
313 uint8_t *fBytes;
314 int32_t fCapacity;
315 } fFields;
316 } fUnion;
317};
318
319inline bool
321{
322 return !(*this == other);
323}
324
325inline UBool
326CollationKey::isBogus() const
327{
328 return fHashCode == 2; // kBogusHashCode
329}
330
331inline const uint8_t*
332CollationKey::getByteArray(int32_t &count) const
333{
334 count = getLength();
335 return getBytes();
336}
337
338U_NAMESPACE_END
339
340#endif /* #if !UCONFIG_NO_COLLATION */
341
342#endif /* U_SHOW_CPLUSPLUS_API */
343
344#endif
Collation keys are generated by the Collator class.
Definition: sortkey.h:101
virtual ~CollationKey()
Sort key destructor.
const CollationKey & operator=(const CollationKey &other)
Assignment operator.
CollationKey(const CollationKey &other)
Copy constructor.
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
UCollationResult compareTo(const CollationKey &target, UErrorCode &status) const
Convenience method which does a string(bit-wise) comparison of the two collation keys.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
CollationKey(const uint8_t *values, int32_t count)
Creates a collation key based on the collation key values.
Collator::EComparisonResult compareTo(const CollationKey &target) const
Convenience method which does a string(bit-wise) comparison of the two collation keys.
CollationKey()
This creates an empty collation key based on the null string.
bool operator==(const CollationKey &source) const
Compare if two collation keys are the same.
int32_t hashCode(void) const
Creates an integer that is unique to the collation key.
EComparisonResult
LESS is returned if source string is compared to be less than target string in the compare() method.
Definition: coll.h:221
The RuleBasedCollator class provides the implementation of Collator, using data-driven tables.
Definition: tblcoll.h:115
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
C++ API: Collation Service.
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:335
UCollationResult
UCOL_LESS is returned if source string is compared to be less than target string in the ucol_strcoll(...
Definition: ucol.h:76
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
C++ API: Unicode String.
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301