src/work/klao/iter_map.h
changeset 362 6c2e8a1f380a
parent 361 ab0899df30d2
child 365 9ca84022df34
equal deleted inserted replaced
1:792b7e4e58a0 2:d5a52e6bd6ae
    53 	KeyType orig_key = data[a];
    53 	KeyType orig_key = data[a];
    54 	while(m > n) {
    54 	while(m > n) {
    55 	  --m;
    55 	  --m;
    56 	  half_swap(a, bounds[m]++);
    56 	  half_swap(a, bounds[m]++);
    57 	}
    57 	}
       
    58 	// FIXME: range check ide?
    58 	while(m < n) {
    59 	while(m < n) {
    59 	  half_swap(a, --bounds[m]);
    60 	  half_swap(a, --bounds[m]);
    60 	  ++m;
    61 	  ++m;
    61 	}
    62 	}
    62 	if(a != orig_a) {
    63 	if(a != orig_a) {
    77     Val operator[](const KeyType& k) const {
    78     Val operator[](const KeyType& k) const {
    78       return find(base[k]);
    79       return find(base[k]);
    79     }
    80     }
    80 
    81 
    81     void set(const KeyType& k, Val n) {
    82     void set(const KeyType& k, Val n) {
    82       // FIXME: n < N ???
    83       // FIXME: range check?
    83       size_t a = base[k];
    84       size_t a = base[k];
    84       if(a < bounds[N-1] && n < N) {
    85       if(a < bounds[N-1]) {
    85 	base.set(k, move(a, find(a), n));
    86 	base.set(k, move(a, find(a), n));
       
    87       }
       
    88       else {
       
    89 	insert(k, n);
    86       }
    90       }
    87     }
    91     }
    88 
    92 
    89     void insert(const KeyType& k, Val n) {
    93     void insert(const KeyType& k, Val n) {
    90       if(n < N) {
    94       data.push_back(k);
    91 	data.push_back(k);
    95       base.set(k, move(bounds[N-1]++, N-1, n));
    92 	base.set(k, move(bounds[N-1]++, N-1, n));
       
    93       }
       
    94     }
    96     }
    95 
    97 
    96     iterator begin(Val n) const {
    98     iterator begin(Val n) const {
    97       if(n < N)
    99       return data.begin() + (n ? bounds[n-1] : 0);
    98 	return data.begin() + (n ? bounds[n-1] : 0);
       
    99       else
       
   100 	return data.end();
       
   101     }
   100     }
   102 
   101 
   103     iterator end(Val n) const {
   102     iterator end(Val n) const {
   104       if(n < N)
   103       return data.begin() + bounds[n];
   105 	return data.begin() + bounds[n];
       
   106       else
       
   107 	return data.end();
       
   108     }
   104     }
   109 
   105 
   110     size_t size(Val n) const {
   106     size_t size(Val n) const {
   111       if(n < N)
   107       return bounds[n] - (n ? bounds[n-1] : 0);
   112 	return bounds[n] - (n ? bounds[n-1] : 0);
       
   113       else
       
   114 	return 0;
       
   115     }
   108     }
   116     
   109     
   117     size_t size() const {
   110     size_t size() const {
   118       // assert(bounds[N-1] == data.size());
   111       // assert(bounds[N-1] == data.size());
   119       return bounds[N-1];
   112       return bounds[N-1];