IterableMap: no range checking, no warning :)
authorklao
Wed, 21 Apr 2004 16:09:42 +0000
changeset 3626c2e8a1f380a
parent 361 ab0899df30d2
child 363 7a05119c121a
IterableMap: no range checking, no warning :)
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 15:46:40 2004 +0000
     1.2 +++ b/src/work/klao/iter_map.h	Wed Apr 21 16:09:42 2004 +0000
     1.3 @@ -55,6 +55,7 @@
     1.4  	  --m;
     1.5  	  half_swap(a, bounds[m]++);
     1.6  	}
     1.7 +	// FIXME: range check ide?
     1.8  	while(m < n) {
     1.9  	  half_swap(a, --bounds[m]);
    1.10  	  ++m;
    1.11 @@ -79,39 +80,31 @@
    1.12      }
    1.13  
    1.14      void set(const KeyType& k, Val n) {
    1.15 -      // FIXME: n < N ???
    1.16 +      // FIXME: range check?
    1.17        size_t a = base[k];
    1.18 -      if(a < bounds[N-1] && n < N) {
    1.19 +      if(a < bounds[N-1]) {
    1.20  	base.set(k, move(a, find(a), n));
    1.21        }
    1.22 +      else {
    1.23 +	insert(k, n);
    1.24 +      }
    1.25      }
    1.26  
    1.27      void insert(const KeyType& k, Val n) {
    1.28 -      if(n < N) {
    1.29 -	data.push_back(k);
    1.30 -	base.set(k, move(bounds[N-1]++, N-1, n));
    1.31 -      }
    1.32 +      data.push_back(k);
    1.33 +      base.set(k, move(bounds[N-1]++, N-1, n));
    1.34      }
    1.35  
    1.36      iterator begin(Val n) const {
    1.37 -      if(n < N)
    1.38 -	return data.begin() + (n ? bounds[n-1] : 0);
    1.39 -      else
    1.40 -	return data.end();
    1.41 +      return data.begin() + (n ? bounds[n-1] : 0);
    1.42      }
    1.43  
    1.44      iterator end(Val n) const {
    1.45 -      if(n < N)
    1.46 -	return data.begin() + bounds[n];
    1.47 -      else
    1.48 -	return data.end();
    1.49 +      return data.begin() + bounds[n];
    1.50      }
    1.51  
    1.52      size_t size(Val n) const {
    1.53 -      if(n < N)
    1.54 -	return bounds[n] - (n ? bounds[n-1] : 0);
    1.55 -      else
    1.56 -	return 0;
    1.57 +      return bounds[n] - (n ? bounds[n-1] : 0);
    1.58      }
    1.59      
    1.60      size_t size() const {
     2.1 --- a/src/work/klao/iter_map_test.cc	Wed Apr 21 15:46:40 2004 +0000
     2.2 +++ b/src/work/klao/iter_map_test.cc	Wed Apr 21 16:09:42 2004 +0000
     2.3 @@ -119,10 +119,10 @@
     2.4    }
     2.5  
     2.6    {
     2.7 -    cout << "Testing the IterableBoolMap...\n";
     2.8 +    cout << "\n\n\nTesting the IterableBoolMap...\n";
     2.9  
    2.10      BaseMap base(344);
    2.11 -    TestBoolMap test(base);
    2.12 +    TestBoolMap test(base,true);
    2.13  
    2.14  
    2.15      print(test,2);
    2.16 @@ -157,54 +157,27 @@
    2.17      cout << " 11: " << test[11] << endl;
    2.18      cout << " 42: " << test[42] << endl;
    2.19  
    2.20 -    cout << "Inserting 21 to class 1...\n";
    2.21 -    test.insert(21,1);
    2.22 -    print(test,2);
    2.23 -
    2.24 -    cout << "Inserting 20 to class 1...\n";
    2.25 -    test.insert(20,0);
    2.26 -    print(test,2);
    2.27 -
    2.28 -    cout << "Testing some map values:\n";
    2.29 -    cout << " 12: " << test[12] << endl;
    2.30 -    cout << " 22: " << test[22] << endl;
    2.31 -    cout << " 10: " << test[10] << endl;
    2.32 -    cout << " 20: " << test[20] << endl;
    2.33 -    cout << " 11: " << test[11] << endl;
    2.34 -    cout << " 21: " << test[21] << endl;
    2.35 -    cout << " 42: " << test[42] << endl;
    2.36 -
    2.37 -    cout << "Setting 20 to class 2...\n";
    2.38 -    test.set(20,2);
    2.39 +    cout << "Setting 10 to class true...\n";
    2.40 +    test.set(10,true);
    2.41      print(test,2);
    2.42    
    2.43 -    cout << "Setting 10 to class 1...\n";
    2.44 -    test.set(10,1);
    2.45 -    print(test,2);
    2.46 -  
    2.47 -    cout << "Setting 11 to class 1...\n";
    2.48 +    cout << "Setting 11 to class true...\n";
    2.49      test.set(11,1);
    2.50      print(test,2);
    2.51    
    2.52 -    cout << "Setting 12 to class 1...\n";
    2.53 -    test.set(12,1);
    2.54 +    cout << "Setting 12 to class false...\n";
    2.55 +    test.set(12,false);
    2.56      print(test,2);
    2.57    
    2.58 -    cout << "Setting 21 to class 2...\n";
    2.59 -    test.set(21,2);
    2.60 -    print(test,2);
    2.61 -  
    2.62 -    cout << "Setting 22 to class 2...\n";
    2.63 -    test.set(22,2);
    2.64 +    cout << "Setting 22 to class false...\n";
    2.65 +    test.set(22,false);
    2.66      print(test,2);
    2.67    
    2.68      cout << "Testing some map values:\n";
    2.69      cout << " 12: " << test[12] << endl;
    2.70      cout << " 22: " << test[22] << endl;
    2.71      cout << " 10: " << test[10] << endl;
    2.72 -    cout << " 20: " << test[20] << endl;
    2.73      cout << " 11: " << test[11] << endl;
    2.74 -    cout << " 21: " << test[21] << endl;
    2.75      cout << " 42: " << test[42] << endl;
    2.76  
    2.77    }