IterableMap with template ValueType. IterableBoolMap as a specialization.
Range checking warnings...
17 /// \todo Decide whether we need all the range checkings!!!
19 template<typename KeyIntMap, uint8_t N, typename Val = uint8_t>
23 typedef typename KeyIntMap::KeyType KeyType;
24 typedef Val ValueType;
26 typedef typename std::vector<KeyType>::const_iterator iterator;
30 std::vector<KeyType> data;
34 Val find(size_t a) const {
35 for(uint8_t n=0; n<N; ++n) {
42 void half_swap(size_t &a, size_t b) {
50 size_t move(size_t a, uint8_t m, uint8_t n) {
53 KeyType orig_key = data[a];
56 half_swap(a, bounds[m]++);
59 half_swap(a, --bounds[m]);
63 base.set(orig_key, a);
72 IterableMap(KeyIntMap &_base, Val d = N+1) : base(_base), def_val(d) {
73 memset(bounds, 0, sizeof(bounds));
74 // for(int i=0; i<N; ++i) { bounds[i]=0; }
77 Val operator[](const KeyType& k) const {
81 void set(const KeyType& k, Val n) {
84 if(a < bounds[N-1] && n < N) {
85 base.set(k, move(a, find(a), n));
89 void insert(const KeyType& k, Val n) {
92 base.set(k, move(bounds[N-1]++, N-1, n));
96 iterator begin(Val n) const {
98 return data.begin() + (n ? bounds[n-1] : 0);
103 iterator end(Val n) const {
105 return data.begin() + bounds[n];
110 size_t size(Val n) const {
112 return bounds[n] - (n ? bounds[n-1] : 0);
117 size_t size() const {
118 // assert(bounds[N-1] == data.size());
127 template<typename KeyIntMap>
128 class IterableBoolMap : public IterableMap<KeyIntMap, 2, bool> {
129 typedef IterableMap<KeyIntMap, 2, bool> Parent;
132 IterableBoolMap(KeyIntMap &_base, bool d = false) : Parent(_base, d) {}