libStatGen Software 1
Loading...
Searching...
No Matches
SortedChunkList Class Reference

Public Member Functions

Chunk pop ()
 
bool insert (const Chunk &chunkToInsert)
 
void clear ()
 
bool empty ()
 
bool mergeOverlapping ()
 

Detailed Description

Definition at line 48 of file IndexBase.h.

Member Function Documentation

◆ clear()

void SortedChunkList::clear ( )

Definition at line 55 of file IndexBase.cpp.

56{
57 chunkList.clear();
58}

◆ empty()

bool SortedChunkList::empty ( )

Definition at line 60 of file IndexBase.cpp.

61{
62 return(chunkList.empty());
63}

◆ insert()

bool SortedChunkList::insert ( const Chunk chunkToInsert)

Definition at line 29 of file IndexBase.cpp.

30{
31 std::pair<std::map<uint64_t, Chunk>::iterator, bool> insertRes;
32 // Insert the passed in chunk.
33 insertRes =
34 chunkList.insert(std::pair<uint64_t, Chunk>(chunkToInsert.chunk_beg,
35 chunkToInsert));
36
37 if(!insertRes.second)
38 {
39 // Failed to insert the chunk.
40 std::cerr << "Failed to insert into the SortedChunkList.\n";
41 std::cerr << "\tpreviously found chunk:\tbeg = " << std::hex
42 << insertRes.first->second.chunk_beg
43 << "\tend = "
44 << insertRes.first->second.chunk_end
45 << "\nnew chunk:\tbeg = " << std::hex
46 << chunkToInsert.chunk_beg
47 << "\tend = "
48 << chunkToInsert.chunk_end
49 << std::endl;
50 }
51 // return the result that comes from insertRes.
52 return(insertRes.second);
53}

◆ mergeOverlapping()

bool SortedChunkList::mergeOverlapping ( )

Definition at line 67 of file IndexBase.cpp.

68{
69 // Start at the beginning of the list and iterate through.
70 std::map<uint64_t, Chunk>::iterator currentPos = chunkList.begin();
71 std::map<uint64_t, Chunk>::iterator nextPos = chunkList.begin();
72 if(nextPos != chunkList.end())
73 {
74 ++nextPos;
75 }
76
77 // Loop until the end is reached.
78 while(nextPos != chunkList.end())
79 {
80 // If the next chunk is completely contained within the current
81 // chunk (its end is less than the current chunk's end),
82 // delete it since its position is already covered.
83 if(nextPos->second.chunk_end < currentPos->second.chunk_end)
84 {
85 chunkList.erase(nextPos);
86 nextPos = currentPos;
87 ++nextPos;
88 continue;
89 }
90
91 // If the next chunk's start position's BGZF block is less than or
92 // equal to the BGZF block of the current chunk's end position,
93 // combine the two chunks into the current chunk.
94 if((nextPos->second.chunk_beg >> 16) <=
95 (currentPos->second.chunk_end >> 16))
96 {
97 currentPos->second.chunk_end = nextPos->second.chunk_end;
98 // nextPos has now been included in the current pos, so
99 // remove it.
100 chunkList.erase(nextPos);
101 nextPos = currentPos;
102 ++nextPos;
103 continue;
104 }
105 else
106 {
107 // Nothing to combine. So try combining at the next
108 currentPos = nextPos;
109 ++nextPos;
110 }
111 }
112 return(true);
113}

◆ pop()

Chunk SortedChunkList::pop ( )

Definition at line 21 of file IndexBase.cpp.

22{
23 Chunk newChunk = chunkList.begin()->second;
24 chunkList.erase(chunkList.begin());
25 return(newChunk);
26}

The documentation for this class was generated from the following files: