# HG changeset patch # User klao # Date 1082563782 0 # Node ID 6c2e8a1f380a91561691be5c27c4aab58f1632d2 # Parent ab0899df30d2968c4376cef296975dc1bbc10f0f IterableMap: no range checking, no warning :) diff -r ab0899df30d2 -r 6c2e8a1f380a src/work/klao/iter_map.h --- a/src/work/klao/iter_map.h Wed Apr 21 15:46:40 2004 +0000 +++ b/src/work/klao/iter_map.h Wed Apr 21 16:09:42 2004 +0000 @@ -55,6 +55,7 @@ --m; half_swap(a, bounds[m]++); } + // FIXME: range check ide? while(m < n) { half_swap(a, --bounds[m]); ++m; @@ -79,39 +80,31 @@ } void set(const KeyType& k, Val n) { - // FIXME: n < N ??? + // FIXME: range check? size_t a = base[k]; - if(a < bounds[N-1] && n < N) { + if(a < bounds[N-1]) { base.set(k, move(a, find(a), n)); } + else { + insert(k, n); + } } void insert(const KeyType& k, Val n) { - if(n < N) { - data.push_back(k); - base.set(k, move(bounds[N-1]++, N-1, n)); - } + data.push_back(k); + base.set(k, move(bounds[N-1]++, N-1, n)); } iterator begin(Val n) const { - if(n < N) - return data.begin() + (n ? bounds[n-1] : 0); - else - return data.end(); + return data.begin() + (n ? bounds[n-1] : 0); } iterator end(Val n) const { - if(n < N) - return data.begin() + bounds[n]; - else - return data.end(); + return data.begin() + bounds[n]; } size_t size(Val n) const { - if(n < N) - return bounds[n] - (n ? bounds[n-1] : 0); - else - return 0; + return bounds[n] - (n ? bounds[n-1] : 0); } size_t size() const { diff -r ab0899df30d2 -r 6c2e8a1f380a src/work/klao/iter_map_test.cc --- a/src/work/klao/iter_map_test.cc Wed Apr 21 15:46:40 2004 +0000 +++ b/src/work/klao/iter_map_test.cc Wed Apr 21 16:09:42 2004 +0000 @@ -119,10 +119,10 @@ } { - cout << "Testing the IterableBoolMap...\n"; + cout << "\n\n\nTesting the IterableBoolMap...\n"; BaseMap base(344); - TestBoolMap test(base); + TestBoolMap test(base,true); print(test,2); @@ -157,54 +157,27 @@ cout << " 11: " << test[11] << endl; cout << " 42: " << test[42] << endl; - cout << "Inserting 21 to class 1...\n"; - test.insert(21,1); - print(test,2); - - cout << "Inserting 20 to class 1...\n"; - test.insert(20,0); - print(test,2); - - cout << "Testing some map values:\n"; - cout << " 12: " << test[12] << endl; - cout << " 22: " << test[22] << endl; - cout << " 10: " << test[10] << endl; - cout << " 20: " << test[20] << endl; - cout << " 11: " << test[11] << endl; - cout << " 21: " << test[21] << endl; - cout << " 42: " << test[42] << endl; - - cout << "Setting 20 to class 2...\n"; - test.set(20,2); + cout << "Setting 10 to class true...\n"; + test.set(10,true); print(test,2); - cout << "Setting 10 to class 1...\n"; - test.set(10,1); - print(test,2); - - cout << "Setting 11 to class 1...\n"; + cout << "Setting 11 to class true...\n"; test.set(11,1); print(test,2); - cout << "Setting 12 to class 1...\n"; - test.set(12,1); + cout << "Setting 12 to class false...\n"; + test.set(12,false); print(test,2); - cout << "Setting 21 to class 2...\n"; - test.set(21,2); - print(test,2); - - cout << "Setting 22 to class 2...\n"; - test.set(22,2); + cout << "Setting 22 to class false...\n"; + test.set(22,false); print(test,2); cout << "Testing some map values:\n"; cout << " 12: " << test[12] << endl; cout << " 22: " << test[22] << endl; cout << " 10: " << test[10] << endl; - cout << " 20: " << test[20] << endl; cout << " 11: " << test[11] << endl; - cout << " 21: " << test[21] << endl; cout << " 42: " << test[42] << endl; }