Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::base::IndexMap< OrderedIndexType, UnorderedIndexType > Class Template Reference

This template class can be used to map between two kinds of indices when the following assumptions apply: More...

#include "indexmap.h"

Inheritance diagram for ion::base::IndexMap< OrderedIndexType, UnorderedIndexType >:

Public Member Functions

 IndexMap (const UnorderedIndexType unordered_indices[], size_t count)
 The map is initialized with an array of N UnorderedIndexType values that directly correspond to a 0-based array of OrderedIndexType, in the same order. More...
 
size_t GetCount () const
 Returns the count passed to the constructor. More...
 
UnorderedIndexType GetUnorderedIndex (OrderedIndexType ordered_index) const
 Returns the UnorderedIndexType corresponding to the given OrderedIndexType value. More...
 
OrderedIndexType GetOrderedIndex (UnorderedIndexType unordered_index) const
 Returns the OrderedIndexType corresponding to the given UnorderedIndexType value. More...
 

Detailed Description

template<typename OrderedIndexType, typename UnorderedIndexType>
class ion::base::IndexMap< OrderedIndexType, UnorderedIndexType >

This template class can be used to map between two kinds of indices when the following assumptions apply:

  • There are N potential values for both types of index.
  • The N values of OrderedIndexType range from 0 to N-1 and are presented in order.
  • The N values of UnorderedIndexType are in an unspecified range and may or may not be presented in order.

Mapping from an OrderedIndexType to an UnorderedIndexType is constant-time, while mapping the other way around is linear.

This class is very light-weight and is intended to be constructed as a temporary variable when needed.

Definition at line 40 of file indexmap.h.

Constructor & Destructor Documentation

template<typename OrderedIndexType, typename UnorderedIndexType>
ion::base::IndexMap< OrderedIndexType, UnorderedIndexType >::IndexMap ( const UnorderedIndexType  unordered_indices[],
size_t  count 
)
inline

The map is initialized with an array of N UnorderedIndexType values that directly correspond to a 0-based array of OrderedIndexType, in the same order.

It is assumed that the lifetime of the passed array is at least as long as the IndexMap instance's, since the IndexMap does not copy the array values.

Definition at line 47 of file indexmap.h.

Member Function Documentation

template<typename OrderedIndexType, typename UnorderedIndexType>
size_t ion::base::IndexMap< OrderedIndexType, UnorderedIndexType >::GetCount ( ) const
inline

Returns the count passed to the constructor.

Definition at line 52 of file indexmap.h.

template<typename OrderedIndexType, typename UnorderedIndexType>
OrderedIndexType ion::base::IndexMap< OrderedIndexType, UnorderedIndexType >::GetOrderedIndex ( UnorderedIndexType  unordered_index) const
inline

Returns the OrderedIndexType corresponding to the given UnorderedIndexType value.

This is a linear-time operation. This will DCHECK if the index is not found.

Definition at line 65 of file indexmap.h.

template<typename OrderedIndexType, typename UnorderedIndexType>
UnorderedIndexType ion::base::IndexMap< OrderedIndexType, UnorderedIndexType >::GetUnorderedIndex ( OrderedIndexType  ordered_index) const
inline

Returns the UnorderedIndexType corresponding to the given OrderedIndexType value.

This is a constant-time operation.

Definition at line 56 of file indexmap.h.


The documentation for this class was generated from the following file: