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

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- File List
- Globals

MapOfSets.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 MAPOFSETS_H
8 #define MAPOFSETS_H
9
10 #include "Lucene.h"
11
12 namespace Lucene {
13
15 template <class MAPKEY, class MAPHASH, class MAPEQUAL, class SETVALUE, class SETHASH, class SETEQUAL>
16 class MapOfSets {
17 public:
18 typedef HashSet<SETVALUE, SETHASH, SETEQUAL> set_type;
19 typedef HashMap<MAPKEY, set_type, MAPHASH, MAPEQUAL> map_type;
20
21 MapOfSets(map_type m) {
22 theMap = m;
23 }
24
25 protected:
26 map_type theMap;
27
28 public:
30 map_type getMap() {
31 return theMap;
32 }
33
37 int32_t put(MAPKEY key, SETVALUE val) {
38 typename map_type::iterator entry = theMap.find(key);
39 if (entry != theMap.end()) {
40 entry->second.add(val);
41 return entry->second.size();
42 } else {
43 set_type theSet(set_type::newInstance());
44 theSet.add(val);
45 theMap.put(key, theSet);
46 return 1;
47 }
48 }
49
53 int32_t putAll(MAPKEY key, set_type vals) {
54 typename map_type::iterator entry = theMap.find(key);
55 if (entry != theMap.end()) {
56 entry->second.addAll(vals.begin(), vals.end());
57 return entry->second.size();
58 } else {
59 set_type theSet(set_type::newInstance(vals.begin(), vals.end()));
60 theMap.put(key, theSet);
61 return theSet.size();
62 }
63 }
64 };
65
66 }
67
68 #endif
Lucene::HashMap::find
iterator find(const KEY &key)
Definition: HashMap.h:110
Lucene::HashSet::end
iterator end()
Definition: HashSet.h:65
Lucene::HashMap< MAPKEY, set_type, MAPHASH, MAPEQUAL >
Lucene::HashMap::put
void put(const KEY &key, const VALUE &value)
Definition: HashMap.h:85
Lucene::HashSet::size
int32_t size() const
Definition: HashSet.h:49
Lucene::HashSet::add
bool add(const TYPE &type)
Definition: HashSet.h:90
Lucene::HashMap::end
iterator end()
Definition: HashMap.h:60
Lucene::MapOfSets::getMap
map_type getMap()
Definition: MapOfSets.h:30
Lucene::HashSet
Utility template class to handle hash set collections that can be safely copied and shared...
Definition: HashSet.h:17
Lucene::MapOfSets::put
int32_t put(MAPKEY key, SETVALUE val)
Adds val to the HashSet associated with key in the HashMap. If key is not already in the map...
Definition: MapOfSets.h:37
Lucene::MapOfSets::MapOfSets
MapOfSets(map_type m)
Definition: MapOfSets.h:21
Lucene
Definition: AbstractAllTermDocs.h:12
Lucene::MapOfSets::map_type
HashMap< MAPKEY, set_type, MAPHASH, MAPEQUAL > map_type
Definition: MapOfSets.h:19
Lucene::HashMap< MAPKEY, set_type, MAPHASH, MAPEQUAL >::iterator
map_type::iterator iterator
Definition: HashMap.h:22
Lucene::MapOfSets::putAll
int32_t putAll(MAPKEY key, set_type vals)
Adds multiple vals to the HashSet associated with key in the HashMap. If key is not already in the ma...
Definition: MapOfSets.h:53
Lucene::HashSet::begin
iterator begin()
Definition: HashSet.h:61
Lucene::MapOfSets::set_type
HashSet< SETVALUE, SETHASH, SETEQUAL > set_type
Definition: MapOfSets.h:18
Lucene::MapOfSets
Helper class for keeping Lists of Objects associated with keys.
Definition: MapOfSets.h:16
Lucene::MapOfSets::theMap
map_type theMap
Definition: MapOfSets.h:26
Lucene::HashSet::newInstance
static this_type newInstance()
Definition: HashSet.h:32

clucene.sourceforge.net