2 *******************************************************************************
4 * Copyright (C) 1999-2014, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: collationweights.h
10 * tab size: 8 (not used)
13 * created on: 2001mar08 as ucol_wgt.h
14 * created by: Markus W. Scherer
17 #ifndef __COLLATIONWEIGHTS_H__
18 #define __COLLATIONWEIGHTS_H__
20 #include "unicode/utypes.h"
22 #if !UCONFIG_NO_COLLATION
24 #include "unicode/uobject.h"
29 * Allocates n collation element weights between two exclusive limits.
30 * Used only internally by the collation tailoring builder.
32 class U_I18N_API CollationWeights
: public UMemory
{
36 static inline int32_t lengthOfWeight(uint32_t weight
) {
37 if((weight
&0xffffff)==0) {
39 } else if((weight
&0xffff)==0) {
41 } else if((weight
&0xff)==0) {
48 void initForPrimary(UBool compressible
);
49 void initForSecondary();
50 void initForTertiary();
53 * Determine heuristically
54 * what ranges to use for a given number of weights between (excluding)
57 * @param lowerLimit A collation element weight; the ranges will be filled to cover
58 * weights greater than this one.
59 * @param upperLimit A collation element weight; the ranges will be filled to cover
60 * weights less than this one.
61 * @param n The number of collation element weights w necessary such that
62 * lowerLimit<w<upperLimit in lexical order.
63 * @return TRUE if it is possible to fit n elements between the limits
65 UBool
allocWeights(uint32_t lowerLimit
, uint32_t upperLimit
, int32_t n
);
68 * Given a set of ranges calculated by allocWeights(),
69 * iterate through the weights.
70 * The ranges are modified to keep the current iteration state.
72 * @return The next weight in the ranges, or 0xffffffff if there is none left.
74 uint32_t nextWeight();
79 int32_t length
, count
;
83 /** @return number of usable byte values for byte idx */
84 inline int32_t countBytes(int32_t idx
) const {
85 return (int32_t)(maxBytes
[idx
] - minBytes
[idx
] + 1);
88 uint32_t incWeight(uint32_t weight
, int32_t length
) const;
89 uint32_t incWeightByOffset(uint32_t weight
, int32_t length
, int32_t offset
) const;
90 void lengthenRange(WeightRange
&range
) const;
92 * Takes two CE weights and calculates the
93 * possible ranges of weights between the two limits, excluding them.
94 * For weights with up to 4 bytes there are up to 2*4-1=7 ranges.
96 UBool
getWeightRanges(uint32_t lowerLimit
, uint32_t upperLimit
);
97 UBool
allocWeightsInShortRanges(int32_t n
, int32_t minLength
);
98 UBool
allocWeightsInMinLengthRanges(int32_t n
, int32_t minLength
);
100 int32_t middleLength
;
101 uint32_t minBytes
[5]; // for byte 1, 2, 3, 4
102 uint32_t maxBytes
[5];
103 WeightRange ranges
[7];
110 #endif // !UCONFIG_NO_COLLATION
111 #endif // __COLLATIONWEIGHTS_H__