1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 1999-2014, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
10 * file name: collationweights.h
12 * tab size: 8 (not used)
15 * created on: 2001mar08 as ucol_wgt.h
16 * created by: Markus W. Scherer
19 #ifndef __COLLATIONWEIGHTS_H__
20 #define __COLLATIONWEIGHTS_H__
22 #include "unicode/utypes.h"
24 #if !UCONFIG_NO_COLLATION
26 #include "unicode/uobject.h"
31 * Allocates n collation element weights between two exclusive limits.
32 * Used only internally by the collation tailoring builder.
34 class U_I18N_API CollationWeights
: public UMemory
{
38 static inline int32_t lengthOfWeight(uint32_t weight
) {
39 if((weight
&0xffffff)==0) {
41 } else if((weight
&0xffff)==0) {
43 } else if((weight
&0xff)==0) {
50 void initForPrimary(UBool compressible
);
51 void initForSecondary();
52 void initForTertiary();
55 * Determine heuristically
56 * what ranges to use for a given number of weights between (excluding)
59 * @param lowerLimit A collation element weight; the ranges will be filled to cover
60 * weights greater than this one.
61 * @param upperLimit A collation element weight; the ranges will be filled to cover
62 * weights less than this one.
63 * @param n The number of collation element weights w necessary such that
64 * lowerLimit<w<upperLimit in lexical order.
65 * @return TRUE if it is possible to fit n elements between the limits
67 UBool
allocWeights(uint32_t lowerLimit
, uint32_t upperLimit
, int32_t n
);
70 * Given a set of ranges calculated by allocWeights(),
71 * iterate through the weights.
72 * The ranges are modified to keep the current iteration state.
74 * @return The next weight in the ranges, or 0xffffffff if there is none left.
76 uint32_t nextWeight();
81 int32_t length
, count
;
85 /** @return number of usable byte values for byte idx */
86 inline int32_t countBytes(int32_t idx
) const {
87 return (int32_t)(maxBytes
[idx
] - minBytes
[idx
] + 1);
90 uint32_t incWeight(uint32_t weight
, int32_t length
) const;
91 uint32_t incWeightByOffset(uint32_t weight
, int32_t length
, int32_t offset
) const;
92 void lengthenRange(WeightRange
&range
) const;
94 * Takes two CE weights and calculates the
95 * possible ranges of weights between the two limits, excluding them.
96 * For weights with up to 4 bytes there are up to 2*4-1=7 ranges.
98 UBool
getWeightRanges(uint32_t lowerLimit
, uint32_t upperLimit
);
99 UBool
allocWeightsInShortRanges(int32_t n
, int32_t minLength
);
100 UBool
allocWeightsInMinLengthRanges(int32_t n
, int32_t minLength
);
102 int32_t middleLength
;
103 uint32_t minBytes
[5]; // for byte 1, 2, 3, 4
104 uint32_t maxBytes
[5];
105 WeightRange ranges
[7];
112 #endif // !UCONFIG_NO_COLLATION
113 #endif // __COLLATIONWEIGHTS_H__