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

HashSet.h
Go to the documentation of this file.
1 // 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:
19 typedef HashSet<TYPE, HASH, EQUAL> this_type;
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:
32 static this_type newInstance() {
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
61 iterator begin() {
62 return setContainer->begin();
63 }
64
65 iterator end() {
66 return setContainer->end();
67 }
68
69 const_iterator begin() const {
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
Lucene::HashSet::iterator
set_type::iterator iterator
Definition: HashSet.h:21
Lucene::HashSet::begin
const_iterator begin() const
Definition: HashSet.h:69
Lucene::HashSet::end
iterator end()
Definition: HashSet.h:65
Lucene::HashSet::operator!
bool operator!() const
Definition: HashSet.h:81
Lucene::HashSet::add
bool add(const TYPE &type)
Definition: HashSet.h:90
Lucene::HashSet::this_type
HashSet< TYPE, HASH, EQUAL > this_type
Definition: HashSet.h:19
Lucene::LuceneSync
Base class for all Lucene synchronised classes.
Definition: LuceneSync.h:15
Lucene::HashSet::contains
bool contains(const TYPE &type) const
Definition: HashSet.h:107
Lucene::HashSet::find
iterator find(const TYPE &type)
Definition: HashSet.h:103
Lucene::HashSet::addAll
void addAll(ITER first, ITER last)
Definition: HashSet.h:95
Lucene::HashSet::newInstance
static this_type newInstance(ITER first, ITER last)
Definition: HashSet.h:39
Lucene::HashSet
Utility template class to handle hash set collections that can be safely copied and shared...
Definition: HashSet.h:17
Lucene::HashSet::end
const_iterator end() const
Definition: HashSet.h:73
Lucene
Definition: AbstractAllTermDocs.h:12
Lucene::HashSet::empty
bool empty() const
Definition: HashSet.h:53
Lucene::HashSet::clear
void clear()
Definition: HashSet.h:57
LuceneSync.h
Lucene::HashSet::const_iterator
set_type::const_iterator const_iterator
Definition: HashSet.h:22
Lucene::HashSet::setContainer
boost::shared_ptr< set_type > setContainer
Definition: HashSet.h:29
Lucene::HashSet::~HashSet
virtual ~HashSet()
Definition: HashSet.h:25
Lucene::HashSet::value_type
TYPE value_type
Definition: HashSet.h:23
Lucene::HashSet::begin
iterator begin()
Definition: HashSet.h:61
Lucene::HashSet::set_type
boost::unordered_set< TYPE, HASH, EQUAL > set_type
Definition: HashSet.h:20
Lucene::HashSet::operator=
set_type & operator=(const set_type &other)
Definition: HashSet.h:85
Lucene::HashSet::reset
void reset()
Definition: HashSet.h:45
Lucene::HashSet::size
int32_t size() const
Definition: HashSet.h:49
Lucene::HashSet::newInstance
static this_type newInstance()
Definition: HashSet.h:32

clucene.sourceforge.net