Changeset 4629 for icGREP/icgrepdevel/icgrep/UCD/unicode_set.cpp
 Timestamp:
 Jul 2, 2015, 9:28:21 AM (4 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

icGREP/icgrepdevel/icgrep/UCD/unicode_set.cpp
r4627 r4629 149 149 const auto e2 = other.quad_end(); 150 150 for (auto i1 = quad_begin(), i2 = other.quad_begin(); i1 != e1 && i2 != e2; ) { 151 const auto run1 = i1.run(); 152 const auto run2 = i2.run(); 153 const auto n = std::min(lengthOf(run1), lengthOf(run2)); 154 if (typeOf(run1) == typeOf(run2) && typeOf(run1) != Mixed) { 155 append_run(typeOf(run1), n, runs); 156 i1 += n; 157 i2 += n; 158 } 159 else if (typeOf(run1) == Full) { 151 const auto n = std::min(i1.length(), i2.length()); 152 if (i1.type() == i2.type() && i1.type() != Mixed) { 153 append_run(i1.type(), n, runs); 154 i1 += n; 155 i2 += n; 156 } 157 else if (i1.type() == Full) { 160 158 for (unsigned i = 0; i != n; ++i, ++i2) { 161 159 append_quad(i2.quad(), quads, runs); … … 163 161 i1 += n; 164 162 } 165 else if ( typeOf(run2) == Full) {163 else if (i2.type() == Full) { 166 164 for (unsigned i = 0; i != n; ++i, ++i1) { 167 165 append_quad(i1.quad(), quads, runs); … … 189 187 auto i1 = quad_begin(), i2 = other.quad_begin(); 190 188 for (; i1 != e1 && i2 != e2; ) { 191 const auto run1 = i1.run(); 192 const auto run2 = i2.run(); 193 const auto n = std::min(lengthOf(run1), lengthOf(run2)); 194 if ((typeOf(run1) == Empty) && (typeOf(run2) == Empty)) { 189 const auto n = std::min(i1.length(), i2.length()); 190 if ((i1.type() == Empty) && (i2.type() == Empty)) { 195 191 append_run(Empty, n, runs); 196 192 i1 += n; 197 193 i2 += n; 198 194 } 199 else if (( typeOf(run1) == Full)  (typeOf(run2) == Full)) {195 else if ((i1.type() == Full)  (i2.type() == Full)) { 200 196 append_run(Full, n, runs); 201 197 i1 += n; 202 198 i2 += n; 203 199 } 204 else if ( typeOf(run1) == Empty) {200 else if (i1.type() == Empty) { 205 201 for (unsigned i = 0; i != n; ++i, ++i2) { 206 202 append_quad(i2.quad(), quads, runs); … … 208 204 i1 += n; 209 205 } 210 else if ( typeOf(run2) == Empty) {206 else if (i2.type() == Empty) { 211 207 for (unsigned i = 0; i != n; ++i, ++i1) { 212 208 append_quad(i1.quad(), quads, runs); … … 233 229 const auto e2 = other.quad_end(); 234 230 for (auto i1 = quad_begin(), i2 = other.quad_begin(); i1 != e1 && i2 != e2; ) { 235 const auto run1 = i1.run(); 236 const auto run2 = i2.run(); 237 unsigned n = std::min(lengthOf(run1), lengthOf(run2)); 238 if ((typeOf(run1) == Empty)  (typeOf(run2) == Full)  (typeOf(run1) == Full && typeOf(run2) == Empty)) { 239 append_run(typeOf(run1), n, runs); 240 i1 += n; 241 i2 += n; 242 } 243 else if (typeOf(run1) == Full) { 231 unsigned n = std::min(i1.length(), i2.length()); 232 if ((i1.type() == Empty)  (i2.type() == Full)  (i1.type() == Full && i2.type() == Empty)) { 233 append_run(i1.type(), n, runs); 234 i1 += n; 235 i2 += n; 236 } 237 else if (i1.type() == Full) { 244 238 for (unsigned i = 0; i != n; ++i, ++i2) { 245 239 append_quad(FULL_QUAD_MASK ^ i2.quad(), quads, runs); … … 247 241 i1 += n; 248 242 } 249 else if ( typeOf(run2) == Empty) {243 else if (i2.type() == Empty) { 250 244 for (unsigned i = 0; i != n; ++i, ++i1) { 251 245 append_quad(i1.quad(), quads, runs); … … 272 266 const auto e2 = other.quad_end(); 273 267 for (auto i1 = quad_begin(), i2 = other.quad_begin(); i1 != e1 && i2 != e2; ) { 274 const auto run1 = i1.run(); 275 const auto run2 = i2.run(); 276 unsigned n = std::min(lengthOf(run1), lengthOf(run2)); 277 if (typeOf(run1) != Mixed && typeOf(run2) != Mixed) { 278 append_run(typeOf(run1) == typeOf(run2) ? Empty : Full, n, runs); 279 i1 += n; 280 i2 += n; 281 } 282 else if (typeOf(run1) == Empty) { 268 unsigned n = std::min(i1.length(), i2.length()); 269 if (i1.type() != Mixed && i2.type() != Mixed) { 270 append_run(i1.type() == i2.type() ? Empty : Full, n, runs); 271 i1 += n; 272 i2 += n; 273 } 274 else if (i1.type() == Empty) { 283 275 for (unsigned i = 0; i < n; ++i, ++i2) { 284 276 append_quad(i2.quad(), quads, runs); … … 286 278 i1 += n; 287 279 } 288 else if ( typeOf(run2) == Empty) {280 else if (i2.type() == Empty) { 289 281 for (unsigned i = 0; i < n; ++i, ++i1) { 290 282 append_quad(i1.quad(), quads, runs); … … 292 284 i2 += n; 293 285 } 294 else if ( typeOf(run1) == Full) {286 else if (i1.type() == Full) { 295 287 for (unsigned i = 0; i < n; ++i, ++i2) { 296 288 append_quad(FULL_QUAD_MASK ^ i2.quad(), quads, runs); … … 298 290 i1 += n; 299 291 } 300 else if ( typeOf(run2) == Empty) {292 else if (i2.type() == Empty) { 301 293 for (unsigned i = 0; i < n; ++i, ++i1) { 302 294 append_quad(FULL_QUAD_MASK ^ i1.quad(), quads, runs); … … 338 330 bool UnicodeSet::contains(const codepoint_t codepoint) const { 339 331 auto n = codepoint / QUAD_BITS; 340 QuadVector::const_iteratorqi = mQuads.cbegin();332 auto qi = mQuads.cbegin(); 341 333 for (const auto & r : mRuns) { 342 334 if (lengthOf(r) >= n) { … … 348 340 } 349 341 if (typeOf(r) == Mixed) { 350 qi += n;342 qi += lengthOf(r); 351 343 } 352 344 n = lengthOf(r); 353 345 } 354 346 return false; 347 } 348 349 /**  * 350 * @brief intersects 351 * @param lo_codepoint 352 * @param hi_codepoint 353 * 354 * Return true if this UnicodeSet contains any code point(s) between lo_codepoint and hi_codepoint 355 **  */ 356 bool UnicodeSet::intersects(const codepoint_t lo_codepoint, const codepoint_t hi_codepoint) const { 357 quad_iterator qi = quad_begin() + lo_codepoint / QUAD_BITS; 358 unsigned n = (hi_codepoint  lo_codepoint) / QUAD_BITS; 359 while (n) { 360 if (qi.type() != Empty) { 361 return true; 362 } 363 const auto l = std::min<unsigned>(qi.length(), n); 364 qi += l; 365 n = l; 366 } 367 // check the remaining portion of this quad 368 unsigned r = (hi_codepoint  lo_codepoint) % QUAD_BITS; 369 if (r == 0  (++qi).type() == Empty) { 370 return false; 371 } 372 if (qi.type() == Full) { 373 return true; 374 } 375 return (qi.quad() & (FULL_QUAD_MASK << r)) != 0; 355 376 } 356 377
Note: See TracChangeset
for help on using the changeset viewer.