37 #include <boost/array.hpp>
38 #include <boost/functional/hash.hpp>
39 #include <boost/unordered/unordered_map.hpp>
44 #ifndef OPENMS_COMPARISON_CLUSTERING_HASHGRID_H
45 #define OPENMS_COMPARISON_CLUSTERING_HASHGRID_H
59 template<
typename Cluster>
77 typedef typename boost::unordered_multimap<ClusterCenter, Cluster>
CellContent;
82 typedef boost::unordered_map<CellIndex, CellContent>
Grid;
84 typedef typename CellContent::key_type
key_type;
169 return !(*
this == rhs);
271 return !(*
this == rhs);
329 return cell.insert(v);
349 auto cell =
cells_.find(cellkey);
352 return cell->second.erase(key);
369 if (grid_it ==
cells_.end())
382 if (grid_it ==
cells_.end())
422 ret += it->second.size();
499 for (; it != ret.
end(); ++it, ++lit, ++rit)
501 double t = std::floor(*lit / *rit);
502 if (t < std::numeric_limits<Int64>::min() || t > std::numeric_limits<Int64>::max())
504 *it =
static_cast<Int64>(t);
513 for (; it_new != d.
end(); ++it_new, ++it_cur)
515 if (*it_cur < *it_new)
522 template<UInt N,
typename T>
525 boost::hash<T> hasher;
526 std::size_t hash = 0;
Representation of a coordinate in D-dimensional space.
Definition: DPosition.h:55
ConstIterator end() const
Non-mutable end iterator.
Definition: DPosition.h:412
CoordinateType * iterator
Definition: DPosition.h:76
const CoordinateType * const_iterator
Definition: DPosition.h:77
ConstIterator begin() const
Non-mutable begin iterator.
Definition: DPosition.h:406
Out of range exception.
Definition: Exception.h:313
Constant element iterator for the hash grid.
Definition: HashGrid.h:192
ConstIterator(const Grid &grid, grid_iterator grid_it, cell_iterator cell_it)
Definition: HashGrid.h:241
const ConstIterator operator++(int)
Definition: HashGrid.h:257
bool operator!=(const ConstIterator &rhs) const
Definition: HashGrid.h:269
value_type * pointer
The pointer type as returned by operator->()
Definition: HashGrid.h:209
const Grid & grid_
Definition: HashGrid.h:214
const CellIndex index() const
Definition: HashGrid.h:284
grid_iterator grid_it_
Definition: HashGrid.h:215
HashGrid::value_type value_type
The iterator's value type.
Definition: HashGrid.h:205
bool operator==(const ConstIterator &rhs) const
Definition: HashGrid.h:264
value_type & reference
The reference type as returned by operator*()
Definition: HashGrid.h:207
Grid::const_iterator grid_iterator
Definition: HashGrid.h:196
ConstIterator & operator++()
Definition: HashGrid.h:250
const value_type * operator->() const
Definition: HashGrid.h:279
cell_iterator cell_it_
Definition: HashGrid.h:216
ConstIterator(const Iterator &it)
Definition: HashGrid.h:246
const value_type & operator*() const
Definition: HashGrid.h:274
ConstIterator(const Grid &grid)
Definition: HashGrid.h:237
std::input_iterator_tag iterator_category
The iterator's category type.
Definition: HashGrid.h:203
CellContent::const_iterator cell_iterator
Definition: HashGrid.h:197
std::ptrdiff_t difference_type
The difference type.
Definition: HashGrid.h:211
void searchNextCell_()
Definition: HashGrid.h:219
Element iterator for the hash grid.
Definition: HashGrid.h:93
value_type & operator*() const
Definition: HashGrid.h:172
CellContent::iterator cell_iterator
Definition: HashGrid.h:98
value_type * pointer
The pointer type as returned by operator->()
Definition: HashGrid.h:110
const CellIndex index() const
Definition: HashGrid.h:182
grid_iterator grid_it_
Definition: HashGrid.h:117
HashGrid::value_type value_type
The iterator's value type.
Definition: HashGrid.h:106
value_type & reference
The reference type as returned by operator*()
Definition: HashGrid.h:108
Grid::iterator grid_iterator
Definition: HashGrid.h:97
bool operator==(const Iterator &rhs) const
Definition: HashGrid.h:162
cell_iterator cell_it_
Definition: HashGrid.h:118
Iterator(Grid &grid, grid_iterator grid_it, cell_iterator cell_it)
Definition: HashGrid.h:143
Grid & grid_
Definition: HashGrid.h:116
std::input_iterator_tag iterator_category
The iterator's category type.
Definition: HashGrid.h:104
Iterator(Grid &grid)
Definition: HashGrid.h:139
std::ptrdiff_t difference_type
The difference type.
Definition: HashGrid.h:112
bool operator!=(const Iterator &rhs) const
Definition: HashGrid.h:167
void searchNextCell_()
Definition: HashGrid.h:121
const Iterator operator++(int)
Definition: HashGrid.h:155
Iterator & operator++()
Definition: HashGrid.h:148
value_type * operator->() const
Definition: HashGrid.h:177
Container for (2-dimensional coordinate, value) pairs.
Definition: HashGrid.h:61
CellContent::const_iterator const_cell_iterator
Definition: HashGrid.h:295
grid_iterator grid_end()
Definition: HashGrid.h:487
CellIndex cellindexAtClustercenter_(const ClusterCenter &key)
Definition: HashGrid.h:494
boost::unordered_multimap< ClusterCenter, Cluster > CellContent
Contents of a cell.
Definition: HashGrid.h:77
const CellIndex & grid_dimension
Upper-right corner of key space for cells.
Definition: HashGrid.h:312
Grid::const_iterator const_grid_iterator
Definition: HashGrid.h:293
CellIndex grid_dimension_
Definition: HashGrid.h:301
Iterator iterator
Definition: HashGrid.h:292
const_iterator begin() const
Returns iterator to first element.
Definition: HashGrid.h:379
CellContent::iterator cell_iterator
Definition: HashGrid.h:296
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:463
const_grid_iterator grid_end() const
Returns iterator to on after last grid cell.
Definition: HashGrid.h:439
DPosition< 2, Int64 > CellIndex
Index for cells.
Definition: HashGrid.h:72
DPosition< 2, double > ClusterCenter
Coordinate for stored pairs.
Definition: HashGrid.h:67
boost::unordered_map< CellIndex, CellContent > Grid
Map of (cell-index, cell-content).
Definition: HashGrid.h:82
cell_iterator insert(const value_type &v)
Inserts a (2-dimensional coordinate, value) pair.
Definition: HashGrid.h:324
ConstIterator const_iterator
Definition: HashGrid.h:291
size_type size() const
Return number of elements.
Definition: HashGrid.h:416
CellContent::value_type value_type
Definition: HashGrid.h:86
bool empty() const
Return true if HashGrid is empty.
Definition: HashGrid.h:408
Grid cells_
Definition: HashGrid.h:300
CellContent::size_type size_type
Definition: HashGrid.h:297
Grid::iterator grid_iterator
Definition: HashGrid.h:294
HashGrid(const ClusterCenter &c_dimension)
Definition: HashGrid.h:315
grid_iterator grid_find(const CellIndex &x)
Returns the grid cell at given index if present, otherwise the grid_end iterator.
Definition: HashGrid.h:471
CellContent::key_type key_type
Definition: HashGrid.h:84
void updateGridDimension_(const CellIndex &d)
Definition: HashGrid.h:509
grid_iterator grid_begin()
Definition: HashGrid.h:480
void clear()
Clears the map.
Definition: HashGrid.h:358
const Grid::mapped_type & grid_at(const CellIndex &x) const
Returns the grid cell at given index.
Definition: HashGrid.h:447
iterator end()
Returns iterator to first element.
Definition: HashGrid.h:392
const_iterator end() const
Returns iterator to first element.
Definition: HashGrid.h:400
void erase(iterator pos)
Erases element on given iterator.
Definition: HashGrid.h:335
const ClusterCenter cell_dimension
Dimension of cells.
Definition: HashGrid.h:307
Grid::mapped_type & grid_at(const CellIndex &x)
Definition: HashGrid.h:455
iterator begin()
Returns iterator to first element.
Definition: HashGrid.h:366
const_grid_iterator grid_begin() const
Returns iterator to first grid cell.
Definition: HashGrid.h:431
size_type erase(const key_type &key)
Erases elements matching the 2-dimensional coordinate.
Definition: HashGrid.h:346
CellContent::mapped_type mapped_type
Definition: HashGrid.h:85
OPENMS_INT64_TYPE Int64
Signed integer type (64bit)
Definition: Types.h:70
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
std::size_t hash_value(const DPosition< N, T > &b)
Definition: HashGrid.h:523