Data structure with fast contiguous ranges retrieval
Imagine data structure, that manipulates some contiguous container, and
allows quick retrieval of contiguous ranges of indices, within this array,
that contains data (and probably free ranges too). Let's call this ranges
"blocks". Each block knows its head and tail index:
struct Block
{
size_t begin;
size_t end;
}
When we manipulating array, our data structure updates blocks:
array view blocks [begin, end]
--------------------------------------------------------------
0 1 2 3 4 5 6 7 8 9 [0, 9]
pop 2 block 1 splitted
0 1 _ 3 4 5 6 7 8 9 [0, 1] [3, 9]
pop 7, 8 block 2 splitted
0 1 _ 3 4 5 6 _ _ 9 [0, 1] [3, 6] [9, 9]
push 7 changed end of block 3
0 1 _ 3 4 5 6 7 _ 9 [0, 1] [3, 7] [9, 9]
push 5 error: already in
0 1 _ 3 4 5 6 7 _ 9 [0, 1] [3, 7] [9, 9]
push 2 blocks 1, 2 merged
0 1 2 3 4 5 6 7 _ 9 [0, 7] [9, 9]
Even before profiling, we know that blocks retrieval speed will be
cornerstone of application performance. Basically usage is: - very often
retrieval of contiguous blocks - quite often write - quite rare
insertions/deletions
What we have already tried:
std::vector<bool> + std::list<Block*>. On every change: write true/false
to vector, then traverse it in for loop and re-generate list. On every
query of blocks return list. Slower than we wanted.
std::list<Block*> update list directly, so no traversing. Return list.
Much code to debug/test.
Questions:
Is that data structure has some generic name?
Is there already such data structures implemented (debugged and tested)?
If no, what can you advice on fast and robust implementation of such data
structure?
Sorry if my explanation is not quite clear.
No comments:
Post a Comment