| 1 | #include "ColorSet.hpp" |
| 2 | |
| 3 | UnitigColors::UnitigColors() : setBits(localBitVector) {} |
| 4 | |
| 5 | UnitigColors::UnitigColors(const UnitigColors& o) { |
| 6 | |
| 7 | const uintptr_t flag = o.setBits & flagMask; |
| 8 | |
| 9 | if (flag == ptrUnitigColors){ |
| 10 | |
| 11 | const UnitigColors* uc_o = o.getConstPtrUnitigColors(); |
| 12 | |
| 13 | UnitigColors* setPtrUC = new UnitigColors[2]; |
| 14 | |
| 15 | setPtrUC[0] = uc_o[0]; |
| 16 | setPtrUC[1] = uc_o[1]; |
| 17 | |
| 18 | setBits = (reinterpret_cast<uintptr_t>(setPtrUC) & pointerMask) | ptrUnitigColors; |
| 19 | } |
| 20 | else if (flag == ptrBitmap){ |
| 21 | |
| 22 | Bitmap* setPtrBmp = new Bitmap; |
| 23 | |
| 24 | setPtrBmp->r = o.getConstPtrBitmap()->r; |
| 25 | |
| 26 | setBits = (reinterpret_cast<uintptr_t>(setPtrBmp) & pointerMask) | ptrBitmap; |
| 27 | } |
| 28 | else if (flag == ptrSharedUnitigColors){ |
| 29 | |
| 30 | const SharedUnitigColors* s_uc = o.getConstPtrSharedUnitigColors(); |
| 31 | |
| 32 | *this = s_uc->first; |
| 33 | } |
| 34 | else if (flag == localTinyBitmap){ |
| 35 | |
| 36 | uint16_t* setPtrTinyBmp = o.getPtrTinyBitmap(); |
| 37 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 38 | TinyBitmap t_bmp_cpy(t_bmp); |
| 39 | |
| 40 | t_bmp.detach(); |
| 41 | |
| 42 | setBits = (reinterpret_cast<uintptr_t>(t_bmp_cpy.detach()) & pointerMask) | localTinyBitmap; |
| 43 | } |
| 44 | else setBits = o.setBits; |
| 45 | } |
| 46 | |
| 47 | UnitigColors::UnitigColors(const UnitigColors& o, const SharedUnitigColors* old_ref_uc, const SharedUnitigColors* new_ref_uc){ |
| 48 | |
| 49 | const uintptr_t flag = o.setBits & flagMask; |
| 50 | |
| 51 | if (flag == ptrUnitigColors){ |
| 52 | |
| 53 | const UnitigColors* uc_o = o.getConstPtrUnitigColors(); |
| 54 | |
| 55 | UnitigColors* setPtrUC = new UnitigColors[2]; |
| 56 | |
| 57 | new (&setPtrUC[0]) UnitigColors(uc_o[0], old_ref_uc, new_ref_uc); |
| 58 | new (&setPtrUC[1]) UnitigColors(uc_o[1], old_ref_uc, new_ref_uc); |
| 59 | |
| 60 | setBits = (reinterpret_cast<uintptr_t>(setPtrUC) & pointerMask) | ptrUnitigColors; |
| 61 | } |
| 62 | else if (flag == ptrBitmap){ |
| 63 | |
| 64 | Bitmap* setPtrBmp = new Bitmap; |
| 65 | |
| 66 | setPtrBmp->r = o.getConstPtrBitmap()->r; |
| 67 | |
| 68 | setBits = (reinterpret_cast<uintptr_t>(setPtrBmp) & pointerMask) | ptrBitmap; |
| 69 | } |
| 70 | else if (flag == ptrSharedUnitigColors){ |
| 71 | |
| 72 | const uintptr_t ptr = reinterpret_cast<uintptr_t>(new_ref_uc) + (o.getPtrSharedUnitigColors() - old_ref_uc); |
| 73 | |
| 74 | setBits = (ptr & pointerMask) | ptrSharedUnitigColors; |
| 75 | } |
| 76 | else if (flag == localTinyBitmap){ |
| 77 | |
| 78 | uint16_t* setPtrTinyBmp = o.getPtrTinyBitmap(); |
| 79 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 80 | TinyBitmap t_bmp_cpy(t_bmp); |
| 81 | |
| 82 | t_bmp.detach(); |
| 83 | |
| 84 | setBits = (reinterpret_cast<uintptr_t>(t_bmp_cpy.detach()) & pointerMask) | localTinyBitmap; |
| 85 | } |
| 86 | else setBits = o.setBits; |
| 87 | } |
| 88 | |
| 89 | UnitigColors::UnitigColors(SharedUnitigColors& o) { |
| 90 | |
| 91 | ++(o.second); |
| 92 | |
| 93 | setBits = (reinterpret_cast<uintptr_t>(&o) & pointerMask) | ptrSharedUnitigColors; |
| 94 | } |
| 95 | |
| 96 | UnitigColors::UnitigColors(UnitigColors&& o) : setBits(o.setBits) { |
| 97 | |
| 98 | o.setBits = localBitVector; |
| 99 | } |
| 100 | |
| 101 | UnitigColors::~UnitigColors() { |
| 102 | |
| 103 | releaseMemory(); |
| 104 | } |
| 105 | |
| 106 | UnitigColors& UnitigColors::operator=(const UnitigColors& o){ |
| 107 | |
| 108 | if (this != &o) { |
| 109 | |
| 110 | const uintptr_t flag = o.setBits & flagMask; |
| 111 | const uintptr_t this_flag = setBits & flagMask; |
| 112 | |
| 113 | if (flag == ptrUnitigColors){ |
| 114 | |
| 115 | const UnitigColors* uc_o = o.getConstPtrUnitigColors(); |
| 116 | |
| 117 | UnitigColors* setPtrUC = nullptr; |
| 118 | |
| 119 | if (this_flag == ptrUnitigColors) setPtrUC = getPtrUnitigColors(); |
| 120 | else { |
| 121 | |
| 122 | releaseMemory(); |
| 123 | setPtrUC = new UnitigColors[2]; |
| 124 | } |
| 125 | |
| 126 | setPtrUC[0] = uc_o[0]; |
| 127 | setPtrUC[1] = uc_o[1]; |
| 128 | |
| 129 | setBits = (reinterpret_cast<uintptr_t>(setPtrUC) & pointerMask) | ptrUnitigColors; |
| 130 | } |
| 131 | else if (flag == ptrBitmap){ |
| 132 | |
| 133 | Bitmap* setPtrBmp = nullptr; |
| 134 | |
| 135 | if (this_flag == ptrBitmap) setPtrBmp = getPtrBitmap(); |
| 136 | else { |
| 137 | |
| 138 | releaseMemory(); |
| 139 | setPtrBmp = new Bitmap; |
| 140 | } |
| 141 | |
| 142 | setPtrBmp->r = o.getConstPtrBitmap()->r; |
| 143 | |
| 144 | setBits = (reinterpret_cast<uintptr_t>(setPtrBmp) & pointerMask) | ptrBitmap; |
| 145 | } |
| 146 | else if (flag == ptrSharedUnitigColors){ |
| 147 | |
| 148 | const SharedUnitigColors* s_uc = o.getConstPtrSharedUnitigColors(); |
| 149 | |
| 150 | *this = s_uc->first; |
| 151 | } |
| 152 | else if (flag == localTinyBitmap){ |
| 153 | |
| 154 | releaseMemory(); |
| 155 | |
| 156 | uint16_t* setPtrTinyBmp = o.getPtrTinyBitmap(); |
| 157 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 158 | TinyBitmap t_bmp_cpy(t_bmp); |
| 159 | |
| 160 | t_bmp.detach(); |
| 161 | |
| 162 | setBits = (reinterpret_cast<uintptr_t>(t_bmp_cpy.detach()) & pointerMask) | localTinyBitmap; |
| 163 | } |
| 164 | else { |
| 165 | |
| 166 | releaseMemory(); |
| 167 | |
| 168 | setBits = o.setBits; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | return *this; |
| 173 | } |
| 174 | |
| 175 | UnitigColors& UnitigColors::operator=(SharedUnitigColors& o){ |
| 176 | |
| 177 | releaseMemory(); |
| 178 | |
| 179 | ++(o.second); |
| 180 | |
| 181 | setBits = (reinterpret_cast<uintptr_t>(&o) & pointerMask) | ptrSharedUnitigColors; |
| 182 | |
| 183 | return *this; |
| 184 | } |
| 185 | |
| 186 | UnitigColors& UnitigColors::operator=(UnitigColors&& o){ |
| 187 | |
| 188 | if (this != &o) { |
| 189 | |
| 190 | releaseMemory(); |
| 191 | |
| 192 | setBits = o.setBits; |
| 193 | o.setBits = localBitVector; |
| 194 | } |
| 195 | |
| 196 | return *this; |
| 197 | } |
| 198 | |
| 199 | /*bool UnitigColors::operator==(const UnitigColors& o) const { |
| 200 | |
| 201 | if (size() != o.size()) return false; |
| 202 | if (isUnitigColors() != o.isUnitigColors()) return false; |
| 203 | |
| 204 | UnitigColors::const_iterator it(begin(1)), o_it(o.begin(1)); |
| 205 | const UnitigColors::const_iterator it_end(end()), o_it_end(o.end()); |
| 206 | |
| 207 | for (; (it != it_end) && (o_it != o_it_end); ++it, ++o_it){ |
| 208 | |
| 209 | if (it.get_ID() != o_it.get_ID()) return false; |
| 210 | } |
| 211 | |
| 212 | return ((it == it_end) && (o_it == o_it_end)); |
| 213 | }*/ |
| 214 | |
| 215 | bool UnitigColors::isEqual(const UnitigMapBase& um, const UnitigColors& o, const UnitigMapBase& um_o) const { |
| 216 | |
| 217 | if (size() != o.size()) return false; |
| 218 | |
| 219 | UnitigColors::const_iterator it(begin(0, um.size - Kmer::k + 1, um.size - Kmer::k + 1)); |
| 220 | UnitigColors::const_iterator o_it(o.begin(0, um_o.size - Kmer::k + 1, um_o.size - Kmer::k + 1)); |
| 221 | const UnitigColors::const_iterator it_end(end()), o_it_end(o.end()); |
| 222 | |
| 223 | for (; (it != it_end) && (o_it != o_it_end); ++it, ++o_it){ |
| 224 | |
| 225 | if (it.get_ID() != o_it.get_ID()) return false; |
| 226 | } |
| 227 | |
| 228 | return ((it == it_end) && (o_it == o_it_end)); |
| 229 | } |
| 230 | |
| 231 | void UnitigColors::clear(){ |
| 232 | |
| 233 | releaseMemory(); |
| 234 | setBits = localBitVector; |
| 235 | } |
| 236 | |
| 237 | size_t UnitigColors::getSizeInBytes() const { |
| 238 | |
| 239 | const uintptr_t flag = setBits & flagMask; |
| 240 | |
| 241 | if (flag == ptrUnitigColors){ |
| 242 | |
| 243 | return sizeof(UnitigColors) + getConstPtrUnitigColors()[0].getSizeInBytes() + getConstPtrUnitigColors()[1].getSizeInBytes(); |
| 244 | } |
| 245 | |
| 246 | if (flag == ptrBitmap) return getConstPtrBitmap()->r.getSizeInBytes() + sizeof(Bitmap) + sizeof(UnitigColors); |
| 247 | |
| 248 | if (flag == localTinyBitmap){ |
| 249 | |
| 250 | uint16_t* setPtrTinyBmp = getPtrTinyBitmap(); |
| 251 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 252 | const size_t ret = t_bmp.getSizeInBytes(); |
| 253 | |
| 254 | t_bmp.detach(); |
| 255 | |
| 256 | return ret; |
| 257 | } |
| 258 | |
| 259 | return sizeof(UnitigColors); // if (flag == ptrSharedUnitigColors), we do not own the pointed UnitigCors so its size is not considered |
| 260 | } |
| 261 | |
| 262 | void UnitigColors::add(const UnitigMapBase& um, const size_t color_id) { |
| 263 | |
| 264 | uintptr_t flag = setBits & flagMask; |
| 265 | |
| 266 | if (flag == ptrUnitigColors){ |
| 267 | |
| 268 | UnitigColors* uc = getPtrUnitigColors(); |
| 269 | |
| 270 | if (!uc[0].contains(color_id)) uc[1].add(um, color_id); |
| 271 | } |
| 272 | else { |
| 273 | |
| 274 | const size_t um_km_sz = um.size - Kmer::k + 1; |
| 275 | size_t color_id_start = um_km_sz * color_id + um.dist; |
| 276 | const size_t color_id_end = color_id_start + std::min(um_km_sz - um.dist, um.len); |
| 277 | |
| 278 | if (flag == ptrSharedUnitigColors){ // copy-on-write |
| 279 | |
| 280 | SharedUnitigColors* s_uc = getPtrSharedUnitigColors(); |
| 281 | |
| 282 | *this = s_uc->first; |
| 283 | |
| 284 | if (--(s_uc->second) == 0) s_uc->first.clear(); |
| 285 | |
| 286 | flag = setBits & flagMask; |
| 287 | } |
| 288 | |
| 289 | if (flag == localSingleInt){ |
| 290 | |
| 291 | const uintptr_t setBits_tmp = setBits >> shiftMaskBits; |
| 292 | |
| 293 | if ((setBits_tmp < maxBitVectorIDs) && ((color_id_end - 1) < maxBitVectorIDs)){ |
| 294 | |
| 295 | setBits = (1ULL << (setBits_tmp + shiftMaskBits)) | localBitVector; |
| 296 | } |
| 297 | else { |
| 298 | |
| 299 | TinyBitmap t_bmp; |
| 300 | |
| 301 | if (t_bmp.add(setBits_tmp)) setBits = (reinterpret_cast<uintptr_t>(t_bmp.detach()) & pointerMask) | localTinyBitmap; |
| 302 | else { |
| 303 | |
| 304 | Bitmap* setPtrBmp = new Bitmap; |
| 305 | |
| 306 | t_bmp.clear(); |
| 307 | setPtrBmp->r.add(setBits_tmp); |
| 308 | |
| 309 | setBits = (reinterpret_cast<uintptr_t>(setPtrBmp) & pointerMask) | ptrBitmap; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | flag = setBits & flagMask; |
| 314 | } |
| 315 | |
| 316 | if (flag == localBitVector){ |
| 317 | |
| 318 | if ((setBits == localBitVector) && (um.len == 1)) setBits = (color_id_start << shiftMaskBits) | localSingleInt; |
| 319 | else if ((color_id_end - 1) < maxBitVectorIDs){ |
| 320 | |
| 321 | for (; color_id_start != color_id_end; ++color_id_start) setBits |= 1ULL << (color_id_start + shiftMaskBits); |
| 322 | } |
| 323 | else { |
| 324 | |
| 325 | uintptr_t setBits_tmp_tb = setBits >> shiftMaskBits; |
| 326 | uintptr_t setBits_tmp_cr = setBits >> shiftMaskBits; |
| 327 | |
| 328 | TinyBitmap t_bmp; |
| 329 | |
| 330 | bool add_ok = true; |
| 331 | |
| 332 | for (size_t i = 0; (setBits_tmp_tb != 0) && add_ok; ++i, setBits_tmp_tb >>= 1) { |
| 333 | |
| 334 | if (setBits_tmp_tb & 0x1) add_ok = t_bmp.add(i); |
| 335 | } |
| 336 | |
| 337 | if (add_ok) setBits = (reinterpret_cast<uintptr_t>(t_bmp.detach()) & pointerMask) | localTinyBitmap; |
| 338 | else { |
| 339 | |
| 340 | Bitmap* setPtrBmp = new Bitmap; |
| 341 | |
| 342 | t_bmp.clear(); |
| 343 | |
| 344 | for (size_t i = 0; setBits_tmp_cr != 0; ++i, setBits_tmp_cr >>= 1) { |
| 345 | |
| 346 | if (setBits_tmp_cr & 0x1) setPtrBmp->r.add(i); |
| 347 | } |
| 348 | |
| 349 | setBits = (reinterpret_cast<uintptr_t>(setPtrBmp) & pointerMask) | ptrBitmap; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | flag = setBits & flagMask; |
| 354 | } |
| 355 | |
| 356 | /*if (flag == localTinyBitmap) { |
| 357 | |
| 358 | bool add_ok = true; |
| 359 | |
| 360 | uint16_t* setPtrTinyBmp = getPtrTinyBitmap(); |
| 361 | |
| 362 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 363 | |
| 364 | while ((color_id_start < color_id_end) && add_ok) color_id_start += (add_ok = t_bmp.add(color_id_start)); |
| 365 | |
| 366 | if (add_ok) setBits = (reinterpret_cast<uintptr_t>(t_bmp.detach()) & pointerMask) | localTinyBitmap; |
| 367 | else { |
| 368 | |
| 369 | Bitmap* setPtrBmp = new Bitmap; |
| 370 | |
| 371 | TinyBitmap::const_iterator it = t_bmp.begin(); |
| 372 | const TinyBitmap::const_iterator it_end = t_bmp.end(); |
| 373 | |
| 374 | uint32_t range_start = *it, range_end = *it; |
| 375 | |
| 376 | if (it != it_end) ++it; |
| 377 | |
| 378 | while (it != it_end){ |
| 379 | |
| 380 | const uint32_t val = *it; |
| 381 | |
| 382 | ++range_end; |
| 383 | ++it; |
| 384 | |
| 385 | if (val != range_end) { |
| 386 | |
| 387 | setPtrBmp->r.addRange(range_start, range_end); |
| 388 | |
| 389 | range_start = val; |
| 390 | range_end = val; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | setPtrBmp->r.addRange(range_start, range_end + 1); |
| 395 | |
| 396 | t_bmp.clear(); |
| 397 | |
| 398 | setBits = (reinterpret_cast<uintptr_t>(setPtrBmp) & pointerMask) | ptrBitmap; |
| 399 | flag = ptrBitmap; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | if (flag == ptrBitmap) { |
| 404 | |
| 405 | Bitmap* bitmap = getPtrBitmap(); |
| 406 | |
| 407 | bitmap->r.addRange(color_id_start, color_id_end); |
| 408 | bitmap->r.runOptimize(); |
| 409 | }*/ |
| 410 | |
| 411 | if (flag == localTinyBitmap) { |
| 412 | |
| 413 | bool add_ok = true; |
| 414 | |
| 415 | uint16_t* setPtrTinyBmp = getPtrTinyBitmap(); |
| 416 | |
| 417 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 418 | |
| 419 | while ((color_id_start < color_id_end) && add_ok) color_id_start += (add_ok = t_bmp.add(color_id_start)); |
| 420 | |
| 421 | if (add_ok) setBits = (reinterpret_cast<uintptr_t>(t_bmp.detach()) & pointerMask) | localTinyBitmap; |
| 422 | else { |
| 423 | |
| 424 | const size_t sz_t_bmp = t_bmp.size(); |
| 425 | |
| 426 | uint32_t* values = new uint32_t[sz_t_bmp]; |
| 427 | |
| 428 | size_t i = 0; |
| 429 | |
| 430 | Bitmap* setPtrBmp = new Bitmap; |
| 431 | |
| 432 | for (TinyBitmap::const_iterator it = t_bmp.begin(), it_end = t_bmp.end(); it != it_end; ++it, ++i) values[i] = *it; |
| 433 | |
| 434 | t_bmp.clear(); |
| 435 | setPtrBmp->r.addMany(sz_t_bmp, values); |
| 436 | |
| 437 | setBits = (reinterpret_cast<uintptr_t>(setPtrBmp) & pointerMask) | ptrBitmap; |
| 438 | flag = ptrBitmap; |
| 439 | |
| 440 | delete[] values; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | if (flag == ptrBitmap) { |
| 445 | |
| 446 | Bitmap* bitmap = getPtrBitmap(); |
| 447 | |
| 448 | for (; color_id_start < color_id_end; ++color_id_start) bitmap->r.add(color_id_start); |
| 449 | |
| 450 | bitmap->r.runOptimize(); |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | void UnitigColors::add(const size_t color_id) { // PRIVATE |
| 456 | |
| 457 | uintptr_t flag = setBits & flagMask; |
| 458 | |
| 459 | if (flag == ptrUnitigColors){ |
| 460 | |
| 461 | UnitigColors* uc = getPtrUnitigColors(); |
| 462 | |
| 463 | if (!uc[0].contains(color_id)) uc[1].add(color_id); |
| 464 | } |
| 465 | else { |
| 466 | |
| 467 | if (flag == ptrSharedUnitigColors){ // copy-on-write |
| 468 | |
| 469 | SharedUnitigColors* s_uc = getPtrSharedUnitigColors(); |
| 470 | |
| 471 | *this = s_uc->first; |
| 472 | |
| 473 | if (--(s_uc->second) == 0) s_uc->first.clear(); |
| 474 | |
| 475 | flag = setBits & flagMask; |
| 476 | } |
| 477 | |
| 478 | if (flag == localSingleInt){ |
| 479 | |
| 480 | const uintptr_t setBits_tmp = setBits >> shiftMaskBits; |
| 481 | |
| 482 | if ((setBits_tmp < maxBitVectorIDs) && (color_id < maxBitVectorIDs)){ |
| 483 | |
| 484 | setBits = (1ULL << (setBits_tmp + shiftMaskBits)) | localBitVector; |
| 485 | } |
| 486 | else { |
| 487 | |
| 488 | TinyBitmap t_bmp; |
| 489 | |
| 490 | if (t_bmp.add(setBits_tmp)) setBits = (reinterpret_cast<uintptr_t>(t_bmp.detach()) & pointerMask) | localTinyBitmap; |
| 491 | else { |
| 492 | |
| 493 | Bitmap* setPtrBmp = new Bitmap; |
| 494 | |
| 495 | t_bmp.clear(); |
| 496 | setPtrBmp->r.add(setBits_tmp); |
| 497 | |
| 498 | setBits = (reinterpret_cast<uintptr_t>(setPtrBmp) & pointerMask) | ptrBitmap; |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | flag = setBits & flagMask; |
| 503 | } |
| 504 | |
| 505 | if (flag == localBitVector){ |
| 506 | |
| 507 | if (setBits == localBitVector) setBits = (color_id << shiftMaskBits) | localSingleInt; |
| 508 | else if (color_id < maxBitVectorIDs) setBits |= 1ULL << (color_id + shiftMaskBits); |
| 509 | else { |
| 510 | |
| 511 | uintptr_t setBits_tmp_tb = setBits >> shiftMaskBits; |
| 512 | uintptr_t setBits_tmp_cr = setBits >> shiftMaskBits; |
| 513 | |
| 514 | TinyBitmap t_bmp; |
| 515 | |
| 516 | bool add_ok = true; |
| 517 | |
| 518 | for (size_t i = 0; (setBits_tmp_tb != 0) && add_ok; ++i, setBits_tmp_tb >>= 1) { |
| 519 | |
| 520 | if (setBits_tmp_tb & 0x1) add_ok = t_bmp.add(i); |
| 521 | } |
| 522 | |
| 523 | if (add_ok) setBits = (reinterpret_cast<uintptr_t>(t_bmp.detach()) & pointerMask) | localTinyBitmap; |
| 524 | else { |
| 525 | |
| 526 | Bitmap* setPtrBmp = new Bitmap; |
| 527 | |
| 528 | t_bmp.clear(); |
| 529 | |
| 530 | for (size_t i = 0; setBits_tmp_cr != 0; ++i, setBits_tmp_cr >>= 1) { |
| 531 | |
| 532 | if (setBits_tmp_cr & 0x1) setPtrBmp->r.add(i); |
| 533 | } |
| 534 | |
| 535 | setBits = (reinterpret_cast<uintptr_t>(setPtrBmp) & pointerMask) | ptrBitmap; |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | flag = setBits & flagMask; |
| 540 | } |
| 541 | |
| 542 | /*if (flag == localTinyBitmap) { |
| 543 | |
| 544 | uint16_t* setPtrTinyBmp = getPtrTinyBitmap(); |
| 545 | |
| 546 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 547 | |
| 548 | if (t_bmp.add(color_id)) setBits = (reinterpret_cast<uintptr_t>(t_bmp.detach()) & pointerMask) | localTinyBitmap; |
| 549 | else { |
| 550 | |
| 551 | Bitmap* setPtrBmp = new Bitmap; |
| 552 | |
| 553 | TinyBitmap::const_iterator it = t_bmp.begin(); |
| 554 | const TinyBitmap::const_iterator it_end = t_bmp.end(); |
| 555 | |
| 556 | uint32_t range_start = *it, range_end = *it; |
| 557 | |
| 558 | if (it != it_end) ++it; |
| 559 | |
| 560 | while (it != it_end){ |
| 561 | |
| 562 | const uint32_t val = *it; |
| 563 | |
| 564 | ++range_end; |
| 565 | ++it; |
| 566 | |
| 567 | if (val != range_end) { |
| 568 | |
| 569 | setPtrBmp->r.addRange(range_start, range_end); |
| 570 | |
| 571 | range_start = val; |
| 572 | range_end = val; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | setPtrBmp->r.addRange(range_start, range_end + 1); |
| 577 | |
| 578 | t_bmp.clear(); |
| 579 | |
| 580 | setBits = (reinterpret_cast<uintptr_t>(setPtrBmp) & pointerMask) | ptrBitmap; |
| 581 | flag = ptrBitmap; |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | if (flag == ptrBitmap) getPtrBitmap()->r.add(color_id); // flag == ptrBitmap |
| 586 | */ |
| 587 | |
| 588 | if (flag == localTinyBitmap) { |
| 589 | |
| 590 | uint16_t* setPtrTinyBmp = getPtrTinyBitmap(); |
| 591 | |
| 592 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 593 | |
| 594 | if (t_bmp.add(color_id)) setBits = (reinterpret_cast<uintptr_t>(t_bmp.detach()) & pointerMask) | localTinyBitmap; |
| 595 | else { |
| 596 | |
| 597 | const size_t sz_t_bmp = t_bmp.size(); |
| 598 | |
| 599 | uint32_t* values = new uint32_t[sz_t_bmp]; |
| 600 | |
| 601 | size_t i = 0; |
| 602 | |
| 603 | Bitmap* setPtrBmp = new Bitmap; |
| 604 | |
| 605 | for (TinyBitmap::const_iterator it = t_bmp.begin(), it_end = t_bmp.end(); it != it_end; ++it, ++i) values[i] = *it; |
| 606 | |
| 607 | t_bmp.clear(); |
| 608 | setPtrBmp->r.addMany(sz_t_bmp, values); |
| 609 | |
| 610 | setBits = (reinterpret_cast<uintptr_t>(setPtrBmp) & pointerMask) | ptrBitmap; |
| 611 | flag = ptrBitmap; |
| 612 | |
| 613 | delete[] values; |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | if (flag == ptrBitmap) getPtrBitmap()->r.add(color_id); // flag == ptrBitmap |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | void UnitigColors::remove(const UnitigMapBase& um, const size_t color_id) { |
| 622 | |
| 623 | uintptr_t flag = setBits & flagMask; |
| 624 | |
| 625 | const size_t um_km_sz = um.size - Kmer::k + 1; |
| 626 | |
| 627 | if (flag == ptrUnitigColors){ |
| 628 | |
| 629 | UnitigColors* uc = getPtrUnitigColors(); |
| 630 | |
| 631 | if (uc[0].contains(color_id)){ |
| 632 | |
| 633 | const UnitigMapBase fake_um(0, 1, Kmer::k, true); |
| 634 | |
| 635 | uc[0].remove(fake_um, color_id); |
| 636 | |
| 637 | if (um.dist != 0){ |
| 638 | |
| 639 | const UnitigMapBase fake_um_start(0, um.dist, um.size, um.strand); |
| 640 | |
| 641 | uc[1].add(fake_um_start, color_id); |
| 642 | } |
| 643 | |
| 644 | if ((um_km_sz - um.len - um.dist) != 0){ |
| 645 | |
| 646 | const UnitigMapBase fake_um_end(um.dist + um.len, um_km_sz - um.len - um.dist, um.size, um.strand); |
| 647 | |
| 648 | uc[1].add(fake_um_end, color_id); |
| 649 | } |
| 650 | } |
| 651 | else uc[1].remove(um, color_id); |
| 652 | |
| 653 | return; |
| 654 | } |
| 655 | |
| 656 | if (flag == ptrSharedUnitigColors){ // copy-on-write |
| 657 | |
| 658 | SharedUnitigColors* s_uc = getPtrSharedUnitigColors(); |
| 659 | |
| 660 | *this = s_uc->first; |
| 661 | |
| 662 | if (--(s_uc->second) == 0) s_uc->first.clear(); |
| 663 | |
| 664 | flag = setBits & flagMask; |
| 665 | } |
| 666 | |
| 667 | size_t color_id_start = um_km_sz * color_id + um.dist; |
| 668 | const size_t color_id_end = color_id_start + std::min(um_km_sz - um.dist, um.len); |
| 669 | |
| 670 | if (flag == localBitVector){ |
| 671 | |
| 672 | uintptr_t mask = 0; |
| 673 | |
| 674 | for (; color_id_start < min(maxBitVectorIDs, color_id_end); ++color_id_start) mask |= 1ULL << (color_id_start + shiftMaskBits); |
| 675 | |
| 676 | setBits &= ~mask; |
| 677 | } |
| 678 | else if (flag == localSingleInt){ |
| 679 | |
| 680 | const uintptr_t color_id = setBits >> shiftMaskBits; |
| 681 | |
| 682 | if ((color_id >= color_id_start) && (color_id < color_id_end)) setBits = localBitVector; |
| 683 | } |
| 684 | else if (flag == localTinyBitmap){ |
| 685 | |
| 686 | bool rm_ok = true; |
| 687 | |
| 688 | uint16_t* setPtrTinyBmp = getPtrTinyBitmap(); |
| 689 | |
| 690 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 691 | |
| 692 | while ((color_id_start < color_id_end) && rm_ok) color_id_start += (rm_ok = t_bmp.remove(color_id_start)); |
| 693 | |
| 694 | if (rm_ok){ |
| 695 | |
| 696 | const size_t card = t_bmp.size(); |
| 697 | |
| 698 | if (card == 0){ |
| 699 | |
| 700 | setBits = (reinterpret_cast<uintptr_t>(t_bmp.detach()) & pointerMask) | localTinyBitmap; |
| 701 | clear(); |
| 702 | } |
| 703 | else if (card == 1){ |
| 704 | |
| 705 | const uint32_t color_id = *(t_bmp.begin()); |
| 706 | |
| 707 | setBits = (reinterpret_cast<uintptr_t>(t_bmp.detach()) & pointerMask) | localTinyBitmap; |
| 708 | |
| 709 | clear(); |
| 710 | add(color_id); |
| 711 | } |
| 712 | else if ((card <= maxBitVectorIDs) && (t_bmp.maximum() < maxBitVectorIDs)){ |
| 713 | |
| 714 | UnitigColors new_uc; |
| 715 | |
| 716 | for (TinyBitmap::const_iterator it = t_bmp.begin(), it_end = t_bmp.end(); it != it_end; ++it) new_uc.add(*it); |
| 717 | |
| 718 | setBits = (reinterpret_cast<uintptr_t>(t_bmp.detach()) & pointerMask) | localTinyBitmap; |
| 719 | |
| 720 | *this = move(new_uc); |
| 721 | } |
| 722 | else setBits = (reinterpret_cast<uintptr_t>(t_bmp.detach()) & pointerMask) | localTinyBitmap; |
| 723 | } |
| 724 | else { |
| 725 | |
| 726 | const size_t sz_t_bmp = t_bmp.size(); |
| 727 | |
| 728 | uint32_t* values = new uint32_t[sz_t_bmp]; |
| 729 | |
| 730 | size_t i = 0; |
| 731 | |
| 732 | Bitmap* setPtrBmp = new Bitmap; |
| 733 | |
| 734 | for (TinyBitmap::const_iterator it = t_bmp.begin(), it_end = t_bmp.end(); it != it_end; ++it, ++i) values[i] = *it; |
| 735 | |
| 736 | t_bmp.clear(); |
| 737 | setPtrBmp->r.addMany(sz_t_bmp, values); |
| 738 | |
| 739 | setBits = (reinterpret_cast<uintptr_t>(setPtrBmp) & pointerMask) | ptrBitmap; |
| 740 | flag = ptrBitmap; |
| 741 | |
| 742 | delete[] values; |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | if (flag == ptrBitmap) { |
| 747 | |
| 748 | Bitmap* bitmap = getPtrBitmap(); |
| 749 | |
| 750 | for (; color_id_start < color_id_end; ++color_id_start) bitmap->r.remove(color_id_start); |
| 751 | |
| 752 | const size_t card = bitmap->r.cardinality(); |
| 753 | |
| 754 | if (card == 0) clear(); |
| 755 | else if (card == 1){ |
| 756 | |
| 757 | const uint32_t color_id = bitmap->r.minimum(); |
| 758 | |
| 759 | clear(); |
| 760 | add(color_id); |
| 761 | } |
| 762 | else if ((card <= maxBitVectorIDs) && (bitmap->r.maximum() < maxBitVectorIDs)){ |
| 763 | |
| 764 | UnitigColors new_uc; |
| 765 | |
| 766 | const_iterator it = begin(um), it_end = end(); |
| 767 | |
| 768 | for (; it != it_end; ++it) new_uc.add(it.getColorID() * um_km_sz + it.getKmerPosition()); |
| 769 | |
| 770 | *this = move(new_uc); |
| 771 | } |
| 772 | else if ((setBits & flagMask) == ptrBitmap) bitmap->r.runOptimize(); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | bool UnitigColors::contains(const UnitigMapBase& um, const size_t color_id) const { |
| 777 | |
| 778 | const uintptr_t flag = setBits & flagMask; |
| 779 | |
| 780 | if (flag == ptrUnitigColors){ |
| 781 | |
| 782 | const UnitigColors* uc = getConstPtrUnitigColors(); |
| 783 | |
| 784 | return (uc[0].contains(color_id) || uc[1].contains(um, color_id)); |
| 785 | } |
| 786 | |
| 787 | if (flag == ptrSharedUnitigColors) return getConstPtrSharedUnitigColors()->first.contains(um, color_id); |
| 788 | |
| 789 | const size_t um_km_sz = um.size - Kmer::k + 1; |
| 790 | size_t color_id_start = um_km_sz * color_id + um.dist; |
| 791 | const size_t color_id_end = color_id_start + std::min(um_km_sz - um.dist, um.len); |
| 792 | |
| 793 | if (flag == ptrBitmap) return getConstPtrBitmap()->r.containsRange(color_id_start, color_id_end); |
| 794 | |
| 795 | if (flag == localTinyBitmap){ |
| 796 | |
| 797 | uint16_t* setPtrTinyBmp = getPtrTinyBitmap(); |
| 798 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 799 | const bool ret = t_bmp.containsRange(color_id_start, color_id_end - 1); |
| 800 | |
| 801 | t_bmp.detach(); |
| 802 | |
| 803 | return ret; |
| 804 | } |
| 805 | |
| 806 | if (flag == localBitVector){ |
| 807 | |
| 808 | if ((color_id_end - 1) < maxBitVectorIDs){ |
| 809 | |
| 810 | uintptr_t setBits_tmp = setBits >> (color_id_start + shiftMaskBits); |
| 811 | |
| 812 | for (; color_id_start < color_id_end; ++color_id_start, setBits_tmp >>= 1){ |
| 813 | |
| 814 | if ((setBits_tmp & 0x1) == 0) return false; |
| 815 | } |
| 816 | } |
| 817 | else return false; |
| 818 | } |
| 819 | |
| 820 | if (flag == localSingleInt) return (um.len == 1) && (color_id_start == (setBits >> shiftMaskBits)); |
| 821 | |
| 822 | return true; |
| 823 | } |
| 824 | |
| 825 | bool UnitigColors::contains(const size_t color_km_id) const { |
| 826 | |
| 827 | const uintptr_t flag = setBits & flagMask; |
| 828 | |
| 829 | if (flag == ptrUnitigColors){ |
| 830 | |
| 831 | const UnitigColors* uc = getConstPtrUnitigColors(); |
| 832 | |
| 833 | return (uc[0].contains(color_km_id) || uc[1].contains(color_km_id)); |
| 834 | } |
| 835 | |
| 836 | if (flag == ptrSharedUnitigColors) return getConstPtrSharedUnitigColors()->first.contains(color_km_id); |
| 837 | |
| 838 | if (flag == ptrBitmap) return getConstPtrBitmap()->r.contains(color_km_id); |
| 839 | |
| 840 | if (flag == localTinyBitmap){ |
| 841 | |
| 842 | uint16_t* setPtrTinyBmp = getPtrTinyBitmap(); |
| 843 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 844 | const bool ret = t_bmp.contains(color_km_id); |
| 845 | |
| 846 | t_bmp.detach(); |
| 847 | |
| 848 | return ret; |
| 849 | } |
| 850 | |
| 851 | if (flag == localSingleInt) return (color_km_id == (setBits >> shiftMaskBits)); |
| 852 | |
| 853 | if (color_km_id < maxBitVectorIDs){ |
| 854 | |
| 855 | const uintptr_t setBits_tmp = 0x1ULL << (color_km_id + shiftMaskBits); |
| 856 | |
| 857 | return ((setBits & setBits_tmp) != 0); |
| 858 | } |
| 859 | |
| 860 | return false; |
| 861 | } |
| 862 | |
| 863 | size_t UnitigColors::colorMax(const UnitigMapBase& um) const { |
| 864 | |
| 865 | const uintptr_t flag = setBits & flagMask; |
| 866 | const size_t length_unitig_km = um.size - Kmer::k + 1; |
| 867 | |
| 868 | if (flag == ptrUnitigColors){ |
| 869 | |
| 870 | const UnitigColors* uc = getConstPtrUnitigColors(); |
| 871 | const UnitigMapBase fake_um(0, 1, Kmer::k, um.strand); |
| 872 | |
| 873 | return max(uc[0].colorMax(fake_um), uc[1].colorMax(um)); |
| 874 | } |
| 875 | |
| 876 | if (flag == ptrSharedUnitigColors) return getConstPtrSharedUnitigColors()->first.colorMax(um); |
| 877 | |
| 878 | if (flag == ptrBitmap) return getConstPtrBitmap()->r.maximum() / length_unitig_km; |
| 879 | |
| 880 | if (flag == localTinyBitmap){ |
| 881 | |
| 882 | uint16_t* setPtrTinyBmp = getPtrTinyBitmap(); |
| 883 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 884 | const size_t ret = t_bmp.maximum() / length_unitig_km; |
| 885 | |
| 886 | t_bmp.detach(); |
| 887 | |
| 888 | return ret; |
| 889 | } |
| 890 | |
| 891 | if (flag == localSingleInt) return (setBits >> shiftMaskBits) / length_unitig_km; |
| 892 | |
| 893 | const int nb_lead_0 = __builtin_clzll(setBits | flagMask); |
| 894 | |
| 895 | return (maxBitVectorIDs - nb_lead_0 - (nb_lead_0 != maxBitVectorIDs)) / length_unitig_km; |
| 896 | } |
| 897 | |
| 898 | size_t UnitigColors::size(const UnitigMapBase& um) const { |
| 899 | |
| 900 | const uintptr_t flag = setBits & flagMask; |
| 901 | |
| 902 | if (flag == ptrUnitigColors){ |
| 903 | |
| 904 | const UnitigColors* uc = getConstPtrUnitigColors(); |
| 905 | |
| 906 | return uc[0].size() * (um.size - Kmer::k + 1) + uc[1].size(); |
| 907 | } |
| 908 | |
| 909 | if (flag == ptrSharedUnitigColors) return getConstPtrSharedUnitigColors()->first.size(um); |
| 910 | |
| 911 | if (flag == ptrBitmap) return getConstPtrBitmap()->r.cardinality(); |
| 912 | |
| 913 | if (flag == localTinyBitmap){ |
| 914 | |
| 915 | uint16_t* setPtrTinyBmp = getPtrTinyBitmap(); |
| 916 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 917 | const size_t ret = t_bmp.size(); |
| 918 | |
| 919 | t_bmp.detach(); |
| 920 | |
| 921 | return ret; |
| 922 | } |
| 923 | |
| 924 | if (flag == localBitVector) return __builtin_popcountll(setBits & pointerMask); |
| 925 | |
| 926 | return 1; |
| 927 | } |
| 928 | |
| 929 | size_t UnitigColors::size(const UnitigMapBase& um, const size_t color_id) const { |
| 930 | |
| 931 | const size_t length_unitig_km = um.size - Kmer::k + 1; |
| 932 | |
| 933 | const uintptr_t flag = setBits & flagMask; |
| 934 | |
| 935 | if (flag == ptrUnitigColors){ |
| 936 | |
| 937 | const UnitigColors* uc = getConstPtrUnitigColors(); |
| 938 | |
| 939 | return static_cast<size_t>(uc[0].contains(color_id)) * length_unitig_km + uc[1].size(um, color_id); |
| 940 | } |
| 941 | |
| 942 | if (flag == ptrSharedUnitigColors) return getConstPtrSharedUnitigColors()->first.size(um, color_id); |
| 943 | |
| 944 | const size_t start_pos = color_id * length_unitig_km; |
| 945 | |
| 946 | size_t end_pos = start_pos + length_unitig_km; |
| 947 | |
| 948 | if (flag == ptrBitmap) { |
| 949 | |
| 950 | const Bitmap* bmp = getConstPtrBitmap(); |
| 951 | |
| 952 | if (start_pos == 0) return bmp->r.rank(end_pos - 1); |
| 953 | |
| 954 | return bmp->r.rank(end_pos - 1) - bmp->r.rank(start_pos - 1); |
| 955 | } |
| 956 | |
| 957 | if (flag == localTinyBitmap){ |
| 958 | |
| 959 | uint16_t* setPtrTinyBmp = getPtrTinyBitmap(); |
| 960 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 961 | const size_t ret = t_bmp.size(start_pos, end_pos); |
| 962 | |
| 963 | t_bmp.detach(); |
| 964 | |
| 965 | return ret; |
| 966 | } |
| 967 | |
| 968 | if (flag == localBitVector){ |
| 969 | |
| 970 | if (start_pos < maxBitVectorIDs){ |
| 971 | |
| 972 | uintptr_t mask = 0; |
| 973 | |
| 974 | end_pos = min(end_pos, maxBitVectorIDs); |
| 975 | |
| 976 | for (size_t i = start_pos; i != end_pos; ++i) mask |= 0x1ULL << (i + shiftMaskBits); |
| 977 | |
| 978 | return __builtin_popcountll(setBits & mask); |
| 979 | } |
| 980 | } |
| 981 | else { |
| 982 | |
| 983 | const uintptr_t ck_id = setBits >> shiftMaskBits; |
| 984 | |
| 985 | if ((ck_id >= start_pos) && (ck_id < end_pos)) return 1; |
| 986 | } |
| 987 | |
| 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | size_t UnitigColors::size() const { //Private |
| 992 | |
| 993 | const uintptr_t flag = setBits & flagMask; |
| 994 | |
| 995 | if (flag == ptrUnitigColors){ |
| 996 | |
| 997 | const UnitigColors* uc = getConstPtrUnitigColors(); |
| 998 | |
| 999 | return uc[0].size() + uc[1].size(); |
| 1000 | } |
| 1001 | |
| 1002 | if (flag == ptrSharedUnitigColors) return getConstPtrSharedUnitigColors()->first.size(); |
| 1003 | |
| 1004 | if (flag == ptrBitmap) return getConstPtrBitmap()->r.cardinality(); |
| 1005 | |
| 1006 | if (flag == localTinyBitmap){ |
| 1007 | |
| 1008 | uint16_t* setPtrTinyBmp = getPtrTinyBitmap(); |
| 1009 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 1010 | const size_t ret = t_bmp.size(); |
| 1011 | |
| 1012 | t_bmp.detach(); |
| 1013 | |
| 1014 | return ret; |
| 1015 | } |
| 1016 | |
| 1017 | if (flag == localBitVector) return __builtin_popcountll(setBits & pointerMask); |
| 1018 | |
| 1019 | return 1; |
| 1020 | } |
| 1021 | |
| 1022 | uint64_t UnitigColors::hash(const size_t seed) const { |
| 1023 | |
| 1024 | uint64_t h = 17; |
| 1025 | |
| 1026 | if ((setBits & flagMask) == ptrUnitigColors){ //FNV hashing (stands for Fowler/Noll/Vo) |
| 1027 | |
| 1028 | const UnitigColors* uc = getConstPtrUnitigColors(); |
| 1029 | |
| 1030 | const uint64_t h1 = uc[1].hash(seed); |
| 1031 | |
| 1032 | const unsigned char* p = (unsigned char*) &h1; |
| 1033 | |
| 1034 | h = uc[0].hash(seed); |
| 1035 | |
| 1036 | for (size_t i = 0; i < sizeof(uint64_t); ++i) h = (h ^ p[i]) * 1099511628211ULL; |
| 1037 | |
| 1038 | return h; |
| 1039 | } |
| 1040 | |
| 1041 | uint64_t buffer[64] = {0}; |
| 1042 | |
| 1043 | const size_t nb_bytes_buffer = 64 * sizeof(uint64_t); |
| 1044 | const size_t nb_bits_buffer = nb_bytes_buffer * 8; |
| 1045 | |
| 1046 | UnitigColors::const_iterator it(begin(0, 1, 1)); |
| 1047 | const UnitigColors::const_iterator it_end(end()); |
| 1048 | |
| 1049 | if (it != it_end){ |
| 1050 | |
| 1051 | const size_t nb_empty_buffer = it.get_ID() >> 12; |
| 1052 | |
| 1053 | size_t up_bound = (nb_empty_buffer * nb_bits_buffer) + nb_bits_buffer; |
| 1054 | |
| 1055 | if (nb_empty_buffer != 0){ |
| 1056 | |
| 1057 | const uint64_t h_empty = wyhash(buffer, nb_bytes_buffer, seed, _wyp); |
| 1058 | |
| 1059 | // https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/builder/HashCodeBuilder.html |
| 1060 | for (size_t i = 0; i < nb_empty_buffer; ++it) h = h * 37 + h_empty; |
| 1061 | } |
| 1062 | |
| 1063 | while (it != it_end) { |
| 1064 | |
| 1065 | while ((it != it_end) && (it.get_ID() < up_bound)){ |
| 1066 | |
| 1067 | buffer[(it.get_ID() & 0xFFF) >> 6] |= 1ULL << (it.get_ID() & 0x3F); |
| 1068 | ++it; |
| 1069 | } |
| 1070 | |
| 1071 | h = h * 37 + wyhash(buffer, nb_bytes_buffer, seed, _wyp); |
| 1072 | up_bound += nb_bits_buffer; |
| 1073 | |
| 1074 | std::memset(buffer, 0, nb_bytes_buffer); |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | return h; |
| 1079 | } |
| 1080 | |
| 1081 | bool UnitigColors::optimizeFullColors(const UnitigMapBase& um){ |
| 1082 | |
| 1083 | const uintptr_t flag = setBits & flagMask; |
| 1084 | |
| 1085 | if ((um.size > Kmer::k) && (flag != localBitVector) && (flag != localSingleInt)){ |
| 1086 | |
| 1087 | UnitigColors full_uc(getFullColors(um)); |
| 1088 | UnitigColors non_full_uc(getNonFullColors(um, full_uc)); |
| 1089 | |
| 1090 | if ((full_uc.getSizeInBytes() + non_full_uc.getSizeInBytes() + sizeof(UnitigColors)) < getSizeInBytes()){ |
| 1091 | |
| 1092 | clear(); |
| 1093 | |
| 1094 | UnitigColors* uc = new UnitigColors[2]; |
| 1095 | |
| 1096 | uc[0] = move(full_uc); |
| 1097 | uc[1] = move(non_full_uc); |
| 1098 | |
| 1099 | setBits = (reinterpret_cast<uintptr_t>(uc) & pointerMask) | ptrUnitigColors; |
| 1100 | |
| 1101 | shrinkSize(); |
| 1102 | |
| 1103 | return true; |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | return false; |
| 1108 | } |
| 1109 | |
| 1110 | UnitigColors UnitigColors::makeFullColors(const UnitigMapBase& um) const { |
| 1111 | |
| 1112 | const uintptr_t flag = setBits & flagMask; |
| 1113 | |
| 1114 | UnitigColors full_uc(getFullColors(um)); |
| 1115 | UnitigColors non_full_uc(getNonFullColors(um, full_uc)); |
| 1116 | UnitigColors new_uc; |
| 1117 | |
| 1118 | UnitigColors* uc = new UnitigColors[2]; |
| 1119 | |
| 1120 | uc[0] = move(full_uc); |
| 1121 | uc[1] = move(non_full_uc); |
| 1122 | |
| 1123 | new_uc.setBits = (reinterpret_cast<uintptr_t>(uc) & pointerMask) | ptrUnitigColors; |
| 1124 | |
| 1125 | new_uc.shrinkSize(); |
| 1126 | |
| 1127 | return new_uc; |
| 1128 | } |
| 1129 | |
| 1130 | UnitigColors UnitigColors::getNonFullColors(const UnitigMapBase& um, const UnitigColors& full_uc) const { |
| 1131 | |
| 1132 | UnitigColors non_full_uc(((setBits & flagMask) == ptrUnitigColors) ? getConstPtrUnitigColors()[1] : *this); |
| 1133 | |
| 1134 | UnitigColors::const_iterator it_f(full_uc.begin(0, 1, 1)); |
| 1135 | const UnitigColors::const_iterator it_f_end(full_uc.end()); |
| 1136 | |
| 1137 | while (it_f != it_f_end){ |
| 1138 | |
| 1139 | non_full_uc.remove(um, it_f.get_ID()); |
| 1140 | ++it_f; |
| 1141 | } |
| 1142 | |
| 1143 | return non_full_uc; |
| 1144 | } |
| 1145 | |
| 1146 | UnitigColors UnitigColors::getFullColors(const UnitigMapBase& um) const { |
| 1147 | |
| 1148 | const size_t len_um_km = um.size - Kmer::k + 1; |
| 1149 | |
| 1150 | size_t prev_color_ID = 0xFFFFFFFFFFFFFFFF; |
| 1151 | size_t count = 0; |
| 1152 | |
| 1153 | UnitigColors new_uc; |
| 1154 | |
| 1155 | UnitigColors::const_iterator it(begin(0, len_um_km, len_um_km)); |
| 1156 | const UnitigColors::const_iterator it_end(end()); |
| 1157 | |
| 1158 | for (; it != it_end; ++it, ++count){ |
| 1159 | |
| 1160 | if (it.getColorID() != prev_color_ID){ |
| 1161 | |
| 1162 | if (count == len_um_km) new_uc.add(prev_color_ID); |
| 1163 | |
| 1164 | count = 0; |
| 1165 | prev_color_ID = it.getColorID(); |
| 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | if (count == len_um_km) new_uc.add(prev_color_ID); |
| 1170 | |
| 1171 | return new_uc; |
| 1172 | } |
| 1173 | |
| 1174 | bool UnitigColors::write(ostream& stream_out, const bool copy_UnitigColors) const { |
| 1175 | |
| 1176 | if (stream_out.good()){ |
| 1177 | |
| 1178 | const uintptr_t flag = setBits & flagMask; |
| 1179 | |
| 1180 | if (flag == ptrUnitigColors){ |
| 1181 | |
| 1182 | stream_out.write(reinterpret_cast<const char*>(&flag), sizeof(uintptr_t)); |
| 1183 | |
| 1184 | const UnitigColors* uc = getConstPtrUnitigColors(); |
| 1185 | |
| 1186 | const bool ret = uc[0].write(stream_out, copy_UnitigColors); |
| 1187 | |
| 1188 | return (ret ? uc[1].write(stream_out, copy_UnitigColors) : ret); |
| 1189 | } |
| 1190 | else if (flag == ptrSharedUnitigColors){ |
| 1191 | |
| 1192 | if (copy_UnitigColors) getConstPtrSharedUnitigColors()->first.write(stream_out, copy_UnitigColors); |
| 1193 | else stream_out.write(reinterpret_cast<const char*>(&flag), sizeof(uintptr_t)); |
| 1194 | } |
| 1195 | else if (flag == ptrBitmap){ |
| 1196 | |
| 1197 | const uint32_t expected_sz = getConstPtrBitmap()->r.getSizeInBytes(); |
| 1198 | |
| 1199 | const uintptr_t flag_expected_sz = (static_cast<uintptr_t>(expected_sz) << shiftMaskBits) | flag; |
| 1200 | |
| 1201 | char* serialized = new char[expected_sz]; |
| 1202 | |
| 1203 | getConstPtrBitmap()->r.write(serialized); |
| 1204 | |
| 1205 | stream_out.write(reinterpret_cast<const char*>(&flag_expected_sz), sizeof(uintptr_t)); |
| 1206 | stream_out.write(serialized, expected_sz); |
| 1207 | |
| 1208 | delete[] serialized; |
| 1209 | } |
| 1210 | else if (flag == localTinyBitmap){ |
| 1211 | |
| 1212 | uint16_t* setPtrTinyBmp = getPtrTinyBitmap(); |
| 1213 | TinyBitmap t_bmp(&setPtrTinyBmp); |
| 1214 | |
| 1215 | stream_out.write(reinterpret_cast<const char*>(&flag), sizeof(uintptr_t)); |
| 1216 | |
| 1217 | t_bmp.write(stream_out); |
| 1218 | t_bmp.detach(); |
| 1219 | } |
| 1220 | else stream_out.write(reinterpret_cast<const char*>(&setBits), sizeof(uintptr_t)); |
| 1221 | |
| 1222 | return true; |
| 1223 | } |
| 1224 | |
| 1225 | return false; |
| 1226 | } |
| 1227 | |
| 1228 | bool UnitigColors::read(istream& stream_in) { |
| 1229 | |
| 1230 | if (stream_in.good()){ |
| 1231 | |
| 1232 | clear(); |
| 1233 | |
| 1234 | stream_in.read(reinterpret_cast<char*>(&setBits), sizeof(uintptr_t)); |
| 1235 | |
| 1236 | const uintptr_t flag = setBits & flagMask; |
| 1237 | |
| 1238 | if (flag == ptrUnitigColors){ |
| 1239 | |
| 1240 | UnitigColors* setPtrUC = new UnitigColors[2]; |
| 1241 | |
| 1242 | bool ret = setPtrUC[0].read(stream_in); |
| 1243 | |
| 1244 | if (ret) ret = setPtrUC[1].read(stream_in); |
| 1245 | |
| 1246 | setBits = (reinterpret_cast<uintptr_t>(setPtrUC) & pointerMask) | ptrUnitigColors; |
| 1247 | |
| 1248 | return ret; |
| 1249 | } |
| 1250 | else if (flag == ptrBitmap){ |
| 1251 | |
| 1252 | Bitmap* setPtrBmp = new Bitmap; |
| 1253 | |
| 1254 | const uint32_t expected_sz = static_cast<uint32_t>(setBits >> shiftMaskBits); |
| 1255 | |
| 1256 | char* serialized = new char[expected_sz]; |
| 1257 | |
| 1258 | stream_in.read(serialized, expected_sz); |
| 1259 | |
| 1260 | setPtrBmp->r = Roaring::read(serialized); |
| 1261 | |
| 1262 | setBits = (reinterpret_cast<uintptr_t>(setPtrBmp) & pointerMask) | ptrBitmap; |
| 1263 | |
| 1264 | delete[] serialized; |
| 1265 | } |
| 1266 | else if (flag == localTinyBitmap){ |
| 1267 | |
| 1268 | TinyBitmap t_bmp; |
| 1269 | |
| 1270 | t_bmp.read(stream_in); |
| 1271 | |
| 1272 | setBits = (reinterpret_cast<uintptr_t>(t_bmp.detach()) & pointerMask) | localTinyBitmap; |
| 1273 | } |
| 1274 | |
| 1275 | return true; |
| 1276 | } |
| 1277 | |
| 1278 | return false; |
| 1279 | } |
| 1280 | |
| 1281 | UnitigColors::const_iterator UnitigColors::begin(const UnitigMapBase& um) const { |
| 1282 | |
| 1283 | if (um.isEmpty) return end(); |
| 1284 | else { |
| 1285 | |
| 1286 | const_iterator it(this, um.dist, um.dist + um.len, um.size - Kmer::k + 1, true); |
| 1287 | return ++it; |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | UnitigColors::const_iterator UnitigColors::begin(const size_t start_pos, const size_t end_pos, const size_t len_km_sz) const { |
| 1292 | |
| 1293 | const_iterator it(this, start_pos, end_pos, len_km_sz, true); |
| 1294 | return ++it; |
| 1295 | } |
| 1296 | |
| 1297 | UnitigColors::const_iterator UnitigColors::end() const { |
| 1298 | |
| 1299 | return const_iterator(this, 0, 0, 0, false); |
| 1300 | } |
| 1301 | |
| 1302 | UnitigColors UnitigColors::reverse(const UnitigMapBase& um) const { |
| 1303 | |
| 1304 | UnitigColors new_cs; |
| 1305 | |
| 1306 | if ((setBits & flagMask) == ptrUnitigColors){ |
| 1307 | |
| 1308 | const UnitigColors* uc = getConstPtrUnitigColors(); |
| 1309 | |
| 1310 | UnitigColors* setPtrUC = new UnitigColors[2]; |
| 1311 | |
| 1312 | setPtrUC[0] = uc[0]; |
| 1313 | setPtrUC[1] = uc[1].reverse(um); |
| 1314 | |
| 1315 | new_cs.setBits = (reinterpret_cast<uintptr_t>(setPtrUC) & pointerMask) | ptrUnitigColors; |
| 1316 | } |
| 1317 | else if ((setBits & flagMask) == ptrSharedUnitigColors){ |
| 1318 | |
| 1319 | new_cs = getConstPtrSharedUnitigColors()->first.reverse(um); |
| 1320 | } |
| 1321 | else { |
| 1322 | |
| 1323 | const size_t len_unitig_km = um.size - Kmer::k + 1; |
| 1324 | |
| 1325 | UnitigColors::const_iterator it(begin(0, len_unitig_km, len_unitig_km)); |
| 1326 | const UnitigColors::const_iterator it_end(end()); |
| 1327 | |
| 1328 | for (; it != it_end; ++it){ |
| 1329 | |
| 1330 | const size_t new_km_dist = len_unitig_km - it.getKmerPosition() - 1; |
| 1331 | |
| 1332 | new_cs.add(len_unitig_km * it.getColorID() + new_km_dist); |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | return new_cs; |
| 1337 | } |
| 1338 | |
| 1339 | UnitigColors::UnitigColors_const_iterator::UnitigColors_const_iterator() : cs(nullptr), it_uc(nullptr), flag(localBitVector), it_setBits(0), |
| 1340 | ck_id(0xffffffffffffffff), cs_sz(0), um_sz(0), start_pos(0), |
| 1341 | end_pos(0), it_roar(empty_roar.end()) {} |
| 1342 | |
| 1343 | UnitigColors::UnitigColors_const_iterator::UnitigColors_const_iterator( const UnitigColors* cs_, const size_t start_pos_, const size_t end_pos_, |
| 1344 | const size_t len_unitig_km, const bool beg) : |
| 1345 | cs(cs_), it_uc(nullptr), um_sz(len_unitig_km), start_pos(0), |
| 1346 | end_pos(0), ck_id(0xffffffffffffffff), it_setBits(0xffffffffffffffff), |
| 1347 | it_roar(empty_roar.end()) { |
| 1348 | |
| 1349 | flag = cs->setBits & flagMask; |
| 1350 | |
| 1351 | if (flag == ptrUnitigColors){ |
| 1352 | |
| 1353 | const UnitigColors* uc = cs->getConstPtrUnitigColors(); |
| 1354 | |
| 1355 | it_uc = new UnitigColors_const_iterator[2]; |
| 1356 | |
| 1357 | it_uc[0] = beg ? uc[0].begin(0, 1, 1) : uc[0].end(); |
| 1358 | it_uc[1] = beg ? uc[1].begin(start_pos_, end_pos_, len_unitig_km) : uc[1].end(); |
| 1359 | |
| 1360 | cs_sz = cs->size(); |
| 1361 | } |
| 1362 | else if (flag == ptrSharedUnitigColors){ |
| 1363 | |
| 1364 | *this = UnitigColors_const_iterator(&(cs->getConstPtrSharedUnitigColors()->first), start_pos_, end_pos_, len_unitig_km, beg); |
| 1365 | } |
| 1366 | else if (flag == ptrBitmap){ |
| 1367 | |
| 1368 | it_roar = beg ? cs->getConstPtrBitmap()->r.begin() : cs->getConstPtrBitmap()->r.end(); |
| 1369 | cs_sz = cs->size(); |
| 1370 | } |
| 1371 | else if (flag == localTinyBitmap){ |
| 1372 | |
| 1373 | uint16_t* setPtrTinyBmp = cs->getPtrTinyBitmap(); |
| 1374 | |
| 1375 | t_bmp = &setPtrTinyBmp; |
| 1376 | it_t_bmp = beg ? t_bmp.begin() : t_bmp.end(); |
| 1377 | cs_sz = cs->size(); |
| 1378 | } |
| 1379 | else cs_sz = (flag == localSingleInt) ? 1 : maxBitVectorIDs; |
| 1380 | |
| 1381 | if (beg){ |
| 1382 | |
| 1383 | start_pos = start_pos_; |
| 1384 | end_pos = end_pos_; |
| 1385 | } |
| 1386 | else it_setBits = cs_sz; |
| 1387 | } |
| 1388 | |
| 1389 | UnitigColors::UnitigColors_const_iterator::UnitigColors_const_iterator(const UnitigColors_const_iterator& o) : cs(o.cs), flag(o.flag), |
| 1390 | it_setBits(o.it_setBits), cs_sz(o.cs_sz), um_sz(o.um_sz), |
| 1391 | ck_id(o.ck_id), start_pos(o.start_pos), end_pos(o.end_pos), |
| 1392 | it_uc(nullptr), it_roar(o.it_roar), it_t_bmp(o.it_t_bmp) { |
| 1393 | |
| 1394 | if (flag == localTinyBitmap){ |
| 1395 | |
| 1396 | uint16_t* setPtrTinyBmp = cs->getPtrTinyBitmap(); |
| 1397 | t_bmp = &setPtrTinyBmp; |
| 1398 | } |
| 1399 | else if (flag == ptrUnitigColors){ |
| 1400 | |
| 1401 | it_uc = new UnitigColors_const_iterator[2]; |
| 1402 | |
| 1403 | it_uc[0] = o.it_uc[0]; |
| 1404 | it_uc[1] = o.it_uc[1]; |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | UnitigColors::UnitigColors_const_iterator::~UnitigColors_const_iterator() { |
| 1409 | |
| 1410 | t_bmp.detach(); |
| 1411 | |
| 1412 | if (it_uc != nullptr) delete[] it_uc; |
| 1413 | } |
| 1414 | |
| 1415 | UnitigColors::UnitigColors_const_iterator& UnitigColors::UnitigColors_const_iterator::operator=(const UnitigColors_const_iterator& o) { |
| 1416 | |
| 1417 | cs = o.cs; |
| 1418 | |
| 1419 | flag = o.flag; |
| 1420 | |
| 1421 | it_setBits = o.it_setBits; |
| 1422 | cs_sz = o.cs_sz; |
| 1423 | um_sz = o.um_sz; |
| 1424 | |
| 1425 | ck_id = o.ck_id; |
| 1426 | |
| 1427 | start_pos = o.start_pos; |
| 1428 | end_pos = o.end_pos; |
| 1429 | |
| 1430 | it_roar = o.it_roar; |
| 1431 | it_t_bmp = o.it_t_bmp; |
| 1432 | |
| 1433 | it_uc = nullptr; |
| 1434 | |
| 1435 | if (flag == localTinyBitmap){ |
| 1436 | |
| 1437 | t_bmp.detach(); |
| 1438 | |
| 1439 | uint16_t* setPtrTinyBmp = cs->getPtrTinyBitmap(); |
| 1440 | t_bmp = &setPtrTinyBmp; |
| 1441 | } |
| 1442 | else if (flag == ptrUnitigColors){ |
| 1443 | |
| 1444 | it_uc = new UnitigColors_const_iterator[2]; |
| 1445 | |
| 1446 | it_uc[0] = o.it_uc[0]; |
| 1447 | it_uc[1] = o.it_uc[1]; |
| 1448 | } |
| 1449 | |
| 1450 | return *this; |
| 1451 | } |
| 1452 | |
| 1453 | UnitigColors::UnitigColors_const_iterator UnitigColors::UnitigColors_const_iterator::operator++(int) { |
| 1454 | |
| 1455 | UnitigColors_const_iterator tmp(*this); |
| 1456 | operator++(); |
| 1457 | return tmp; |
| 1458 | } |
| 1459 | |
| 1460 | UnitigColors::UnitigColors_const_iterator& UnitigColors::UnitigColors_const_iterator::operator++() { |
| 1461 | |
| 1462 | bool first_round = true; |
| 1463 | |
| 1464 | while ((it_setBits != cs_sz) && (first_round || (getKmerPosition() < start_pos) || (getKmerPosition() >= end_pos))){ |
| 1465 | |
| 1466 | ++it_setBits; |
| 1467 | |
| 1468 | if (flag == ptrUnitigColors) { |
| 1469 | |
| 1470 | if (it_setBits != 0){ // Must increment one iterator |
| 1471 | |
| 1472 | if (!it_uc[0].isInvalid() && (getColorID() == it_uc[0].getColorID())){ // We were iterating over a full color |
| 1473 | |
| 1474 | ++ck_id; |
| 1475 | |
| 1476 | if (getKmerPosition() == 0) ++it_uc[0]; // If the next k-mer position is past the last |
| 1477 | else { |
| 1478 | |
| 1479 | --it_setBits; |
| 1480 | first_round = false; |
| 1481 | |
| 1482 | continue; |
| 1483 | } |
| 1484 | } |
| 1485 | else if (!it_uc[1].isInvalid()) ++it_uc[1]; |
| 1486 | } |
| 1487 | |
| 1488 | if (it_uc[0].isInvalid()) ck_id = it_uc[1].ck_id; // If first iterator finished, consider second iterator |
| 1489 | else if (it_uc[1].isInvalid() || (it_uc[0].getColorID() < it_uc[1].getColorID())){ |
| 1490 | |
| 1491 | ck_id = it_uc[0].getColorID() * um_sz; |
| 1492 | } |
| 1493 | else ck_id = it_uc[1].ck_id; |
| 1494 | } |
| 1495 | else if (flag == ptrBitmap) { |
| 1496 | |
| 1497 | if (it_setBits != 0) ++it_roar; |
| 1498 | if (it_roar != cs->getConstPtrBitmap()->r.end()) ck_id = *it_roar; |
| 1499 | } |
| 1500 | else if (flag == localTinyBitmap) { |
| 1501 | |
| 1502 | if (it_setBits != 0) ++it_t_bmp; |
| 1503 | if (it_t_bmp != t_bmp.end()) ck_id = *it_t_bmp; |
| 1504 | } |
| 1505 | else if (flag == localBitVector){ |
| 1506 | |
| 1507 | while (it_setBits < maxBitVectorIDs){ |
| 1508 | |
| 1509 | if (((cs->setBits >> (it_setBits + shiftMaskBits)) & 0x1) != 0){ |
| 1510 | |
| 1511 | ck_id = it_setBits; |
| 1512 | break; |
| 1513 | } |
| 1514 | |
| 1515 | ++it_setBits; |
| 1516 | } |
| 1517 | } |
| 1518 | else ck_id = cs->setBits >> shiftMaskBits; |
| 1519 | |
| 1520 | first_round = false; |
| 1521 | } |
| 1522 | |
| 1523 | return *this; |
| 1524 | } |
| 1525 | |
| 1526 | UnitigColors::UnitigColors_const_iterator& UnitigColors::UnitigColors_const_iterator::nextColor() { |
| 1527 | |
| 1528 | bool first_round = true; |
| 1529 | |
| 1530 | while ((it_setBits != cs_sz) && (first_round || (getKmerPosition() < start_pos) || (getKmerPosition() >= end_pos))){ |
| 1531 | |
| 1532 | const size_t nextColor = getColorID() + 1; |
| 1533 | const size_t nextPos = nextColor * um_sz + start_pos; |
| 1534 | |
| 1535 | if (flag == ptrUnitigColors) { |
| 1536 | |
| 1537 | while (!it_uc[0].isInvalid() && (it_uc[0].ck_id < nextColor)) ++it_uc[0]; |
| 1538 | while (!it_uc[1].isInvalid() && (it_uc[1].ck_id < nextPos)) it_uc[1].nextColor(); |
| 1539 | |
| 1540 | if (it_uc[0].isInvalid() && it_uc[1].isInvalid()) it_setBits = cs_sz; |
| 1541 | else if (it_uc[0].isInvalid()) ck_id = it_uc[1].ck_id; |
| 1542 | else if (it_uc[1].isInvalid() || (it_uc[0].getColorID() < it_uc[1].getColorID())) ck_id = it_uc[0].getColorID() * um_sz; |
| 1543 | else ck_id = it_uc[1].ck_id; |
| 1544 | } |
| 1545 | else if (flag == ptrBitmap) { |
| 1546 | |
| 1547 | while ((it_roar != cs->getConstPtrBitmap()->r.end()) && (*it_roar < nextPos)) ++it_roar; |
| 1548 | |
| 1549 | if (it_roar != cs->getConstPtrBitmap()->r.end()) ck_id = *it_roar; |
| 1550 | else it_setBits = cs_sz; |
| 1551 | } |
| 1552 | else if (flag == localTinyBitmap) { |
| 1553 | |
| 1554 | while ((it_t_bmp != t_bmp.end()) && (*it_t_bmp < nextPos)) ++it_t_bmp; |
| 1555 | |
| 1556 | if (it_t_bmp != t_bmp.end()) ck_id = *it_t_bmp; |
| 1557 | else it_setBits = cs_sz; |
| 1558 | } |
| 1559 | else if (flag == localBitVector){ |
| 1560 | |
| 1561 | it_setBits = min(maxBitVectorIDs, nextPos); |
| 1562 | |
| 1563 | while (it_setBits < maxBitVectorIDs){ |
| 1564 | |
| 1565 | if ((cs->setBits >> (it_setBits + shiftMaskBits)) & 0x1){ |
| 1566 | |
| 1567 | ck_id = it_setBits; |
| 1568 | break; |
| 1569 | } |
| 1570 | |
| 1571 | ++it_setBits; |
| 1572 | } |
| 1573 | } |
| 1574 | else ++it_setBits; |
| 1575 | |
| 1576 | first_round = false; |
| 1577 | } |
| 1578 | |
| 1579 | return *this; |
| 1580 | } |
| 1581 | |
| 1582 | bool UnitigColors::UnitigColors_const_iterator::operator==(const UnitigColors_const_iterator& o) const { |
| 1583 | |
| 1584 | if ((cs == o.cs) && (flag == o.flag) && (cs_sz == o.cs_sz)){ |
| 1585 | |
| 1586 | if (flag == ptrUnitigColors) return (it_uc[0] == o.it_uc[0]) && (it_uc[1] == o.it_uc[1]); |
| 1587 | if (flag == ptrBitmap) return (it_roar == o.it_roar); |
| 1588 | if (flag == localTinyBitmap) return (it_t_bmp == o.it_t_bmp); |
| 1589 | |
| 1590 | return (it_setBits == o.it_setBits); |
| 1591 | } |
| 1592 | |
| 1593 | return false; |
| 1594 | } |
| 1595 | |
| 1596 | bool UnitigColors::UnitigColors_const_iterator::operator!=(const UnitigColors_const_iterator& o) const { |
| 1597 | |
| 1598 | return !operator==(o); |
| 1599 | } |
| 1600 | |
| 1601 | const size_t UnitigColors::maxBitVectorIDs = 61; // 64 bits - 3 bits for the color set type |
| 1602 | |
| 1603 | const uintptr_t UnitigColors::localTinyBitmap = 0x0; |
| 1604 | const uintptr_t UnitigColors::localBitVector = 0x1; |
| 1605 | const uintptr_t UnitigColors::localSingleInt = 0x2; |
| 1606 | const uintptr_t UnitigColors::ptrBitmap = 0x3; |
| 1607 | const uintptr_t UnitigColors::ptrUnitigColors = 0x4; |
| 1608 | const uintptr_t UnitigColors::ptrSharedUnitigColors = 0x5; // Flag 5 |
| 1609 | |
| 1610 | const size_t UnitigColors::shiftMaskBits = 3; |
| 1611 | |
| 1612 | const uintptr_t UnitigColors::flagMask = 0x7; |
| 1613 | const uintptr_t UnitigColors::pointerMask = 0xFFFFFFFFFFFFFFF8; |