11#include <boost/functional/hash.hpp>
12#include <boost/unordered/unordered_map.hpp>
23#ifndef OPENMS_COMPARISON_CLUSTERING_HASHGRID_H
24 #define OPENMS_COMPARISON_CLUSTERING_HASHGRID_H
38 template<
typename Cluster>
56 typedef typename boost::unordered_multimap<ClusterCenter, Cluster>
CellContent;
61 typedef boost::unordered_map<CellIndex, CellContent>
Grid;
63 typedef typename CellContent::key_type
key_type;
148 return !(*
this == rhs);
250 return !(*
this == rhs);
308 return cell.insert(v);
328 auto cell =
cells_.find(cellkey);
331 return cell->second.erase(key);
348 if (grid_it ==
cells_.end())
361 if (grid_it ==
cells_.end())
401 ret += it->second.size();
482 for (; it != ret.
end(); ++it, ++lit, ++rit)
484 double t = std::floor(*lit / *rit);
485 if (t < std::numeric_limits<Int64>::min() || t > std::numeric_limits<Int64>::max())
487 *it =
static_cast<Int64>(t);
497 for (; it_new != d.
end(); ++it_new, ++it_cur)
499 if (*it_cur < *it_new)
506 template<UInt N,
typename T>
509 boost::hash<T> hasher;
510 std::size_t hash = 0;
Representation of a coordinate in D-dimensional space.
Definition DPosition.h:32
const_iterator begin() const
Non-mutable begin iterator.
Definition DPosition.h:348
CoordinateType * iterator
Definition DPosition.h:51
const CoordinateType * const_iterator
Definition DPosition.h:52
const_iterator end() const
Non-mutable end iterator.
Definition DPosition.h:354
Out of range exception.
Definition Exception.h:291
Constant element iterator for the hash grid.
Definition HashGrid.h:171
ConstIterator(const Grid &grid, grid_iterator grid_it, cell_iterator cell_it)
Definition HashGrid.h:220
const ConstIterator operator++(int)
Definition HashGrid.h:236
bool operator!=(const ConstIterator &rhs) const
Definition HashGrid.h:248
value_type * pointer
The pointer type as returned by operator->()
Definition HashGrid.h:188
const Grid & grid_
Definition HashGrid.h:193
const CellIndex index() const
Definition HashGrid.h:263
grid_iterator grid_it_
Definition HashGrid.h:194
const value_type * operator->() const
Definition HashGrid.h:258
HashGrid::value_type value_type
The iterator's value type.
Definition HashGrid.h:184
bool operator==(const ConstIterator &rhs) const
Definition HashGrid.h:243
value_type & reference
The reference type as returned by operator*()
Definition HashGrid.h:186
const value_type & operator*() const
Definition HashGrid.h:253
Grid::const_iterator grid_iterator
Definition HashGrid.h:175
cell_iterator cell_it_
Definition HashGrid.h:195
ConstIterator(const Iterator &it)
Definition HashGrid.h:225
ConstIterator(const Grid &grid)
Definition HashGrid.h:216
std::input_iterator_tag iterator_category
The iterator's category type.
Definition HashGrid.h:182
CellContent::const_iterator cell_iterator
Definition HashGrid.h:176
std::ptrdiff_t difference_type
The difference type.
Definition HashGrid.h:190
void searchNextCell_()
Definition HashGrid.h:198
ConstIterator & operator++()
Definition HashGrid.h:229
Element iterator for the hash grid.
Definition HashGrid.h:72
value_type & operator*() const
Definition HashGrid.h:151
CellContent::iterator cell_iterator
Definition HashGrid.h:77
value_type * pointer
The pointer type as returned by operator->()
Definition HashGrid.h:89
const CellIndex index() const
Definition HashGrid.h:161
grid_iterator grid_it_
Definition HashGrid.h:96
HashGrid::value_type value_type
The iterator's value type.
Definition HashGrid.h:85
value_type & reference
The reference type as returned by operator*()
Definition HashGrid.h:87
Grid::iterator grid_iterator
Definition HashGrid.h:76
bool operator==(const Iterator &rhs) const
Definition HashGrid.h:141
cell_iterator cell_it_
Definition HashGrid.h:97
Iterator(Grid &grid, grid_iterator grid_it, cell_iterator cell_it)
Definition HashGrid.h:122
value_type * operator->() const
Definition HashGrid.h:156
Grid & grid_
Definition HashGrid.h:95
std::input_iterator_tag iterator_category
The iterator's category type.
Definition HashGrid.h:83
Iterator(Grid &grid)
Definition HashGrid.h:118
std::ptrdiff_t difference_type
The difference type.
Definition HashGrid.h:91
bool operator!=(const Iterator &rhs) const
Definition HashGrid.h:146
void searchNextCell_()
Definition HashGrid.h:100
Iterator & operator++()
Definition HashGrid.h:127
const Iterator operator++(int)
Definition HashGrid.h:134
Container for (2-dimensional coordinate, value) pairs.
Definition HashGrid.h:40
CellContent::const_iterator const_cell_iterator
Definition HashGrid.h:274
grid_iterator grid_end()
Definition HashGrid.h:466
boost::unordered_multimap< ClusterCenter, Cluster > CellContent
Contents of a cell.
Definition HashGrid.h:56
const CellIndex & grid_dimension
Upper-right corner of key space for cells.
Definition HashGrid.h:291
Grid::const_iterator const_grid_iterator
Definition HashGrid.h:272
CellIndex grid_dimension_
Definition HashGrid.h:280
Iterator iterator
Definition HashGrid.h:271
const_iterator begin() const
Returns iterator to first element.
Definition HashGrid.h:358
CellContent::iterator cell_iterator
Definition HashGrid.h:275
const_grid_iterator grid_find(const CellIndex &x) const
Returns the grid cell at given index if present, otherwise the grid_end iterator.
Definition HashGrid.h:442
const_grid_iterator grid_end() const
Returns iterator to on after last grid cell.
Definition HashGrid.h:418
DPosition< 2, Int64 > CellIndex
Index for cells.
Definition HashGrid.h:51
DPosition< 2, double > ClusterCenter
Coordinate for stored pairs.
Definition HashGrid.h:46
boost::unordered_map< CellIndex, CellContent > Grid
Map of (cell-index, cell-content).
Definition HashGrid.h:61
cell_iterator insert(const value_type &v)
Inserts a (2-dimensional coordinate, value) pair.
Definition HashGrid.h:303
ConstIterator const_iterator
Definition HashGrid.h:270
size_type size() const
Return number of elements.
Definition HashGrid.h:395
CellContent::value_type value_type
Definition HashGrid.h:65
bool empty() const
Return true if HashGrid is empty.
Definition HashGrid.h:387
CellIndex cellIndexAtClusterCenter(const ClusterCenter &key) const
Computes the cell index for a given cluster center coordinate.
Definition HashGrid.h:477
Grid cells_
Definition HashGrid.h:279
CellContent::size_type size_type
Definition HashGrid.h:276
Grid::iterator grid_iterator
Definition HashGrid.h:273
HashGrid(const ClusterCenter &c_dimension)
Definition HashGrid.h:294
grid_iterator grid_find(const CellIndex &x)
Returns the grid cell at given index if present, otherwise the grid_end iterator.
Definition HashGrid.h:450
CellContent::key_type key_type
Definition HashGrid.h:63
const Grid::mapped_type & grid_at(const CellIndex &x) const
Returns the grid cell at given index.
Definition HashGrid.h:426
void updateGridDimension_(const CellIndex &d)
Definition HashGrid.h:493
grid_iterator grid_begin()
Definition HashGrid.h:459
void clear()
Clears the map.
Definition HashGrid.h:337
iterator end()
Returns iterator to first element.
Definition HashGrid.h:371
const_iterator end() const
Returns iterator to first element.
Definition HashGrid.h:379
void erase(iterator pos)
Erases element on given iterator.
Definition HashGrid.h:314
const ClusterCenter cell_dimension
Dimension of cells.
Definition HashGrid.h:286
iterator begin()
Returns iterator to first element.
Definition HashGrid.h:345
const_grid_iterator grid_begin() const
Returns iterator to first grid cell.
Definition HashGrid.h:410
size_type erase(const key_type &key)
Erases elements matching the 2-dimensional coordinate.
Definition HashGrid.h:325
Grid::mapped_type & grid_at(const CellIndex &x)
Definition HashGrid.h:434
CellContent::mapped_type mapped_type
Definition HashGrid.h:64
int64_t Int64
Signed integer type (64bit)
Definition Types.h:40
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::size_t hash_value(const DPosition< N, T > &b)
Definition HashGrid.h:507