Remove function and some todos.
authorklao
Wed, 21 Apr 2004 19:52:09 +0000
changeset 367825647d4eca7
parent 366 be6fe0ea99b5
child 368 0beed7a49063
Remove function and some todos.
src/work/klao/iter_map.h
src/work/klao/iter_map_test.cc
     1.1 --- a/src/work/klao/iter_map.h	Wed Apr 21 19:10:59 2004 +0000
     1.2 +++ b/src/work/klao/iter_map.h	Wed Apr 21 19:52:09 2004 +0000
     1.3 @@ -14,9 +14,13 @@
     1.4  
     1.5  namespace hugo {
     1.6  
     1.7 +  /// \brief A map with "small integers" as value set which can enumarate it
     1.8 +  /// value classes
     1.9  
    1.10    /// \todo Decide whether we need all the range checkings!!!
    1.11  
    1.12 +  /// \todo Implement dynamic map behaviour. Is it necessary? Yes it is.
    1.13 +
    1.14    template<typename KeyIntMap, uint8_t N, typename Val = uint8_t>
    1.15    class IterableMap {
    1.16    public:
    1.17 @@ -84,7 +88,7 @@
    1.18        // FIXME: range check?
    1.19        size_t a = base[k];
    1.20        if(a < bounds[N-1]) {
    1.21 -	base.set(k, move(a, find(a), n));
    1.22 +	move(a, find(a), n);
    1.23        }
    1.24        else {
    1.25  	insert(k, n);
    1.26 @@ -96,6 +100,17 @@
    1.27        base.set(k, move(bounds[N-1]++, N-1, n));
    1.28      }
    1.29  
    1.30 +    /// This func is not very usable, but necessary to implement 
    1.31 +    /// dynamic map behaviour.
    1.32 +    void remove(const KeyType& k) {
    1.33 +      size_t a = base[k];
    1.34 +      if(a < bounds[N-1]) {
    1.35 +	move(a, find(a), N);
    1.36 +	data.pop_back();
    1.37 +	base.set(k, -1);
    1.38 +      }
    1.39 +    }
    1.40 +
    1.41      iterator begin(Val n) const {
    1.42        return data.begin() + (n ? bounds[n-1] : 0);
    1.43      }
     2.1 --- a/src/work/klao/iter_map_test.cc	Wed Apr 21 19:10:59 2004 +0000
     2.2 +++ b/src/work/klao/iter_map_test.cc	Wed Apr 21 19:52:09 2004 +0000
     2.3 @@ -225,5 +225,9 @@
     2.4        cout << " " << a;
     2.5      }
     2.6      cout << endl;
     2.7 +
     2.8 +    cout << "Removing 10 from the map...\n";
     2.9 +    test.remove(10);
    2.10 +    print(test,2);
    2.11    }
    2.12  }