COIN-OR::LEMON - Graph Library

Changeset 362:6c2e8a1f380a in lemon-0.x


Ignore:
Timestamp:
04/21/04 18:09:42 (20 years ago)
Author:
Mihaly Barasz
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@490
Message:

IterableMap?: no range checking, no warning :)

Location:
src/work/klao
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/work/klao/iter_map.h

    r361 r362  
    5656          half_swap(a, bounds[m]++);
    5757        }
     58        // FIXME: range check ide?
    5859        while(m < n) {
    5960          half_swap(a, --bounds[m]);
     
    8081
    8182    void set(const KeyType& k, Val n) {
    82       // FIXME: n < N ???
     83      // FIXME: range check?
    8384      size_t a = base[k];
    84       if(a < bounds[N-1] && n < N) {
     85      if(a < bounds[N-1]) {
    8586        base.set(k, move(a, find(a), n));
     87      }
     88      else {
     89        insert(k, n);
    8690      }
    8791    }
    8892
    8993    void insert(const KeyType& k, Val n) {
    90       if(n < N) {
    91         data.push_back(k);
    92         base.set(k, move(bounds[N-1]++, N-1, n));
    93       }
     94      data.push_back(k);
     95      base.set(k, move(bounds[N-1]++, N-1, n));
    9496    }
    9597
    9698    iterator begin(Val n) const {
    97       if(n < N)
    98         return data.begin() + (n ? bounds[n-1] : 0);
    99       else
    100         return data.end();
     99      return data.begin() + (n ? bounds[n-1] : 0);
    101100    }
    102101
    103102    iterator end(Val n) const {
    104       if(n < N)
    105         return data.begin() + bounds[n];
    106       else
    107         return data.end();
     103      return data.begin() + bounds[n];
    108104    }
    109105
    110106    size_t size(Val n) const {
    111       if(n < N)
    112         return bounds[n] - (n ? bounds[n-1] : 0);
    113       else
    114         return 0;
     107      return bounds[n] - (n ? bounds[n-1] : 0);
    115108    }
    116109   
  • src/work/klao/iter_map_test.cc

    r361 r362  
    120120
    121121  {
    122     cout << "Testing the IterableBoolMap...\n";
     122    cout << "\n\n\nTesting the IterableBoolMap...\n";
    123123
    124124    BaseMap base(344);
    125     TestBoolMap test(base);
     125    TestBoolMap test(base,true);
    126126
    127127
     
    158158    cout << " 42: " << test[42] << endl;
    159159
    160     cout << "Inserting 21 to class 1...\n";
    161     test.insert(21,1);
    162     print(test,2);
    163 
    164     cout << "Inserting 20 to class 1...\n";
    165     test.insert(20,0);
    166     print(test,2);
    167 
    168     cout << "Testing some map values:\n";
    169     cout << " 12: " << test[12] << endl;
    170     cout << " 22: " << test[22] << endl;
    171     cout << " 10: " << test[10] << endl;
    172     cout << " 20: " << test[20] << endl;
    173     cout << " 11: " << test[11] << endl;
    174     cout << " 21: " << test[21] << endl;
    175     cout << " 42: " << test[42] << endl;
    176 
    177     cout << "Setting 20 to class 2...\n";
    178     test.set(20,2);
     160    cout << "Setting 10 to class true...\n";
     161    test.set(10,true);
    179162    print(test,2);
    180163 
    181     cout << "Setting 10 to class 1...\n";
    182     test.set(10,1);
    183     print(test,2);
    184  
    185     cout << "Setting 11 to class 1...\n";
     164    cout << "Setting 11 to class true...\n";
    186165    test.set(11,1);
    187166    print(test,2);
    188167 
    189     cout << "Setting 12 to class 1...\n";
    190     test.set(12,1);
     168    cout << "Setting 12 to class false...\n";
     169    test.set(12,false);
    191170    print(test,2);
    192171 
    193     cout << "Setting 21 to class 2...\n";
    194     test.set(21,2);
    195     print(test,2);
    196  
    197     cout << "Setting 22 to class 2...\n";
    198     test.set(22,2);
     172    cout << "Setting 22 to class false...\n";
     173    test.set(22,false);
    199174    print(test,2);
    200175 
     
    203178    cout << " 22: " << test[22] << endl;
    204179    cout << " 10: " << test[10] << endl;
    205     cout << " 20: " << test[20] << endl;
    206180    cout << " 11: " << test[11] << endl;
    207     cout << " 21: " << test[21] << endl;
    208181    cout << " 42: " << test[42] << endl;
    209182
Note: See TracChangeset for help on using the changeset viewer.