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


Loading...
Searching...
No Matches
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
13namespace Lucene {
14
16template < class TYPE, class HASH = boost::hash<TYPE>, class EQUAL = std::equal_to<TYPE> >
17class HashSet : public LuceneSync {
18public:
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
28protected:
29 boost::shared_ptr<set_type> setContainer;
30
31public:
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
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
Utility template class to handle hash set collections that can be safely copied and shared.
Definition HashSet.h:17
static this_type newInstance(ITER first, ITER last)
Definition HashSet.h:39
virtual ~HashSet()
Definition HashSet.h:25
const_iterator begin() const
Definition HashSet.h:69
bool add(const TYPE &type)
Definition HashSet.h:90
bool operator!() const
Definition HashSet.h:81
void reset()
Definition HashSet.h:45
iterator begin()
Definition HashSet.h:61
bool empty() const
Definition HashSet.h:53
bool remove(const TYPE &type)
Definition HashSet.h:99
set_type::iterator iterator
Definition HashSet.h:21
bool contains(const TYPE &type) const
Definition HashSet.h:107
boost::shared_ptr< set_type > setContainer
Definition HashSet.h:29
boost::unordered_set< TYPE, HASH, EQUAL > set_type
Definition HashSet.h:20
void addAll(ITER first, ITER last)
Definition HashSet.h:95
static this_type newInstance()
Definition HashSet.h:32
set_type & operator=(const set_type &other)
Definition HashSet.h:85
const_iterator end() const
Definition HashSet.h:73
int32_t size() const
Definition HashSet.h:49
iterator end()
Definition HashSet.h:65
void clear()
Definition HashSet.h:57
set_type::const_iterator const_iterator
Definition HashSet.h:22
TYPE value_type
Definition HashSet.h:23
iterator find(const TYPE &type)
Definition HashSet.h:103
HashSet< TYPE, HASH, EQUAL > this_type
Definition HashSet.h:19
Base class for all Lucene synchronised classes.
Definition LuceneSync.h:15
Definition AbstractAllTermDocs.h:12

clucene.sourceforge.net