18 #ifndef ION_BASE_INDEXMAP_H_
19 #define ION_BASE_INDEXMAP_H_
39 template <
typename OrderedIndexType,
typename UnorderedIndexType>
47 IndexMap(
const UnorderedIndexType unordered_indices[],
size_t count)
48 : unordered_indices_(unordered_indices),
57 DCHECK_LE(0, static_cast<int>(ordered_index));
58 DCHECK_GT(count_, static_cast<size_t>(ordered_index));
59 return unordered_indices_[ordered_index];
66 int ordered_index = -1;
67 for (
size_t i = 0; i < count_; ++i) {
68 if (unordered_indices_[i] == unordered_index) {
69 ordered_index =
static_cast<int>(i);
73 DCHECK_GE(ordered_index, 0) <<
"IndexMap: Invalid unordered index "
74 << unordered_index <<
" does not match any "
76 return static_cast<OrderedIndexType
>(ordered_index);
80 const UnorderedIndexType* unordered_indices_;
87 #endif // ION_BASE_INDEXMAP_H_
size_t GetCount() const
Returns the count passed to the constructor.
OrderedIndexType GetOrderedIndex(UnorderedIndexType unordered_index) const
Returns the OrderedIndexType corresponding to the given UnorderedIndexType value. ...
#define DCHECK_GT(val1, val2)
UnorderedIndexType GetUnorderedIndex(OrderedIndexType ordered_index) const
Returns the UnorderedIndexType corresponding to the given OrderedIndexType value. ...
This template class can be used to map between two kinds of indices when the following assumptions ap...
#define DCHECK_GE(val1, val2)
Copyright 2016 Google Inc.
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-b...
#define DCHECK_LE(val1, val2)