Idezni csak pontosan, szepen, ahogy a csiga...
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]++);
58 // FIXME: range check ide?
60 half_swap(a, --bounds[m]);
64 base.set(orig_key, a);
73 IterableMap(KeyIntMap &_base, Val d = N+1) : base(_base), def_val(d) {
74 memset(bounds, 0, sizeof(bounds));
75 // for(int i=0; i<N; ++i) { bounds[i]=0; }
78 Val operator[](const KeyType& k) const {
82 void set(const KeyType& k, Val n) {
83 // FIXME: range check?
86 base.set(k, move(a, find(a), n));
93 void insert(const KeyType& k, Val n) {
95 base.set(k, move(bounds[N-1]++, N-1, n));
98 iterator begin(Val n) const {
99 return data.begin() + (n ? bounds[n-1] : 0);
102 iterator end(Val n) const {
103 return data.begin() + bounds[n];
106 size_t size(Val n) const {
107 return bounds[n] - (n ? bounds[n-1] : 0);
110 size_t size() const {
111 // assert(bounds[N-1] == data.size());
120 template<typename KeyIntMap>
121 class IterableBoolMap : public IterableMap<KeyIntMap, 2, bool> {
122 typedef IterableMap<KeyIntMap, 2, bool> Parent;
125 IterableBoolMap(KeyIntMap &_base, bool d = false) : Parent(_base, d) {}