39 #include <boost/array.hpp>
40 #include <boost/functional/hash.hpp>
41 #include <boost/unordered/unordered_map.hpp>
46 #ifndef OPENMS_COMPARISON_CLUSTERING_HASHGRID_H
47 #define OPENMS_COMPARISON_CLUSTERING_HASHGRID_H
61 template <
typename Cluster>
79 typedef typename boost::unordered_multimap<ClusterCenter, Cluster>
CellContent;
84 typedef boost::unordered_map<CellIndex, CellContent>
Grid;
86 typedef typename CellContent::key_type
key_type;
95 public std::iterator<std::input_iterator_tag, value_type>
154 {
return !(*
this == rhs); }
173 public std::iterator<std::input_iterator_tag, const value_type>
236 {
return !(*
this == rhs); }
294 return cell.insert(v);
314 auto cell =
cells_.find(cellkey);
315 if (cell ==
cells_.end())
return 0;
316 return cell->second.erase(key);
330 if (grid_it ==
cells_.end())
return end();
342 if (grid_it ==
cells_.end())
return end();
381 ret += it->second.size();
434 for (; it != ret.
end(); ++it, ++lit, ++rit)
436 double t = std::floor(*lit / *rit);
437 if (t < std::numeric_limits<Int64>::min() || t > std::numeric_limits<Int64>::max())
throw Exception::OutOfRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
438 *it =
static_cast<Int64>(t);
447 for (; it_new != d.
end(); ++it_new, ++it_cur)
449 if (*it_cur < *it_new)
457 template <UInt N,
typename T>
460 boost::hash<T> hasher;
461 std::size_t hash = 0;
Representation of a coordinate in D-dimensional space.
Definition: DPosition.h:54
ConstIterator end() const
Non-mutable end iterator.
Definition: DPosition.h:401
CoordinateType * iterator
Definition: DPosition.h:75
const CoordinateType * const_iterator
Definition: DPosition.h:76
ConstIterator begin() const
Non-mutable begin iterator.
Definition: DPosition.h:395
Out of range exception.
Definition: Exception.h:313
Constant element iterator for the hash grid.
Definition: HashGrid.h:174
ConstIterator(const Grid &grid, grid_iterator grid_it, cell_iterator cell_it)
Definition: HashGrid.h:208
const ConstIterator operator++(int)
Definition: HashGrid.h:225
bool operator!=(const ConstIterator &rhs) const
Definition: HashGrid.h:235
const Grid & grid_
Definition: HashGrid.h:181
const CellIndex index() const
Definition: HashGrid.h:244
grid_iterator grid_it_
Definition: HashGrid.h:182
bool operator==(const ConstIterator &rhs) const
Definition: HashGrid.h:232
Grid::const_iterator grid_iterator
Definition: HashGrid.h:178
ConstIterator & operator++()
Definition: HashGrid.h:218
const value_type * operator->() const
Definition: HashGrid.h:241
cell_iterator cell_it_
Definition: HashGrid.h:183
ConstIterator(const Iterator &it)
Definition: HashGrid.h:214
const value_type & operator*() const
Definition: HashGrid.h:238
ConstIterator(const Grid &grid)
Definition: HashGrid.h:204
CellContent::const_iterator cell_iterator
Definition: HashGrid.h:179
void searchNextCell_()
Definition: HashGrid.h:186
Element iterator for the hash grid.
Definition: HashGrid.h:96
value_type & operator*() const
Definition: HashGrid.h:156
CellContent::iterator cell_iterator
Definition: HashGrid.h:101
const CellIndex index() const
Definition: HashGrid.h:162
grid_iterator grid_it_
Definition: HashGrid.h:104
Grid::iterator grid_iterator
Definition: HashGrid.h:100
bool operator==(const Iterator &rhs) const
Definition: HashGrid.h:150
cell_iterator cell_it_
Definition: HashGrid.h:105
Iterator(Grid &grid, grid_iterator grid_it, cell_iterator cell_it)
Definition: HashGrid.h:130
Grid & grid_
Definition: HashGrid.h:103
Iterator(Grid &grid)
Definition: HashGrid.h:126
bool operator!=(const Iterator &rhs) const
Definition: HashGrid.h:153
void searchNextCell_()
Definition: HashGrid.h:108
const Iterator operator++(int)
Definition: HashGrid.h:143
Iterator & operator++()
Definition: HashGrid.h:136
value_type * operator->() const
Definition: HashGrid.h:159
Container for (2-dimensional coordinate, value) pairs.
Definition: HashGrid.h:63
CellContent::const_iterator const_cell_iterator
Definition: HashGrid.h:256
grid_iterator grid_end()
Definition: HashGrid.h:425
CellIndex cellindexAtClustercenter_(const ClusterCenter &key)
Definition: HashGrid.h:429
boost::unordered_multimap< ClusterCenter, Cluster > CellContent
Contents of a cell.
Definition: HashGrid.h:79
const CellIndex & grid_dimension
Upper-right corner of key space for cells.
Definition: HashGrid.h:274
Grid::const_iterator const_grid_iterator
Definition: HashGrid.h:254
CellIndex grid_dimension_
Definition: HashGrid.h:262
Iterator iterator
Definition: HashGrid.h:253
const_iterator begin() const
Returns iterator to first element.
Definition: HashGrid.h:339
CellContent::iterator cell_iterator
Definition: HashGrid.h:257
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:410
const_grid_iterator grid_end() const
Returns iterator to on after last grid cell.
Definition: HashGrid.h:395
DPosition< 2, Int64 > CellIndex
Index for cells.
Definition: HashGrid.h:74
DPosition< 2, double > ClusterCenter
Coordinate for stored pairs.
Definition: HashGrid.h:69
boost::unordered_map< CellIndex, CellContent > Grid
Map of (cell-index, cell-content).
Definition: HashGrid.h:84
cell_iterator insert(const value_type &v)
Inserts a (2-dimensional coordinate, value) pair.
Definition: HashGrid.h:289
ConstIterator const_iterator
Definition: HashGrid.h:252
size_type size() const
Return number of elements.
Definition: HashGrid.h:375
CellContent::value_type value_type
Definition: HashGrid.h:88
bool empty() const
Return true if HashGrid is empty.
Definition: HashGrid.h:367
Grid cells_
Definition: HashGrid.h:261
CellContent::size_type size_type
Definition: HashGrid.h:258
Grid::iterator grid_iterator
Definition: HashGrid.h:255
HashGrid(const ClusterCenter &c_dimension)
Definition: HashGrid.h:277
grid_iterator grid_find(const CellIndex &x)
Returns the grid cell at given index if present, otherwise the grid_end iterator.
Definition: HashGrid.h:415
CellContent::key_type key_type
Definition: HashGrid.h:86
void updateGridDimension_(const CellIndex &d)
Definition: HashGrid.h:443
grid_iterator grid_begin()
Definition: HashGrid.h:421
void clear()
Clears the map.
Definition: HashGrid.h:322
const Grid::mapped_type & grid_at(const CellIndex &x) const
Returns the grid cell at given index.
Definition: HashGrid.h:400
iterator end()
Returns iterator to first element.
Definition: HashGrid.h:351
const_iterator end() const
Returns iterator to first element.
Definition: HashGrid.h:359
void erase(iterator pos)
Erases element on given iterator.
Definition: HashGrid.h:300
const ClusterCenter cell_dimension
Dimension of cells.
Definition: HashGrid.h:269
Grid::mapped_type & grid_at(const CellIndex &x)
Definition: HashGrid.h:405
iterator begin()
Returns iterator to first element.
Definition: HashGrid.h:327
const_grid_iterator grid_begin() const
Returns iterator to first grid cell.
Definition: HashGrid.h:390
size_type erase(const key_type &key)
Erases elements matching the 2-dimensional coordinate.
Definition: HashGrid.h:311
CellContent::mapped_type mapped_type
Definition: HashGrid.h:87
OPENMS_INT64_TYPE Int64
Signed integer type (64bit)
Definition: Types.h:70
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
std::size_t hash_value(const DPosition< N, T > &b)
Definition: HashGrid.h:458