-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcircbuf.hpp
49 lines (36 loc) · 1.03 KB
/
circbuf.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef CIRCBUF_GUARD
#define CIRCBUF_GUARD
#include <cstdint>
#include <cstdlib>
/*
x[pos % 1000] = 64 bit int
gpos (32 bits) [could be 28 bits for humans -- log2(chr1 length) = 27.9]
event (8 bits)
16 [18] bits for alt and refcounts
Implement with failure on collision (if buffer is big enough, this should never happen)
If we wanted to get fancy, we could make it decay to a pointer to a linked list for resolution
*/
namespace walker {
// TODO: make these all operators. make virtual where useful.
// collision checking?
template<class T = uint64_t, uint8_t POW = 10>
class static_circbuf {
public:
T& at(uint64_t pos) {
return buffer[pos & mask];
}
void insert(uint64_t pos, T val) {
buffer[pos & mask] = val;
}
void erase(uint64_t pos) {
buffer[pos & mask] = T();
}
static_circbuf() : buffer() {}
//virtual bool equals(uint64_t pos, T val); // TODO: make this an operator
protected:
uint64_t size {1 << POW};
uint64_t mask {(1 << POW) - 1};
T buffer[1 << POW];
};
}
#endif