// -*- c++ -*- // #ifndef LEMON_ITER_MAP #define LEMON_ITER_MAP #include #include // for uint8_t #include // for memset #include #include namespace lemon { /// \brief A map with "small integers" as value set which can enumarate it /// value classes /// \todo Decide whether we need all the range checkings!!! /// \todo Implement dynamic map behaviour. Is it necessary? Yes it is. template class IterableMap { public: typedef typename KeyIntMap::KeyType KeyType; typedef Val ValueType; typedef typename std::vector::const_iterator iterator; protected: KeyIntMap &base; std::vector data; size_t bounds[N]; Val def_val; Val find(size_t a) const { for(uint8_t n=0; n a) return n; } return def_val; } void half_swap(size_t &a, size_t b) { if(a != b) { base.set(data[b],a); data[a] = data[b]; a = b; } } size_t move(size_t a, uint8_t m, uint8_t n) { if(m != n) { size_t orig_a = a; KeyType orig_key = data[a]; while(m > n) { --m; half_swap(a, bounds[m]++); } // FIXME: range check ide? while(m < n) { half_swap(a, --bounds[m]); ++m; } if(a != orig_a) { base.set(orig_key, a); data[a]=orig_key; } } return a; } public: 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