# HG changeset patch # User klao # Date 1082562400 0 # Node ID ab0899df30d2968c4376cef296975dc1bbc10f0f # Parent 91fba31268d663ef9c657fc534277e149ae52ec3 IterableMap with template ValueType. IterableBoolMap as a specialization. Range checking warnings... diff -r 91fba31268d6 -r ab0899df30d2 src/work/klao/iter_map.h --- a/src/work/klao/iter_map.h Wed Apr 21 15:14:45 2004 +0000 +++ b/src/work/klao/iter_map.h Wed Apr 21 15:46:40 2004 +0000 @@ -16,12 +16,12 @@ /// \todo Decide whether we need all the range checkings!!! - template + template class IterableMap { public: typedef typename KeyIntMap::KeyType KeyType; - typedef uint8_t ValueType; + typedef Val ValueType; typedef typename std::vector::const_iterator iterator; @@ -29,11 +29,14 @@ KeyIntMap &base; std::vector data; size_t bounds[N]; + Val def_val; - uint8_t find(size_t a) const { - uint8_t n=0; - for(; n a) + return n; + } + return def_val; } void half_swap(size_t &a, size_t b) { @@ -66,44 +69,45 @@ public: - IterableMap(KeyIntMap &_base) : base(_base) { + IterableMap(KeyIntMap &_base, Val d = N+1) : base(_base), def_val(d) { memset(bounds, 0, sizeof(bounds)); // for(int i=0; i + class IterableBoolMap : public IterableMap { + typedef IterableMap Parent; + + public: + IterableBoolMap(KeyIntMap &_base, bool d = false) : Parent(_base, d) {} + }; + } #endif diff -r 91fba31268d6 -r ab0899df30d2 src/work/klao/iter_map_test.cc --- a/src/work/klao/iter_map_test.cc Wed Apr 21 15:14:45 2004 +0000 +++ b/src/work/klao/iter_map_test.cc Wed Apr 21 15:46:40 2004 +0000 @@ -10,14 +10,16 @@ typedef StdMap BaseMap; typedef IterableMap TestMap; +typedef IterableBoolMap TestBoolMap; -void print(TestMap const& m) { +template +void print(TM const& m, int N = 3) { cout << "Size of the map: " << m.size() << endl; for(int i=0; i