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


 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
MapOfSets.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 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:
20 
22  theMap = m;
23  }
24 
25 protected:
27 
28 public:
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 {
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

clucene.sourceforge.net