OpenMS
Loading...
Searching...
No Matches
HashGrid< Cluster > Class Template Reference

Container for (2-dimensional coordinate, value) pairs. More...

#include <OpenMS/ML/CLUSTERING/HashGrid.h>

Collaboration diagram for HashGrid< Cluster >:
[legend]

Classes

class  ConstIterator
 Constant element iterator for the hash grid. More...
 
class  Iterator
 Element iterator for the hash grid. More...
 

Public Types

typedef DPosition< 2, double > ClusterCenter
 Coordinate for stored pairs.
 
typedef DPosition< 2, Int64CellIndex
 Index for cells.
 
typedef boost::unordered_multimap< ClusterCenter, Cluster > CellContent
 Contents of a cell.
 
typedef boost::unordered_map< CellIndex, CellContentGrid
 Map of (cell-index, cell-content).
 
typedef CellContent::key_type key_type
 
typedef CellContent::mapped_type mapped_type
 
typedef CellContent::value_type value_type
 
typedef ConstIterator const_iterator
 
typedef Iterator iterator
 
typedef Grid::const_iterator const_grid_iterator
 
typedef Grid::iterator grid_iterator
 
typedef CellContent::const_iterator const_cell_iterator
 
typedef CellContent::iterator cell_iterator
 
typedef CellContent::size_type size_type
 

Public Member Functions

 HashGrid (const ClusterCenter &c_dimension)
 
cell_iterator insert (const value_type &v)
 Inserts a (2-dimensional coordinate, value) pair.
 
void erase (iterator pos)
 Erases element on given iterator.
 
size_type erase (const key_type &key)
 Erases elements matching the 2-dimensional coordinate.
 
void clear ()
 Clears the map.
 
iterator begin ()
 Returns iterator to first element.
 
const_iterator begin () const
 Returns iterator to first element.
 
iterator end ()
 Returns iterator to first element.
 
const_iterator end () const
 Returns iterator to first element.
 
bool empty () const
 Return true if HashGrid is empty.
 
size_type size () const
 Return number of elements.
 
const_grid_iterator grid_begin () const
 Returns iterator to first grid cell.
 
const_grid_iterator grid_end () const
 Returns iterator to on after last grid cell.
 
const Grid::mapped_type & grid_at (const CellIndex &x) const
 Returns the grid cell at given index.
 
Grid::mapped_type & grid_at (const CellIndex &x)
 
const_grid_iterator grid_find (const CellIndex &x) const
 Returns the grid cell at given index if present, otherwise the grid_end iterator.
 
grid_iterator grid_find (const CellIndex &x)
 Returns the grid cell at given index if present, otherwise the grid_end iterator.
 
grid_iterator grid_begin ()
 
grid_iterator grid_end ()
 
CellIndex cellIndexAtClusterCenter (const ClusterCenter &key) const
 Computes the cell index for a given cluster center coordinate.
 

Public Attributes

const ClusterCenter cell_dimension
 Dimension of cells.
 
const CellIndexgrid_dimension
 Upper-right corner of key space for cells.
 

Private Member Functions

void updateGridDimension_ (const CellIndex &d)
 

Private Attributes

Grid cells_
 
CellIndex grid_dimension_
 

Detailed Description

template<typename Cluster>
class OpenMS::HashGrid< Cluster >

Container for (2-dimensional coordinate, value) pairs.

A hash-grid consists of hash-grid cells. The key of each cell is a pair of integers. Each pair is assigned to a cell using a hash function.

This container implements most parts of the C++ standard map interface.

Template Parameters
ClusterType to be stored in the hash grid. (e.g. HierarchicalClustering::Cluster)

Member Typedef Documentation

◆ cell_iterator

template<typename Cluster >
typedef CellContent::iterator cell_iterator

◆ CellContent

template<typename Cluster >
typedef boost::unordered_multimap<ClusterCenter, Cluster> CellContent

Contents of a cell.

◆ CellIndex

template<typename Cluster >
typedef DPosition<2, Int64> CellIndex

Index for cells.

◆ ClusterCenter

template<typename Cluster >
typedef DPosition<2, double> ClusterCenter

Coordinate for stored pairs.

◆ const_cell_iterator

template<typename Cluster >
typedef CellContent::const_iterator const_cell_iterator

◆ const_grid_iterator

template<typename Cluster >
typedef Grid::const_iterator const_grid_iterator

◆ const_iterator

template<typename Cluster >
typedef ConstIterator const_iterator

◆ Grid

template<typename Cluster >
typedef boost::unordered_map<CellIndex, CellContent> Grid

Map of (cell-index, cell-content).

◆ grid_iterator

template<typename Cluster >
typedef Grid::iterator grid_iterator

◆ iterator

template<typename Cluster >
typedef Iterator iterator

◆ key_type

template<typename Cluster >
typedef CellContent::key_type key_type

◆ mapped_type

template<typename Cluster >
typedef CellContent::mapped_type mapped_type

◆ size_type

template<typename Cluster >
typedef CellContent::size_type size_type

◆ value_type

template<typename Cluster >
typedef CellContent::value_type value_type

Constructor & Destructor Documentation

◆ HashGrid()

template<typename Cluster >
HashGrid ( const ClusterCenter c_dimension)
inlineexplicit

Member Function Documentation

◆ begin() [1/2]

template<typename Cluster >
iterator begin ( )
inline

Returns iterator to first element.

References HashGrid< Cluster >::cells_, and HashGrid< Cluster >::end().

◆ begin() [2/2]

template<typename Cluster >
const_iterator begin ( ) const
inline

Returns iterator to first element.

References HashGrid< Cluster >::cells_, and HashGrid< Cluster >::end().

◆ cellIndexAtClusterCenter()

template<typename Cluster >
CellIndex cellIndexAtClusterCenter ( const ClusterCenter key) const
inline

Computes the cell index for a given cluster center coordinate.

Parameters
[in]keyCluster center coordinate
Returns
Cell index corresponding to the coordinate
Exceptions
Exception::OutOfRangeif computed cell index exceeds Int64 limits

References DPosition< D, TCoordinateType >::begin(), HashGrid< Cluster >::cell_dimension, and DPosition< D, TCoordinateType >::end().

Referenced by HashGrid< Cluster >::erase(), and HashGrid< Cluster >::insert().

◆ clear()

template<typename Cluster >
void clear ( )
inline

Clears the map.

References HashGrid< Cluster >::cells_.

◆ empty()

template<typename Cluster >
bool empty ( ) const
inline

Return true if HashGrid is empty.

References HashGrid< Cluster >::size().

◆ end() [1/2]

template<typename Cluster >
iterator end ( )
inline

Returns iterator to first element.

References HashGrid< Cluster >::cells_.

Referenced by HashGrid< Cluster >::begin(), and HashGrid< Cluster >::begin().

◆ end() [2/2]

template<typename Cluster >
const_iterator end ( ) const
inline

Returns iterator to first element.

References HashGrid< Cluster >::cells_.

◆ erase() [1/2]

template<typename Cluster >
size_type erase ( const key_type key)
inline

Erases elements matching the 2-dimensional coordinate.

Parameters
[in]keyKey of element to be erased.
Returns
Number of elements erased.

References HashGrid< Cluster >::cellIndexAtClusterCenter(), and HashGrid< Cluster >::cells_.

◆ erase() [2/2]

template<typename Cluster >
void erase ( iterator  pos)
inline

Erases element on given iterator.

References HashGrid< Cluster >::Iterator::cell_it_, and HashGrid< Cluster >::Iterator::grid_it_.

◆ grid_at() [1/2]

template<typename Cluster >
Grid::mapped_type & grid_at ( const CellIndex x)
inline
Warning
Currently needed non-const by HierarchicalClustering.

References HashGrid< Cluster >::cells_.

◆ grid_at() [2/2]

template<typename Cluster >
const Grid::mapped_type & grid_at ( const CellIndex x) const
inline

Returns the grid cell at given index.

References HashGrid< Cluster >::cells_.

◆ grid_begin() [1/2]

template<typename Cluster >
grid_iterator grid_begin ( )
inline
Warning
Currently needed non-const by HierarchicalClustering.

References HashGrid< Cluster >::cells_.

◆ grid_begin() [2/2]

template<typename Cluster >
const_grid_iterator grid_begin ( ) const
inline

Returns iterator to first grid cell.

References HashGrid< Cluster >::cells_.

Referenced by HashGrid< Cluster >::size().

◆ grid_end() [1/2]

template<typename Cluster >
grid_iterator grid_end ( )
inline
Warning
Currently needed non-const by HierarchicalClustering.

References HashGrid< Cluster >::cells_.

◆ grid_end() [2/2]

template<typename Cluster >
const_grid_iterator grid_end ( ) const
inline

Returns iterator to on after last grid cell.

References HashGrid< Cluster >::cells_.

Referenced by HashGrid< Cluster >::size().

◆ grid_find() [1/2]

template<typename Cluster >
grid_iterator grid_find ( const CellIndex x)
inline

Returns the grid cell at given index if present, otherwise the grid_end iterator.

References HashGrid< Cluster >::cells_.

◆ grid_find() [2/2]

template<typename Cluster >
const_grid_iterator grid_find ( const CellIndex x) const
inline

Returns the grid cell at given index if present, otherwise the grid_end iterator.

References HashGrid< Cluster >::cells_.

◆ insert()

template<typename Cluster >
cell_iterator insert ( const value_type v)
inline

Inserts a (2-dimensional coordinate, value) pair.

Parameters
[in]vPair to be inserted.
Returns
Iterator that points to the inserted pair.

References HashGrid< Cluster >::cellIndexAtClusterCenter(), HashGrid< Cluster >::cells_, and HashGrid< Cluster >::updateGridDimension_().

◆ size()

template<typename Cluster >
size_type size ( ) const
inline

Return number of elements.

References HashGrid< Cluster >::grid_begin(), and HashGrid< Cluster >::grid_end().

Referenced by HashGrid< Cluster >::empty().

◆ updateGridDimension_()

template<typename Cluster >
void updateGridDimension_ ( const CellIndex d)
inlineprivate

Member Data Documentation

◆ cell_dimension

template<typename Cluster >
const ClusterCenter cell_dimension

Dimension of cells.

Referenced by HashGrid< Cluster >::cellIndexAtClusterCenter().

◆ cells_

◆ grid_dimension

template<typename Cluster >
const CellIndex& grid_dimension

Upper-right corner of key space for cells.

◆ grid_dimension_

template<typename Cluster >
CellIndex grid_dimension_
private