summaryrefslogtreecommitdiff
path: root/flower/associter.hh
blob: 6103f2266c8746a73e22926e08d1495636914d87 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
  associter.hh -- part of flowerlib

  (c) 1996 Han-Wen Nienhuys
*/

#ifndef ASSOCITER_HH
#define ASSOCITER_HH

#include "assoc.hh"

/// an iterator for the #Assoc# class
template<class K, class V>
struct Assoc_iter {
    int i;
    Assoc<K,V> &assoc_;
    
    Assoc_iter(Assoc<K,V> &a) :
	assoc_(a)
    {	
	i= next(0);
    }
    int next(int j) {
	while (j < assoc_.arr.sz() && assoc_.arr[j].free)
	    j++;
	return j;
    }
    bool ok() const {
	return i < assoc_.arr.sz();
    }
    void OK()const {
	assert(!ok() || !assoc_.arr[i].free);
    }
    void operator++(int) { i++; i = next(i); }
    K key() { return assoc_.arr[i].key; }
    V &val() { return assoc_.arr[i].val; }    
};
/*
  Iterator
 */

#endif