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 
2 // Copyright (c) 2009-2014 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 public:
20  typedef boost::unordered_set<TYPE, HASH, EQUAL> set_type;
21  typedef typename set_type::iterator iterator;
22  typedef typename set_type::const_iterator const_iterator;
23  typedef TYPE value_type;
24 
25  virtual ~HashSet() {
26  }
27 
28 protected:
29  boost::shared_ptr<set_type> setContainer;
30 
31 public:
33  this_type instance;
34  instance.setContainer = Lucene::newInstance<set_type>();
35  return instance;
36  }
37 
38  template <class ITER>
39  static this_type newInstance(ITER first, ITER last) {
40  this_type instance;
41  instance.setContainer = Lucene::newInstance<set_type>(first, last);
42  return instance;
43  }
44 
45  void reset() {
46  setContainer.reset();
47  }
48 
49  int32_t size() const {
50  return (int32_t)setContainer->size();
51  }
52 
53  bool empty() const {
54  return setContainer->empty();
55  }
56 
57  void clear() {
58  setContainer->clear();
59  }
60 
62  return setContainer->begin();
63  }
64 
66  return setContainer->end();
67  }
68 
70  return setContainer->begin();
71  }
72 
73  const_iterator end() const {
74  return setContainer->end();
75  }
76 
77  operator bool() const {
78  return setContainer.get() != NULL;
79  }
80 
81  bool operator! () const {
82  return !setContainer;
83  }
84 
85  set_type& operator= (const set_type& other) {
86  setContainer = other.setContainer;
87  return *this;
88  }
89 
90  bool add(const TYPE& type) {
91  return setContainer->insert(type).second;
92  }
93 
94  template <class ITER>
95  void addAll(ITER first, ITER last) {
96  setContainer->insert(first, last);
97  }
98 
99  bool remove(const TYPE& type) {
100  return (setContainer->erase(type) > 0);
101  }
102 
103  iterator find(const TYPE& type) {
104  return setContainer->find(type);
105  }
106 
107  bool contains(const TYPE& type) const {
108  return (setContainer->find(type) != setContainer->end());
109  }
110 };
111 
112 }
113 
114 #endif

clucene.sourceforge.net