xref: /aosp_15_r20/external/icu/libicu/cts_headers/collationfastlatin.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker *******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2013-2015, International Business Machines
6*0e209d39SAndroid Build Coastguard Worker * Corporation and others.  All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker *******************************************************************************
8*0e209d39SAndroid Build Coastguard Worker * collationfastlatin.h
9*0e209d39SAndroid Build Coastguard Worker *
10*0e209d39SAndroid Build Coastguard Worker * created on: 2013aug09
11*0e209d39SAndroid Build Coastguard Worker * created by: Markus W. Scherer
12*0e209d39SAndroid Build Coastguard Worker */
13*0e209d39SAndroid Build Coastguard Worker 
14*0e209d39SAndroid Build Coastguard Worker #ifndef __COLLATIONFASTLATIN_H__
15*0e209d39SAndroid Build Coastguard Worker #define __COLLATIONFASTLATIN_H__
16*0e209d39SAndroid Build Coastguard Worker 
17*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
18*0e209d39SAndroid Build Coastguard Worker 
19*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_COLLATION
20*0e209d39SAndroid Build Coastguard Worker 
21*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
22*0e209d39SAndroid Build Coastguard Worker 
23*0e209d39SAndroid Build Coastguard Worker struct CollationData;
24*0e209d39SAndroid Build Coastguard Worker struct CollationSettings;
25*0e209d39SAndroid Build Coastguard Worker 
26*0e209d39SAndroid Build Coastguard Worker class U_I18N_API CollationFastLatin /* all static */ {
27*0e209d39SAndroid Build Coastguard Worker public:
28*0e209d39SAndroid Build Coastguard Worker     /**
29*0e209d39SAndroid Build Coastguard Worker      * Fast Latin format version (one byte 1..FF).
30*0e209d39SAndroid Build Coastguard Worker      * Must be incremented for any runtime-incompatible changes,
31*0e209d39SAndroid Build Coastguard Worker      * in particular, for changes to any of the following constants.
32*0e209d39SAndroid Build Coastguard Worker      *
33*0e209d39SAndroid Build Coastguard Worker      * When the major version number of the main data format changes,
34*0e209d39SAndroid Build Coastguard Worker      * we can reset this fast Latin version to 1.
35*0e209d39SAndroid Build Coastguard Worker      */
36*0e209d39SAndroid Build Coastguard Worker     static const uint16_t VERSION = 2;
37*0e209d39SAndroid Build Coastguard Worker 
38*0e209d39SAndroid Build Coastguard Worker     static const int32_t LATIN_MAX = 0x17f;
39*0e209d39SAndroid Build Coastguard Worker     static const int32_t LATIN_LIMIT = LATIN_MAX + 1;
40*0e209d39SAndroid Build Coastguard Worker 
41*0e209d39SAndroid Build Coastguard Worker     static const int32_t LATIN_MAX_UTF8_LEAD = 0xc5;  // UTF-8 lead byte of LATIN_MAX
42*0e209d39SAndroid Build Coastguard Worker 
43*0e209d39SAndroid Build Coastguard Worker     static const int32_t PUNCT_START = 0x2000;
44*0e209d39SAndroid Build Coastguard Worker     static const int32_t PUNCT_LIMIT = 0x2040;
45*0e209d39SAndroid Build Coastguard Worker 
46*0e209d39SAndroid Build Coastguard Worker     // excludes U+FFFE & U+FFFF
47*0e209d39SAndroid Build Coastguard Worker     static const int32_t NUM_FAST_CHARS = LATIN_LIMIT + (PUNCT_LIMIT - PUNCT_START);
48*0e209d39SAndroid Build Coastguard Worker 
49*0e209d39SAndroid Build Coastguard Worker     // Note on the supported weight ranges:
50*0e209d39SAndroid Build Coastguard Worker     // Analysis of UCA 6.3 and CLDR 23 non-search tailorings shows that
51*0e209d39SAndroid Build Coastguard Worker     // the CEs for characters in the above ranges, excluding expansions with length >2,
52*0e209d39SAndroid Build Coastguard Worker     // excluding contractions of >2 characters, and other restrictions
53*0e209d39SAndroid Build Coastguard Worker     // (see the builder's getCEsFromCE32()),
54*0e209d39SAndroid Build Coastguard Worker     // use at most about 150 primary weights,
55*0e209d39SAndroid Build Coastguard Worker     // where about 94 primary weights are possibly-variable (space/punct/symbol/currency),
56*0e209d39SAndroid Build Coastguard Worker     // at most 4 secondary before-common weights,
57*0e209d39SAndroid Build Coastguard Worker     // at most 4 secondary after-common weights,
58*0e209d39SAndroid Build Coastguard Worker     // at most 16 secondary high weights (in secondary CEs), and
59*0e209d39SAndroid Build Coastguard Worker     // at most 4 tertiary after-common weights.
60*0e209d39SAndroid Build Coastguard Worker     // The following ranges are designed to support slightly more weights than that.
61*0e209d39SAndroid Build Coastguard Worker     // (en_US_POSIX is unusual: It creates about 64 variable + 116 Latin primaries.)
62*0e209d39SAndroid Build Coastguard Worker 
63*0e209d39SAndroid Build Coastguard Worker     // Digits may use long primaries (preserving more short ones)
64*0e209d39SAndroid Build Coastguard Worker     // or short primaries (faster) without changing this data structure.
65*0e209d39SAndroid Build Coastguard Worker     // (If we supported numeric collation, then digits would have to have long primaries
66*0e209d39SAndroid Build Coastguard Worker     // so that special handling does not affect the fast path.)
67*0e209d39SAndroid Build Coastguard Worker 
68*0e209d39SAndroid Build Coastguard Worker     static const uint32_t SHORT_PRIMARY_MASK = 0xfc00;  // bits 15..10
69*0e209d39SAndroid Build Coastguard Worker     static const uint32_t INDEX_MASK = 0x3ff;  // bits 9..0 for expansions & contractions
70*0e209d39SAndroid Build Coastguard Worker     static const uint32_t SECONDARY_MASK = 0x3e0;  // bits 9..5
71*0e209d39SAndroid Build Coastguard Worker     static const uint32_t CASE_MASK = 0x18;  // bits 4..3
72*0e209d39SAndroid Build Coastguard Worker     static const uint32_t LONG_PRIMARY_MASK = 0xfff8;  // bits 15..3
73*0e209d39SAndroid Build Coastguard Worker     static const uint32_t TERTIARY_MASK = 7;  // bits 2..0
74*0e209d39SAndroid Build Coastguard Worker     static const uint32_t CASE_AND_TERTIARY_MASK = CASE_MASK | TERTIARY_MASK;
75*0e209d39SAndroid Build Coastguard Worker 
76*0e209d39SAndroid Build Coastguard Worker     static const uint32_t TWO_SHORT_PRIMARIES_MASK =
77*0e209d39SAndroid Build Coastguard Worker             (SHORT_PRIMARY_MASK << 16) | SHORT_PRIMARY_MASK;  // 0xfc00fc00
78*0e209d39SAndroid Build Coastguard Worker     static const uint32_t TWO_LONG_PRIMARIES_MASK =
79*0e209d39SAndroid Build Coastguard Worker             (LONG_PRIMARY_MASK << 16) | LONG_PRIMARY_MASK;  // 0xfff8fff8
80*0e209d39SAndroid Build Coastguard Worker     static const uint32_t TWO_SECONDARIES_MASK =
81*0e209d39SAndroid Build Coastguard Worker             (SECONDARY_MASK << 16) | SECONDARY_MASK;  // 0x3e003e0
82*0e209d39SAndroid Build Coastguard Worker     static const uint32_t TWO_CASES_MASK =
83*0e209d39SAndroid Build Coastguard Worker             (CASE_MASK << 16) | CASE_MASK;  // 0x180018
84*0e209d39SAndroid Build Coastguard Worker     static const uint32_t TWO_TERTIARIES_MASK =
85*0e209d39SAndroid Build Coastguard Worker             (TERTIARY_MASK << 16) | TERTIARY_MASK;  // 0x70007
86*0e209d39SAndroid Build Coastguard Worker 
87*0e209d39SAndroid Build Coastguard Worker     /**
88*0e209d39SAndroid Build Coastguard Worker      * Contraction with one fast Latin character.
89*0e209d39SAndroid Build Coastguard Worker      * Use INDEX_MASK to find the start of the contraction list after the fixed table.
90*0e209d39SAndroid Build Coastguard Worker      * The first entry contains the default mapping.
91*0e209d39SAndroid Build Coastguard Worker      * Otherwise use CONTR_CHAR_MASK for the contraction character index
92*0e209d39SAndroid Build Coastguard Worker      * (in ascending order).
93*0e209d39SAndroid Build Coastguard Worker      * Use CONTR_LENGTH_SHIFT for the length of the entry
94*0e209d39SAndroid Build Coastguard Worker      * (1=BAIL_OUT, 2=one CE, 3=two CEs).
95*0e209d39SAndroid Build Coastguard Worker      *
96*0e209d39SAndroid Build Coastguard Worker      * Also, U+0000 maps to a contraction entry, so that the fast path need not
97*0e209d39SAndroid Build Coastguard Worker      * check for NUL termination.
98*0e209d39SAndroid Build Coastguard Worker      * It usually maps to a contraction list with only the completely ignorable default value.
99*0e209d39SAndroid Build Coastguard Worker      */
100*0e209d39SAndroid Build Coastguard Worker     static const uint32_t CONTRACTION = 0x400;
101*0e209d39SAndroid Build Coastguard Worker     /**
102*0e209d39SAndroid Build Coastguard Worker      * An expansion encodes two CEs.
103*0e209d39SAndroid Build Coastguard Worker      * Use INDEX_MASK to find the pair of CEs after the fixed table.
104*0e209d39SAndroid Build Coastguard Worker      *
105*0e209d39SAndroid Build Coastguard Worker      * The higher a mini CE value, the easier it is to process.
106*0e209d39SAndroid Build Coastguard Worker      * For expansions and higher, no context needs to be considered.
107*0e209d39SAndroid Build Coastguard Worker      */
108*0e209d39SAndroid Build Coastguard Worker     static const uint32_t EXPANSION = 0x800;
109*0e209d39SAndroid Build Coastguard Worker     /**
110*0e209d39SAndroid Build Coastguard Worker      * Encodes one CE with a long/low mini primary (there are 128).
111*0e209d39SAndroid Build Coastguard Worker      * All potentially-variable primaries must be in this range,
112*0e209d39SAndroid Build Coastguard Worker      * to make the short-primary path as fast as possible.
113*0e209d39SAndroid Build Coastguard Worker      */
114*0e209d39SAndroid Build Coastguard Worker     static const uint32_t MIN_LONG = 0xc00;
115*0e209d39SAndroid Build Coastguard Worker     static const uint32_t LONG_INC = 8;
116*0e209d39SAndroid Build Coastguard Worker     static const uint32_t MAX_LONG = 0xff8;
117*0e209d39SAndroid Build Coastguard Worker     /**
118*0e209d39SAndroid Build Coastguard Worker      * Encodes one CE with a short/high primary (there are 60),
119*0e209d39SAndroid Build Coastguard Worker      * plus a secondary CE if the secondary weight is high.
120*0e209d39SAndroid Build Coastguard Worker      * Fast handling: At least all letter primaries should be in this range.
121*0e209d39SAndroid Build Coastguard Worker      */
122*0e209d39SAndroid Build Coastguard Worker     static const uint32_t MIN_SHORT = 0x1000;
123*0e209d39SAndroid Build Coastguard Worker     static const uint32_t SHORT_INC = 0x400;
124*0e209d39SAndroid Build Coastguard Worker     /** The highest primary weight is reserved for U+FFFF. */
125*0e209d39SAndroid Build Coastguard Worker     static const uint32_t MAX_SHORT = SHORT_PRIMARY_MASK;
126*0e209d39SAndroid Build Coastguard Worker 
127*0e209d39SAndroid Build Coastguard Worker     static const uint32_t MIN_SEC_BEFORE = 0;  // must add SEC_OFFSET
128*0e209d39SAndroid Build Coastguard Worker     static const uint32_t SEC_INC = 0x20;
129*0e209d39SAndroid Build Coastguard Worker     static const uint32_t MAX_SEC_BEFORE = MIN_SEC_BEFORE + 4 * SEC_INC;  // 5 before common
130*0e209d39SAndroid Build Coastguard Worker     static const uint32_t COMMON_SEC = MAX_SEC_BEFORE + SEC_INC;
131*0e209d39SAndroid Build Coastguard Worker     static const uint32_t MIN_SEC_AFTER = COMMON_SEC + SEC_INC;
132*0e209d39SAndroid Build Coastguard Worker     static const uint32_t MAX_SEC_AFTER = MIN_SEC_AFTER + 5 * SEC_INC;  // 6 after common
133*0e209d39SAndroid Build Coastguard Worker     static const uint32_t MIN_SEC_HIGH = MAX_SEC_AFTER + SEC_INC;  // 20 high secondaries
134*0e209d39SAndroid Build Coastguard Worker     static const uint32_t MAX_SEC_HIGH = SECONDARY_MASK;
135*0e209d39SAndroid Build Coastguard Worker 
136*0e209d39SAndroid Build Coastguard Worker     /**
137*0e209d39SAndroid Build Coastguard Worker      * Lookup: Add this offset to secondary weights, except for completely ignorable CEs.
138*0e209d39SAndroid Build Coastguard Worker      * Must be greater than any special value, e.g., MERGE_WEIGHT.
139*0e209d39SAndroid Build Coastguard Worker      * The exact value is not relevant for the format version.
140*0e209d39SAndroid Build Coastguard Worker      */
141*0e209d39SAndroid Build Coastguard Worker     static const uint32_t SEC_OFFSET = SEC_INC;
142*0e209d39SAndroid Build Coastguard Worker     static const uint32_t COMMON_SEC_PLUS_OFFSET = COMMON_SEC + SEC_OFFSET;
143*0e209d39SAndroid Build Coastguard Worker 
144*0e209d39SAndroid Build Coastguard Worker     static const uint32_t TWO_SEC_OFFSETS =
145*0e209d39SAndroid Build Coastguard Worker             (SEC_OFFSET << 16) | SEC_OFFSET;  // 0x200020
146*0e209d39SAndroid Build Coastguard Worker     static const uint32_t TWO_COMMON_SEC_PLUS_OFFSET =
147*0e209d39SAndroid Build Coastguard Worker             (COMMON_SEC_PLUS_OFFSET << 16) | COMMON_SEC_PLUS_OFFSET;
148*0e209d39SAndroid Build Coastguard Worker 
149*0e209d39SAndroid Build Coastguard Worker     static const uint32_t LOWER_CASE = 8;  // case bits include this offset
150*0e209d39SAndroid Build Coastguard Worker     static const uint32_t TWO_LOWER_CASES = (LOWER_CASE << 16) | LOWER_CASE;  // 0x80008
151*0e209d39SAndroid Build Coastguard Worker 
152*0e209d39SAndroid Build Coastguard Worker     static const uint32_t COMMON_TER = 0;  // must add TER_OFFSET
153*0e209d39SAndroid Build Coastguard Worker     static const uint32_t MAX_TER_AFTER = 7;  // 7 after common
154*0e209d39SAndroid Build Coastguard Worker 
155*0e209d39SAndroid Build Coastguard Worker     /**
156*0e209d39SAndroid Build Coastguard Worker      * Lookup: Add this offset to tertiary weights, except for completely ignorable CEs.
157*0e209d39SAndroid Build Coastguard Worker      * Must be greater than any special value, e.g., MERGE_WEIGHT.
158*0e209d39SAndroid Build Coastguard Worker      * Must be greater than case bits as well, so that with combined case+tertiary weights
159*0e209d39SAndroid Build Coastguard Worker      * plus the offset the tertiary bits does not spill over into the case bits.
160*0e209d39SAndroid Build Coastguard Worker      * The exact value is not relevant for the format version.
161*0e209d39SAndroid Build Coastguard Worker      */
162*0e209d39SAndroid Build Coastguard Worker     static const uint32_t TER_OFFSET = SEC_OFFSET;
163*0e209d39SAndroid Build Coastguard Worker     static const uint32_t COMMON_TER_PLUS_OFFSET = COMMON_TER + TER_OFFSET;
164*0e209d39SAndroid Build Coastguard Worker 
165*0e209d39SAndroid Build Coastguard Worker     static const uint32_t TWO_TER_OFFSETS = (TER_OFFSET << 16) | TER_OFFSET;
166*0e209d39SAndroid Build Coastguard Worker     static const uint32_t TWO_COMMON_TER_PLUS_OFFSET =
167*0e209d39SAndroid Build Coastguard Worker             (COMMON_TER_PLUS_OFFSET << 16) | COMMON_TER_PLUS_OFFSET;
168*0e209d39SAndroid Build Coastguard Worker 
169*0e209d39SAndroid Build Coastguard Worker     static const uint32_t MERGE_WEIGHT = 3;
170*0e209d39SAndroid Build Coastguard Worker     static const uint32_t EOS = 2;  // end of string
171*0e209d39SAndroid Build Coastguard Worker     static const uint32_t BAIL_OUT = 1;
172*0e209d39SAndroid Build Coastguard Worker 
173*0e209d39SAndroid Build Coastguard Worker     /**
174*0e209d39SAndroid Build Coastguard Worker      * Contraction result first word bits 8..0 contain the
175*0e209d39SAndroid Build Coastguard Worker      * second contraction character, as a char index 0..NUM_FAST_CHARS-1.
176*0e209d39SAndroid Build Coastguard Worker      * Each contraction list is terminated with a word containing CONTR_CHAR_MASK.
177*0e209d39SAndroid Build Coastguard Worker      */
178*0e209d39SAndroid Build Coastguard Worker     static const uint32_t CONTR_CHAR_MASK = 0x1ff;
179*0e209d39SAndroid Build Coastguard Worker     /**
180*0e209d39SAndroid Build Coastguard Worker      * Contraction result first word bits 10..9 contain the result length:
181*0e209d39SAndroid Build Coastguard Worker      * 1=bail out, 2=one mini CE, 3=two mini CEs
182*0e209d39SAndroid Build Coastguard Worker      */
183*0e209d39SAndroid Build Coastguard Worker     static const uint32_t CONTR_LENGTH_SHIFT = 9;
184*0e209d39SAndroid Build Coastguard Worker 
185*0e209d39SAndroid Build Coastguard Worker     /**
186*0e209d39SAndroid Build Coastguard Worker      * Comparison return value when the regular comparison must be used.
187*0e209d39SAndroid Build Coastguard Worker      * The exact value is not relevant for the format version.
188*0e209d39SAndroid Build Coastguard Worker      */
189*0e209d39SAndroid Build Coastguard Worker     static const int32_t BAIL_OUT_RESULT = -2;
190*0e209d39SAndroid Build Coastguard Worker 
getCharIndex(char16_t c)191*0e209d39SAndroid Build Coastguard Worker     static inline int32_t getCharIndex(char16_t c) {
192*0e209d39SAndroid Build Coastguard Worker         if(c <= LATIN_MAX) {
193*0e209d39SAndroid Build Coastguard Worker             return c;
194*0e209d39SAndroid Build Coastguard Worker         } else if(PUNCT_START <= c && c < PUNCT_LIMIT) {
195*0e209d39SAndroid Build Coastguard Worker             return c - (PUNCT_START - LATIN_LIMIT);
196*0e209d39SAndroid Build Coastguard Worker         } else {
197*0e209d39SAndroid Build Coastguard Worker             // Not a fast Latin character.
198*0e209d39SAndroid Build Coastguard Worker             // Note: U+FFFE & U+FFFF are forbidden in tailorings
199*0e209d39SAndroid Build Coastguard Worker             // and thus do not occur in any contractions.
200*0e209d39SAndroid Build Coastguard Worker             return -1;
201*0e209d39SAndroid Build Coastguard Worker         }
202*0e209d39SAndroid Build Coastguard Worker     }
203*0e209d39SAndroid Build Coastguard Worker 
204*0e209d39SAndroid Build Coastguard Worker     /**
205*0e209d39SAndroid Build Coastguard Worker      * Computes the options value for the compare functions
206*0e209d39SAndroid Build Coastguard Worker      * and writes the precomputed primary weights.
207*0e209d39SAndroid Build Coastguard Worker      * Returns -1 if the Latin fastpath is not supported for the data and settings.
208*0e209d39SAndroid Build Coastguard Worker      * The capacity must be LATIN_LIMIT.
209*0e209d39SAndroid Build Coastguard Worker      */
210*0e209d39SAndroid Build Coastguard Worker     static int32_t getOptions(const CollationData *data, const CollationSettings &settings,
211*0e209d39SAndroid Build Coastguard Worker                               uint16_t *primaries, int32_t capacity);
212*0e209d39SAndroid Build Coastguard Worker 
213*0e209d39SAndroid Build Coastguard Worker     static int32_t compareUTF16(const uint16_t *table, const uint16_t *primaries, int32_t options,
214*0e209d39SAndroid Build Coastguard Worker                                 const char16_t *left, int32_t leftLength,
215*0e209d39SAndroid Build Coastguard Worker                                 const char16_t *right, int32_t rightLength);
216*0e209d39SAndroid Build Coastguard Worker 
217*0e209d39SAndroid Build Coastguard Worker     static int32_t compareUTF8(const uint16_t *table, const uint16_t *primaries, int32_t options,
218*0e209d39SAndroid Build Coastguard Worker                                const uint8_t *left, int32_t leftLength,
219*0e209d39SAndroid Build Coastguard Worker                                const uint8_t *right, int32_t rightLength);
220*0e209d39SAndroid Build Coastguard Worker 
221*0e209d39SAndroid Build Coastguard Worker private:
222*0e209d39SAndroid Build Coastguard Worker     static uint32_t lookup(const uint16_t *table, UChar32 c);
223*0e209d39SAndroid Build Coastguard Worker     static uint32_t lookupUTF8(const uint16_t *table, UChar32 c,
224*0e209d39SAndroid Build Coastguard Worker                                const uint8_t *s8, int32_t &sIndex, int32_t sLength);
225*0e209d39SAndroid Build Coastguard Worker     static uint32_t lookupUTF8Unsafe(const uint16_t *table, UChar32 c,
226*0e209d39SAndroid Build Coastguard Worker                                      const uint8_t *s8, int32_t &sIndex);
227*0e209d39SAndroid Build Coastguard Worker 
228*0e209d39SAndroid Build Coastguard Worker     static uint32_t nextPair(const uint16_t *table, UChar32 c, uint32_t ce,
229*0e209d39SAndroid Build Coastguard Worker                              const char16_t *s16, const uint8_t *s8, int32_t &sIndex, int32_t &sLength);
230*0e209d39SAndroid Build Coastguard Worker 
getPrimaries(uint32_t variableTop,uint32_t pair)231*0e209d39SAndroid Build Coastguard Worker     static inline uint32_t getPrimaries(uint32_t variableTop, uint32_t pair) {
232*0e209d39SAndroid Build Coastguard Worker         uint32_t ce = pair & 0xffff;
233*0e209d39SAndroid Build Coastguard Worker         if(ce >= MIN_SHORT) { return pair & TWO_SHORT_PRIMARIES_MASK; }
234*0e209d39SAndroid Build Coastguard Worker         if(ce > variableTop) { return pair & TWO_LONG_PRIMARIES_MASK; }
235*0e209d39SAndroid Build Coastguard Worker         if(ce >= MIN_LONG) { return 0; }  // variable
236*0e209d39SAndroid Build Coastguard Worker         return pair;  // special mini CE
237*0e209d39SAndroid Build Coastguard Worker     }
getSecondariesFromOneShortCE(uint32_t ce)238*0e209d39SAndroid Build Coastguard Worker     static inline uint32_t getSecondariesFromOneShortCE(uint32_t ce) {
239*0e209d39SAndroid Build Coastguard Worker         ce &= SECONDARY_MASK;
240*0e209d39SAndroid Build Coastguard Worker         if(ce < MIN_SEC_HIGH) {
241*0e209d39SAndroid Build Coastguard Worker             return ce + SEC_OFFSET;
242*0e209d39SAndroid Build Coastguard Worker         } else {
243*0e209d39SAndroid Build Coastguard Worker             return ((ce + SEC_OFFSET) << 16) | COMMON_SEC_PLUS_OFFSET;
244*0e209d39SAndroid Build Coastguard Worker         }
245*0e209d39SAndroid Build Coastguard Worker     }
246*0e209d39SAndroid Build Coastguard Worker     static uint32_t getSecondaries(uint32_t variableTop, uint32_t pair);
247*0e209d39SAndroid Build Coastguard Worker     static uint32_t getCases(uint32_t variableTop, UBool strengthIsPrimary, uint32_t pair);
248*0e209d39SAndroid Build Coastguard Worker     static uint32_t getTertiaries(uint32_t variableTop, UBool withCaseBits, uint32_t pair);
249*0e209d39SAndroid Build Coastguard Worker     static uint32_t getQuaternaries(uint32_t variableTop, uint32_t pair);
250*0e209d39SAndroid Build Coastguard Worker 
251*0e209d39SAndroid Build Coastguard Worker private:
252*0e209d39SAndroid Build Coastguard Worker     CollationFastLatin() = delete;  // no constructor
253*0e209d39SAndroid Build Coastguard Worker };
254*0e209d39SAndroid Build Coastguard Worker 
255*0e209d39SAndroid Build Coastguard Worker /*
256*0e209d39SAndroid Build Coastguard Worker  * Format of the CollationFastLatin data table.
257*0e209d39SAndroid Build Coastguard Worker  * CollationFastLatin::VERSION = 2.
258*0e209d39SAndroid Build Coastguard Worker  *
259*0e209d39SAndroid Build Coastguard Worker  * This table contains data for a Latin-text collation fastpath.
260*0e209d39SAndroid Build Coastguard Worker  * The data is stored as an array of uint16_t which contains the following parts.
261*0e209d39SAndroid Build Coastguard Worker  *
262*0e209d39SAndroid Build Coastguard Worker  * uint16_t  -- version & header length
263*0e209d39SAndroid Build Coastguard Worker  *   Bits 15..8: version, must match the VERSION
264*0e209d39SAndroid Build Coastguard Worker  *         7..0: length of the header
265*0e209d39SAndroid Build Coastguard Worker  *
266*0e209d39SAndroid Build Coastguard Worker  * uint16_t varTops[header length - 1]
267*0e209d39SAndroid Build Coastguard Worker  *   Version 2:
268*0e209d39SAndroid Build Coastguard Worker  *   varTops[m] is the highest CollationFastLatin long-primary weight
269*0e209d39SAndroid Build Coastguard Worker  *   of supported maxVariable group m
270*0e209d39SAndroid Build Coastguard Worker  *   (special reorder group space, punct, symbol, currency).
271*0e209d39SAndroid Build Coastguard Worker  *
272*0e209d39SAndroid Build Coastguard Worker  *   Version 1:
273*0e209d39SAndroid Build Coastguard Worker  *   Each of these values maps the variable top lead byte of a supported maxVariable group
274*0e209d39SAndroid Build Coastguard Worker  *   to the highest CollationFastLatin long-primary weight.
275*0e209d39SAndroid Build Coastguard Worker  *   The values are stored in ascending order.
276*0e209d39SAndroid Build Coastguard Worker  *   Bits 15..7: max fast-Latin long-primary weight (bits 11..3 shifted left by 4 bits)
277*0e209d39SAndroid Build Coastguard Worker  *         6..0: regular primary lead byte
278*0e209d39SAndroid Build Coastguard Worker  *
279*0e209d39SAndroid Build Coastguard Worker  * uint16_t miniCEs[0x1c0]
280*0e209d39SAndroid Build Coastguard Worker  *   A mini collation element for each character U+0000..U+017F and U+2000..U+203F.
281*0e209d39SAndroid Build Coastguard Worker  *   Each value encodes one or two mini CEs (two are possible if the first one
282*0e209d39SAndroid Build Coastguard Worker  *   has a short mini primary and the second one is a secondary CE, i.e., primary == 0),
283*0e209d39SAndroid Build Coastguard Worker  *   or points to an expansion or to a contraction table.
284*0e209d39SAndroid Build Coastguard Worker  *   U+0000 always has a contraction entry,
285*0e209d39SAndroid Build Coastguard Worker  *   so that NUL-termination need not be tested in the fastpath.
286*0e209d39SAndroid Build Coastguard Worker  *   If the collation elements for a character or contraction cannot be encoded in this format,
287*0e209d39SAndroid Build Coastguard Worker  *   then the BAIL_OUT value is stored.
288*0e209d39SAndroid Build Coastguard Worker  *   For details see the comments for the class constants.
289*0e209d39SAndroid Build Coastguard Worker  *
290*0e209d39SAndroid Build Coastguard Worker  * uint16_t expansions[variable length];
291*0e209d39SAndroid Build Coastguard Worker  *   Expansion mini CEs contain an offset relative to just after the miniCEs table.
292*0e209d39SAndroid Build Coastguard Worker  *   An expansions contains exactly 2 mini CEs.
293*0e209d39SAndroid Build Coastguard Worker  *
294*0e209d39SAndroid Build Coastguard Worker  * uint16_t contractions[variable length];
295*0e209d39SAndroid Build Coastguard Worker  *   Contraction mini CEs contain an offset relative to just after the miniCEs table.
296*0e209d39SAndroid Build Coastguard Worker  *   It points to a list of tuples which map from a contraction suffix character to a result.
297*0e209d39SAndroid Build Coastguard Worker  *   First uint16_t of each tuple:
298*0e209d39SAndroid Build Coastguard Worker  *     Bits 10..9: Length of the result (1..3), see comments on CONTR_LENGTH_SHIFT.
299*0e209d39SAndroid Build Coastguard Worker  *     Bits  8..0: Contraction character, see comments on CONTR_CHAR_MASK.
300*0e209d39SAndroid Build Coastguard Worker  *   This is followed by 0, 1, or 2 uint16_t according to the length.
301*0e209d39SAndroid Build Coastguard Worker  *   Each list is terminated by an entry with CONTR_CHAR_MASK.
302*0e209d39SAndroid Build Coastguard Worker  *   Each list starts with such an entry which also contains the default result
303*0e209d39SAndroid Build Coastguard Worker  *   for when there is no contraction match.
304*0e209d39SAndroid Build Coastguard Worker  *
305*0e209d39SAndroid Build Coastguard Worker  * -----------------
306*0e209d39SAndroid Build Coastguard Worker  * Changes for version 2 (ICU 55)
307*0e209d39SAndroid Build Coastguard Worker  *
308*0e209d39SAndroid Build Coastguard Worker  * Special reorder groups do not necessarily start on whole primary lead bytes any more.
309*0e209d39SAndroid Build Coastguard Worker  * Therefore, the varTops data has a new format:
310*0e209d39SAndroid Build Coastguard Worker  * Version 1 stored the lead bytes of the highest root primaries for
311*0e209d39SAndroid Build Coastguard Worker  * the maxVariable-supported special reorder groups.
312*0e209d39SAndroid Build Coastguard Worker  * Now the top 16 bits would need to be stored,
313*0e209d39SAndroid Build Coastguard Worker  * and it is simpler to store only the fast-Latin weights.
314*0e209d39SAndroid Build Coastguard Worker  */
315*0e209d39SAndroid Build Coastguard Worker 
316*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
317*0e209d39SAndroid Build Coastguard Worker 
318*0e209d39SAndroid Build Coastguard Worker #endif  // !UCONFIG_NO_COLLATION
319*0e209d39SAndroid Build Coastguard Worker #endif  // __COLLATIONFASTLATIN_H__
320