OLD | NEW |
1 /* | 1 /* |
2 ********************************************************************** | 2 ********************************************************************** |
3 * Copyright (C) 2007, International Business Machines | 3 * Copyright (C) 2014, International Business Machines |
4 * Corporation and others. All Rights Reserved. | 4 * Corporation and others. All Rights Reserved. |
5 ********************************************************************** | 5 ********************************************************************** |
6 * file name: bitset.cpp | 6 * file name: bitset.cpp |
7 * encoding: US-ASCII | 7 * encoding: US-ASCII |
8 * tab size: 8 (not used) | 8 * tab size: 8 (not used) |
9 * indentation:4 | 9 * indentation:4 |
10 * | 10 * |
11 * created on: 2007jan15 | 11 * created on: 2007jan15 |
12 * created by: Markus Scherer | 12 * created by: Markus Scherer |
13 * | 13 * |
14 * Idea for a "compiled", fast, read-only (immutable) version of a UnicodeSet | 14 * Idea for a "compiled", fast, read-only (immutable) version of a UnicodeSet |
15 * using a folded bit set consisting of a 1k-entry index table and a | 15 * using a folded bit set consisting of a 1k-entry index table and a |
16 * compacted array of 64-bit words. | 16 * compacted array of 64-bit words. |
17 * Uses a simple hash table for compaction. | 17 * Uses a simple hash table for compaction. |
18 * Uses the original set for supplementary code points. | 18 * Uses the original set for supplementary code points. |
19 */ | 19 */ |
20 | 20 |
21 #include "unicode/utypes.h" | 21 #include "unicode/utypes.h" |
22 #include "unicont.h" | 22 #include "unicont.h" |
| 23 #include "cmemory.h" // for UPRV_LENGTHOF |
23 | 24 |
24 /* | 25 /* |
25 * Hash table for up to 1k 64-bit words, for 1 bit per BMP code point. | 26 * Hash table for up to 1k 64-bit words, for 1 bit per BMP code point. |
26 * Hashes 64-bit words and maps them to 16-bit integers which are | 27 * Hashes 64-bit words and maps them to 16-bit integers which are |
27 * assigned in order of new incoming words for subsequent storage | 28 * assigned in order of new incoming words for subsequent storage |
28 * in a contiguous array. | 29 * in a contiguous array. |
29 */ | 30 */ |
30 struct BMPBitHash : public UObject { | 31 struct BMPBitHash : public UObject { |
31 int64_t keys[0x800]; // 2k | 32 int64_t keys[0x800]; // 2k |
32 uint16_t values[0x800]; | 33 uint16_t values[0x800]; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 index[i++]=all; | 140 index[i++]=all; |
140 } while(i<j); | 141 } while(i<j); |
141 } | 142 } |
142 b=INT64_C(0xffffffffffffffff); | 143 b=INT64_C(0xffffffffffffffff); |
143 } | 144 } |
144 /* i==j */ | 145 /* i==j */ |
145 b&=(INT64_C(1)<<(end&0x3f))-1; | 146 b&=(INT64_C(1)<<(end&0x3f))-1; |
146 prevIndex=j; | 147 prevIndex=j; |
147 } | 148 } |
148 | 149 |
149 if(bitHash->countKeys()>LENGTHOF(shortBits)) { | 150 if(bitHash->countKeys()>UPRV_LENGTHOF(shortBits)) { |
150 bits=(int64_t *)uprv_malloc(bitHash->countKeys()*8); | 151 bits=(int64_t *)uprv_malloc(bitHash->countKeys()*8); |
151 } | 152 } |
152 if(bits!=NULL) { | 153 if(bits!=NULL) { |
153 bitHash->invert(bits); | 154 bitHash->invert(bits); |
154 } else { | 155 } else { |
155 bits=shortBits; | 156 bits=shortBits; |
156 errorCode=U_MEMORY_ALLOCATION_ERROR; | 157 errorCode=U_MEMORY_ALLOCATION_ERROR; |
157 return; | 158 return; |
158 } | 159 } |
159 | 160 |
(...skipping 28 matching lines...) Expand all Loading... |
188 | 189 |
189 private: | 190 private: |
190 uint16_t index[0x400]; | 191 uint16_t index[0x400]; |
191 int64_t shortBits[32]; | 192 int64_t shortBits[32]; |
192 int64_t *bits; | 193 int64_t *bits; |
193 | 194 |
194 uint32_t latin1Bits[8]; | 195 uint32_t latin1Bits[8]; |
195 | 196 |
196 UnicodeSet *restSet; | 197 UnicodeSet *restSet; |
197 }; | 198 }; |
OLD | NEW |