7 #include "TinyBitmap.hpp" 24 struct alignas(8) Bitmap { Roaring r; };
32 typedef pair<UnitigColors, size_t> SharedUnitigColors;
75 return make_pair(ck_id % um_sz, ck_id / um_sz);
88 inline size_t getColorID()
const {
return ck_id / um_sz; }
139 const Roaring empty_roar;
144 Roaring::const_iterator it_roar;
145 TinyBitmap::const_iterator it_t_bmp;
148 const size_t len_unitig_km,
const bool beg);
150 inline uint64_t get_ID()
const {
return ck_id; }
152 inline bool isInvalid()
const {
154 return ((ck_id == 0xffffffffffffffff) || (it_setBits == cs_sz));
229 inline bool isEmpty()
const {
return (size() == 0); }
269 size_t size(
const UnitigMapBase& um,
const size_t color_id)
const;
284 bool write(ostream& stream_out,
const bool copy_UnitigColors =
true)
const;
292 bool read(istream& stream_in);
314 const_iterator
end()
const;
324 uint64_t hash(
const size_t seed = 0)
const;
333 void add(
const size_t color_id);
334 bool contains(
const size_t color_km_id)
const;
336 inline void releaseMemory(){
338 const uintptr_t flag = setBits & flagMask;
340 if (flag == ptrUnitigColors)
delete[] getPtrUnitigColors();
341 else if (flag == ptrBitmap)
delete getPtrBitmap();
342 else if (flag == ptrSharedUnitigColors){
344 SharedUnitigColors* s_uc = getPtrSharedUnitigColors();
346 if (--(s_uc->second) == 0) s_uc->first.clear();
348 else if (flag == localTinyBitmap){
350 uint16_t* setPtrTinyBmp = getPtrTinyBitmap();
351 TinyBitmap t_bmp(&setPtrTinyBmp);
356 setBits = localBitVector;
359 inline void shrinkSize(){
361 const uintptr_t flag = setBits & flagMask;
363 if (flag == ptrUnitigColors){
370 else if (flag == ptrBitmap) getPtrBitmap()->r.shrinkToFit();
371 else if (flag == localTinyBitmap){
373 uint16_t* setPtrTinyBmp = getPtrTinyBitmap();
374 TinyBitmap t_bmp(&setPtrTinyBmp);
378 setBits = (
reinterpret_cast<uintptr_t
>(t_bmp.detach()) & pointerMask) | localTinyBitmap;
388 return (isUnitigColors() ? getPtrUnitigColors() :
nullptr);
393 return (isUnitigColors() ? getPtrUnitigColors() :
nullptr);
396 inline bool isBitmap()
const {
return ((setBits & flagMask) == ptrBitmap); }
397 inline bool isTinyBitmap()
const {
return ((setBits & flagMask) == localTinyBitmap); }
398 inline bool isUnitigColors()
const {
return ((setBits & flagMask) == ptrUnitigColors); }
399 inline bool isSharedUnitigColors()
const {
return ((setBits & flagMask) == ptrSharedUnitigColors); }
405 const_iterator
begin(
const size_t start_pos,
const size_t end_pos,
const size_t len_km_sz)
const;
407 inline Bitmap* getPtrBitmap()
const {
409 return reinterpret_cast<Bitmap*
>(setBits & pointerMask);
412 inline const Bitmap* getConstPtrBitmap()
const {
414 return reinterpret_cast<const Bitmap*
>(setBits & pointerMask);
417 inline uint16_t* getPtrTinyBitmap()
const {
419 return reinterpret_cast<uint16_t*
>(setBits & pointerMask);
424 return reinterpret_cast<UnitigColors*
>(setBits & pointerMask);
427 inline const UnitigColors* getConstPtrUnitigColors()
const {
429 return reinterpret_cast<const UnitigColors*
>(setBits & pointerMask);
432 inline SharedUnitigColors* getPtrSharedUnitigColors()
const {
434 return reinterpret_cast<SharedUnitigColors*
>(setBits & pointerMask);
437 inline const SharedUnitigColors* getConstPtrSharedUnitigColors()
const {
439 return reinterpret_cast<const SharedUnitigColors*
>(setBits & pointerMask);
442 static const size_t maxBitVectorIDs;
443 static const size_t shiftMaskBits;
455 static const uintptr_t localTinyBitmap;
456 static const uintptr_t localBitVector;
457 static const uintptr_t localSingleInt;
458 static const uintptr_t ptrBitmap;
459 static const uintptr_t ptrUnitigColors;
460 static const uintptr_t ptrSharedUnitigColors;
462 static const uintptr_t flagMask;
463 static const uintptr_t pointerMask;
Definition: ColorSet.hpp:468
size_t colorMax(const UnitigMapBase &um) const
Get the largest color index of all k-mers of a reference unitig.
Represent the k-mer color sets of a unitig.
Definition: ColorSet.hpp:21
bool write(ostream &stream_out, const bool copy_UnitigColors=true) const
Write a UnitigColors to a stream.
bool contains(const UnitigMapBase &um, const size_t color_id) const
Check if a color is present on all k-mers of a unitig mapping.
size_t getKmerPosition() const
Get the k-mer position of the k-mer visited by the iterator.
Definition: ColorSet.hpp:82
size_t getColorID() const
Get the color of the k-mer visited by the iterator.
Definition: ColorSet.hpp:88
UnitigColors_const_iterator const_iterator
Iterator for the colors of a unitig.
Definition: ColorSet.hpp:164
Represent a Colored and Compacted de Bruijn graph.
Definition: ColoredCDBG.hpp:151
UnitigColors()
Constructor (set up an empty container of k-mer color sets).
Definition: ColorSet.hpp:16
bool read(istream &stream_in)
Read a UnitigColors from a stream.
~UnitigColors()
Destructor.
pair< size_t, size_t > operator*() const
Indirection operator.
Definition: ColorSet.hpp:73
Interface to access the colors and the data associated with a unitig of a ColoredCDBG.
Definition: ColorSet.hpp:15
size_t getSizeInBytes() const
Size of the UnitigColors in bytes.
void add(const UnitigMapBase &um, const size_t color_id)
Add a color in the current UnitigColors to all k-mers of a unitig mapping.
bool isEmpty() const
Check if a UnitigColors is empty (no colors).
Definition: ColorSet.hpp:229
const_iterator begin(const UnitigMapBase &um) const
Create a constant iterator on all pairs (k-mer position, color) of the UnitigColors.
Interface for the Compacted de Bruijn graph API.
void clear()
Empty a UnitigColors of its content.
See UnitigColors::const_iterator.
Definition: ColorSet.hpp:37
UnitigColors & operator=(const UnitigColors &o)
Copy assignment operator.
bool optimizeFullColors(const UnitigMapBase &um)
If possible, decrease the memory usage of the UnitigColors by optimizing the memory for "full colors"...
bool isEqual(const UnitigMapBase &um, const UnitigColors &o, const UnitigMapBase &um_o) const
Check if two UnitigColors are equal.
const_iterator end() const
Create a constant iterator to the "past-the-last" pair (k-mer position, color) of the UnitigColors...
Structure containing the basic information of a unitig mapping.
Definition: UnitigMap.hpp:33