Gaia
searchspacepool.h
1 /*
2  * Copyright (C) 2006-2013 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Gaia
5  *
6  * Gaia is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License as published by the Free
8  * Software Foundation (FSF), either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the Affero GNU General Public License
17  * version 3 along with this program. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef GAIA_SEARCHSPACEPOOL_H
21 #define GAIA_SEARCHSPACEPOOL_H
22 
23 #include <QMutex>
24 #include "searchspace.h"
25 
26 namespace gaia2 {
27 
28 namespace parser {
29  class Predicate;
30 }
31 
32 
40 template <typename SearchPointType, typename DataSetType>
42 
43  public:
45 
51  BaseSearchSpacePool(const DataSetType* dataset);
52 
54 
59  void recreate();
60 
65  SearchSpaceType* getAllPoints() const;
66 
71  void indexOn(const QString& descriptorName);
72 
76  bool hasIndex(const QString& descriptorName) const;
77 
78  SearchSpaceType* getSubSpace(const parser::Predicate* pred) const;
79 
80  const DataSetType* dataset() const { return _dataset; }
81 
85  static void clear();
86 
87  static SearchSpaceType* acquire();
88  static void release(SearchSpaceType* sspace);
89 
90  protected:
91  static QList<SearchSpaceType*> _sspool;
92  static QMutex* _sspoolMutex;
93 
94  friend class BaseQueryOptimizer<SearchPointType, DataSetType>;
95 
96  const DataSetType* _dataset;
97 
98  SearchSpaceType* _originalSpace;
99 
100  class ValueIndex {
101  public:
102  GaiaMap<QPair<int, int>, SearchSpaceType*> sorted; // key is <start,end> for ranges
103  SearchSpaceType* sspace;
104 
105  void clear() {
106  foreach (const SearchSpaceType* sspace, sorted) delete sspace;
107  sorted.clear();
108  delete sspace; sspace = 0;
109  }
110 
111  SearchSpaceType* getSubSpaceInto(SearchSpaceType* result,
112  int start, int end) const;
113  };
114 
115  GaiaMap<QString, ValueIndex> _valueIndex; // from descriptor name to ordered sspace
116 
117  class LabelIndex {
118  public:
119  GaiaMap<QString, QPair<int, int> > ranges; // from label value to (start, end) range inside sspace
120  SearchSpaceType* sspace;
121 
122  void clear() { delete sspace; sspace = 0; ranges.clear(); }
123  };
124 
125  GaiaMap<QString, LabelIndex> _labelIndex; // from descriptor name to label index
126 
127 
128  void clearIndices();
129  int getCuttingPos(const SearchSpaceType& sspace,
130  int idx, int type, Real value, int start, int end) const;
131 
133  void indexOnValue(const QString& descriptorName);
134 
136  void indexOnLabel(const QString& descriptorName);
137 
139  void indexOnEnum(const QString& descriptorName);
140 
141 };
142 
143 
144 // include implementation directly as our class is a templated one
145 #include "searchspacepool_impl.h"
146 
147 
150 
151 } // namespace gaia2
152 
153 
154 #endif // GAIA_SEARCHSPACEPOOL_H
Definition: parsertypes.h:40
Map class (derived from QMap) but that throws a custom Exception instead of returning a default const...
Definition: types.h:143
The QueryOptimizer class tries to optimize a query by reducing the SearchSpace on which it is suppose...
Definition: parsertypes.h:30
Main Gaia namespace, which contains all the library functions.
Definition: addfield.cpp:22
A SearchSpace is a structure dedicated to the task of storing pointers to Point with an associated di...
Definition: searchspace.h:91
The SearchSpacePool accomplishes 2 main functions:
Definition: searchspacepool.h:41
Definition: searchspacepool.h:100
Definition: searchspacepool.h:117