Speclib  0.1.2
The library for writing better CUDA libraries
sp::c::IntMap< KeyType, ValueType, KeyBits > Class Template Referencefinal

Like std::map, but for compile-time use. More...

#include <IntMap.hpp>

Public Types

using iterator = Iterator< ValueType >
 
using const_iterator = Iterator< const ValueType >
 

Public Member Functions

constexpr IntMap (const std::initializer_list< std::pair< KeyType, ValueType > > &init)
 
constexpr bool operator== (const IntMap &other) const
 
constexpr bool operator!= (const IntMap &other) const
 
constexpr ValueType & operator[] (KeyType i)
 
constexpr const ValueType & operator[] (KeyType i) const
 
constexpr ValueType & at (KeyType i)
 
constexpr const ValueType & at (KeyType i) const
 
constexpr iterator begin ()
 
constexpr iterator end ()
 
constexpr const_iterator begin () const
 
constexpr const_iterator end () const
 
constexpr iterator lower_bound (KeyType i)
 
constexpr iterator upper_bound (KeyType i)
 
constexpr const_iterator lower_bound (KeyType i) const
 
constexpr const_iterator upper_bound (KeyType i) const
 
constexpr uint64_t empty () const
 
constexpr uint64_t size () const
 
constexpr int count (KeyType i) const
 
constexpr bool contains (KeyType i) const
 
constexpr void insert (sp::Pair< KeyType, ValueType > p)
 
constexpr void erase (KeyType i)
 
template<typename Fn >
constexpr void map (const Fn &fn)
 Apply a map function to the values in the IntMap. More...
 
template<typename Result , typename Fn >
constexpr Result reduce (const Fn &fn, Result initialResult={})
 Apply a reduce function to the values in the IntMap. More...
 
constexpr const IntSet< KeyType, KeyBits > & keySet ()
 

Public Attributes

IntSet< KeyType, KeyBits > keys
 

Detailed Description

template<typename KeyType, typename ValueType, int KeyBits = sizeof(KeyType) * 8>
class sp::c::IntMap< KeyType, ValueType, KeyBits >

Like std::map, but for compile-time use.

Unlike std::map, access and update operations are constant-time.

Note
Like all structures in the sp::c namespace, this cannot be used at runtime.
Template Parameters
KeyTypeThe key type of the map. This must be a fundamental integer type.
ValueTypeThe value type of the map. Must be default constexpr constructible and constexpr copyable, or a fundamental data type.
KeyBitsThe number of bits in the key to use. The default is the size needed to store any value of KeyType. This template parameter is useful to limit the address space used by the container (e.g: to nest containers). For unsigned integers, the minimum value is 0 and the maximum value is 2^KeyBits - 1. For signed integers, the minimum value is -2^(KeyBits - 1) and the maximum is 2^(KeyBits - 1) - 1. This must be at least 0, and at most sizeof(KeyType) * 8.

Member Function Documentation

◆ map()

template<typename KeyType , typename ValueType , int KeyBits = sizeof(KeyType) * 8>
template<typename Fn >
constexpr void sp::c::IntMap< KeyType, ValueType, KeyBits >::map ( const Fn &  fn)
constexpr

Apply a map function to the values in the IntMap.

Template Parameters
FnThe type of the function. The function must accept two arguments: (KeyType, ValueType &). The second argument is a reference to the value in the map, so this is where the mapped value should be written.
Parameters
fnThe function object. This can be a function pointer, or an object with operator().

◆ reduce()

template<typename KeyType , typename ValueType , int KeyBits = sizeof(KeyType) * 8>
template<typename Result , typename Fn >
constexpr Result sp::c::IntMap< KeyType, ValueType, KeyBits >::reduce ( const Fn &  fn,
Result  initialResult = {} 
)
constexpr

Apply a reduce function to the values in the IntMap.

Template Parameters
ResultThe type of the result (also used as the accumulator).
FnThe type of the function. The function must accept three arguments: (Result &, KeyType, ValueType). The third argument is the accumulator to write to.
Parameters
fnThe function object. This can be a function pointer, or an object with operator().
initialResultThe result to use before any elements of the IntMap have been processed.
Returns
The result of the reduction.