77 Val operator[](const KeyType& k) const { |
78 Val operator[](const KeyType& k) const { |
78 return find(base[k]); |
79 return find(base[k]); |
79 } |
80 } |
80 |
81 |
81 void set(const KeyType& k, Val n) { |
82 void set(const KeyType& k, Val n) { |
82 // FIXME: n < N ??? |
83 // FIXME: range check? |
83 size_t a = base[k]; |
84 size_t a = base[k]; |
84 if(a < bounds[N-1] && n < N) { |
85 if(a < bounds[N-1]) { |
85 base.set(k, move(a, find(a), n)); |
86 base.set(k, move(a, find(a), n)); |
|
87 } |
|
88 else { |
|
89 insert(k, n); |
86 } |
90 } |
87 } |
91 } |
88 |
92 |
89 void insert(const KeyType& k, Val n) { |
93 void insert(const KeyType& k, Val n) { |
90 if(n < N) { |
94 data.push_back(k); |
91 data.push_back(k); |
95 base.set(k, move(bounds[N-1]++, N-1, n)); |
92 base.set(k, move(bounds[N-1]++, N-1, n)); |
|
93 } |
|
94 } |
96 } |
95 |
97 |
96 iterator begin(Val n) const { |
98 iterator begin(Val n) const { |
97 if(n < N) |
99 return data.begin() + (n ? bounds[n-1] : 0); |
98 return data.begin() + (n ? bounds[n-1] : 0); |
|
99 else |
|
100 return data.end(); |
|
101 } |
100 } |
102 |
101 |
103 iterator end(Val n) const { |
102 iterator end(Val n) const { |
104 if(n < N) |
103 return data.begin() + bounds[n]; |
105 return data.begin() + bounds[n]; |
|
106 else |
|
107 return data.end(); |
|
108 } |
104 } |
109 |
105 |
110 size_t size(Val n) const { |
106 size_t size(Val n) const { |
111 if(n < N) |
107 return bounds[n] - (n ? bounds[n-1] : 0); |
112 return bounds[n] - (n ? bounds[n-1] : 0); |
|
113 else |
|
114 return 0; |
|
115 } |
108 } |
116 |
109 |
117 size_t size() const { |
110 size_t size() const { |
118 // assert(bounds[N-1] == data.size()); |
111 // assert(bounds[N-1] == data.size()); |
119 return bounds[N-1]; |
112 return bounds[N-1]; |