• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef INTERVALSET_H_
2 #define INTERVALSET_H_
3 
4 #include <stddef.h>
5 #include <vector>
6 
7 class IntervalSet {
8   typedef int key_t; // TODO?! template <typename T>
9   typedef std::pair<key_t,key_t> value_t;
10   typedef std::vector<value_t> data_t;
11  public:
12   static const key_t npos;
13 
14   void clear();
15   // [start;end) !
16   void add(key_t start,key_t end=npos);
17   void finish();
18 
size()19   size_t size() const { return data.size(); }
20 
21   // only after finish() has been called:
22   bool contains(key_t val) const;
23   key_t next(key_t val) const;
24 
25   void dump() const;
26  private:
27   // currently not used
28   bool intersect(const value_t &a,const value_t &b) const;
29   void unite(value_t &aret,const value_t &b) const;
30  private:
31   data_t data;
32 };
33 
34 #endif
35