src
uniq_vector.h
Go to the documentation of this file.
1 #ifndef _RE2C_UTIL_UNIQ_VECTOR_
2 #define _RE2C_UTIL_UNIQ_VECTOR_
3 
4 #include <vector>
5 
6 namespace re2c
7 {
8 
9 // wrapper over std::vector
10 // O(n) lookup
11 // O(n) insertion
12 template <typename value_t>
14 {
15  typedef std::vector<value_t> elems_t;
16  elems_t elems;
17 public:
19  : elems ()
20  {}
21  size_t size () const
22  {
23  return elems.size ();
24  }
25  const value_t & operator [] (size_t i) const
26  {
27  return elems[i];
28  }
29  size_t find_or_add (const value_t & v)
30  {
31  const size_t size = elems.size ();
32  for (size_t i = 0; i < size; ++i)
33  {
34  if (elems[i] == v)
35  {
36  return i;
37  }
38  }
39  elems.push_back (v);
40  return size;
41  }
42 };
43 
44 } // namespace re2c
45 
46 #endif // _RE2C_UTIL_UNIQ_VECTOR_
const value_t & operator[](size_t i) const
Definition: uniq_vector.h:25
size_t size() const
Definition: uniq_vector.h:21
size_t find_or_add(const value_t &v)
Definition: uniq_vector.h:29
Definition: bitmap.cc:10