18 #include "IndexBase.h"
21 Chunk SortedChunkList::pop()
23 Chunk newChunk = chunkList.begin()->second;
24 chunkList.erase(chunkList.begin());
29 bool SortedChunkList::insert(
const Chunk& chunkToInsert)
31 std::pair<std::map<uint64_t, Chunk>::iterator,
bool> insertRes;
34 chunkList.insert(std::pair<uint64_t, Chunk>(chunkToInsert.chunk_beg,
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
44 << insertRes.first->second.chunk_end
45 <<
"\nnew chunk:\tbeg = " << std::hex
46 << chunkToInsert.chunk_beg
48 << chunkToInsert.chunk_end
52 return(insertRes.second);
55 void SortedChunkList::clear()
60 bool SortedChunkList::empty()
62 return(chunkList.empty());
67 bool SortedChunkList::mergeOverlapping()
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())
78 while(nextPos != chunkList.end())
83 if(nextPos->second.chunk_end < currentPos->second.chunk_end)
85 chunkList.erase(nextPos);
94 if((nextPos->second.chunk_beg >> 16) <=
95 (currentPos->second.chunk_end >> 16))
97 currentPos->second.chunk_end = nextPos->second.chunk_end;
100 chunkList.erase(nextPos);
101 nextPos = currentPos;
108 currentPos = nextPos;
116 IndexBase::IndexBase()
124 IndexBase::~IndexBase()
142 return(myRefs.size());
148 void IndexBase::getBinsForRegion(uint32_t start, uint32_t end,
bool binMap[MAX_NUM_BINS+1])
150 for(uint32_t index = 0; index < MAX_NUM_BINS+1; index++)
152 binMap[index] =
false;
159 if(start > MAX_POSITION)
161 start = MAX_POSITION;
163 if(end > MAX_POSITION)
169 binMap[binNum] =
true;
170 for (binNum = 1 + (start>>26); binNum <= 1 + (end>>26); ++binNum)
171 binMap[binNum] =
true;
172 for (binNum = 9 + (start>>23); binNum <= 9 + (end>>23); ++binNum)
173 binMap[binNum] =
true;
174 for (binNum = 73 + (start>>20); binNum <= 73 + (end>>20); ++binNum)
175 binMap[binNum] =
true;
176 for (binNum = 585 + (start>>17); binNum <= 585 + (end>>17); ++binNum)
177 binMap[binNum] =
true;
178 for (binNum = 4681 + (start>>14); binNum <= 4681 + (end>>14); ++binNum)
179 binMap[binNum] =
true;
185 bool IndexBase::getMinOffsetFromLinearIndex(int32_t refID, uint32_t position,
186 uint64_t& minOffset)
const
188 int32_t linearIndex = position >> LINEAR_INDEX_SHIFT;
198 int32_t linearOffsetSize = myRefs[refID].n_intv;
204 if((linearOffsetSize == 0) || (linearIndex >= linearOffsetSize))
211 minOffset = myRefs[refID].ioffsets[linearIndex];
219 while((minOffset == 0) && (--linearIndex >= 0))
221 minOffset = myRefs[refID].ioffsets[linearIndex];
230 while((minOffset == 0) && (linearIndex < linearOffsetSize))
232 minOffset = myRefs[refID].ioffsets[linearIndex];