Lucene++ - a full-featured, c++ search engine
API Documentation


 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
HashSet.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2011 Alan Wright. All rights reserved.
3 // Distributable under the terms of either the Apache License (Version 2.0)
4 // or the GNU Lesser General Public License.
6 
7 #ifndef HASHSET_H
8 #define HASHSET_H
9 
10 #include <boost/unordered_set.hpp>
11 #include "LuceneSync.h"
12 
13 namespace Lucene
14 {
16  template < class TYPE, class HASH = boost::hash<TYPE>, class EQUAL = std::equal_to<TYPE> >
17  class HashSet : public LuceneSync
18  {
19  public:
21  typedef boost::unordered_set< TYPE, HASH, EQUAL, LuceneAllocator<TYPE> > set_type;
22  typedef typename set_type::iterator iterator;
23  typedef typename set_type::const_iterator const_iterator;
24  typedef TYPE value_type;
25 
26  virtual ~HashSet()
27  {
28  }
29 
30  protected:
31  boost::shared_ptr<set_type> setContainer;
32 
33  public:
35  {
36  this_type instance;
37  instance.setContainer = Lucene::newInstance<set_type>();
38  return instance;
39  }
40 
41  template <class ITER>
42  static this_type newInstance(ITER first, ITER last)
43  {
44  this_type instance;
45  instance.setContainer = Lucene::newInstance<set_type>(first, last);
46  return instance;
47  }
48 
49  void reset()
50  {
51  setContainer.reset();
52  }
53 
54  int32_t size() const
55  {
56  return (int32_t)setContainer->size();
57  }
58 
59  bool empty() const
60  {
61  return setContainer->empty();
62  }
63 
64  void clear()
65  {
66  setContainer->clear();
67  }
68 
70  {
71  return setContainer->begin();
72  }
73 
75  {
76  return setContainer->end();
77  }
78 
80  {
81  return setContainer->begin();
82  }
83 
85  {
86  return setContainer->end();
87  }
88 
89  operator bool() const
90  {
91  return setContainer;
92  }
93 
94  bool operator! () const
95  {
96  return !setContainer;
97  }
98 
99  set_type& operator= (const set_type& other)
100  {
101  setContainer = other.setContainer;
102  return *this;
103  }
104 
105  bool add(const TYPE& type)
106  {
107  return setContainer->insert(type).second;
108  }
109 
110  template <class ITER>
111  void addAll(ITER first, ITER last)
112  {
113  setContainer->insert(first, last);
114  }
115 
116  bool remove(const TYPE& type)
117  {
118  return (setContainer->erase(type) > 0);
119  }
120 
121  iterator find(const TYPE& type)
122  {
123  return setContainer->find(type);
124  }
125 
126  bool contains(const TYPE& type) const
127  {
128  return (setContainer->find(type) != setContainer->end());
129  }
130  };
131 }
132 
133 #endif

clucene.sourceforge.net