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 // Copyright (c) 2009-2011 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  {
18  public:
21 
23  {
24  theMap = m;
25  }
26 
27  protected:
29 
30  public:
33  {
34  return theMap;
35  }
36 
40  int32_t put(MAPKEY key, SETVALUE val)
41  {
42  typename map_type::iterator entry = theMap.find(key);
43  if (entry != theMap.end())
44  {
45  entry->second.add(val);
46  return entry->second.size();
47  }
48  else
49  {
51  theSet.add(val);
52  theMap.put(key, theSet);
53  return 1;
54  }
55  }
56 
60  int32_t putAll(MAPKEY key, set_type vals)
61  {
62  typename map_type::iterator entry = theMap.find(key);
63  if (entry != theMap.end())
64  {
65  entry->second.addAll(vals.begin(), vals.end());
66  return entry->second.size();
67  }
68  else
69  {
70  set_type theSet(set_type::newInstance(vals.begin(), vals.end()));
71  theMap.put(key, theSet);
72  return theSet.size();
73  }
74  }
75  };
76 }
77 
78 #endif

clucene.sourceforge.net