Speclib  0.1.2
The library for writing better CUDA libraries
sp::BitfieldMap< KeyBits, Members > Class Template Reference

An associative container backed by a sorted list of integers. More...

#include <BitfieldMap.hpp>

Public Types

using ValueType = typename Members::ValueType
 
using ThisType = BitfieldMap< KeyBits, Members >
 
using AsList = Members
 
template<ValueType NewMapping>
using put = decltype(putHelper< NewMapping >())
 Add a new mapping. More...
 
template<ValueType Key, int KB = KeyBits>
using erase = decltype(eraseHelper< Key, KB >())
 Remove mappings with keys prefixed by the top KB bits of Key. If KB == KeyBits, at most one removal occurs. More...
 
template<typename OtherMap >
using copyFrom = BitfieldMap< KeyBits, decltype(BitfieldMapCopyFromHelper< KeyBits >(AsList{}, typename OtherMap::AsList{}, sp::make_int_sequence< Size+OtherMap::Size >{}))>
 Copy mappings from OtherMap into this one, overwriting any that already exist. More...
 
template<typename Lambda >
using map = BitfieldMap< KeyBits, typename Members::template map< Lambda > >
 Functional map, applied to the underlying list. More...
 

Static Public Member Functions

template<int KB = KeyBits>
constexpr static int lookupKey (ValueType Key)
 Find a (unique) key in the map, or -1 if it doesn't exist. More...
 
template<int KB = KeyBits>
static constexpr ValueType keyToMapping (ValueType Key)
 
template<int KB = KeyBits>
static constexpr bool containsKey (ValueType I)
 Determine if any values with the specified key prefix are present. More...
 
static constexpr ValueType get (ValueType I)
 Get the single value mapped by the key prefix of the input. More...
 
template<ValueType NewMapping>
static constexpr auto putHelper ()
 
template<ValueType KeyValue, int KB>
static constexpr auto eraseHelper ()
 

Static Public Attributes

constexpr static int ValueBits = sizeof(ValueType) * 8
 
constexpr static int Size = Members::Size
 
constexpr static bool Empty = Size == 0
 

Detailed Description

template<int KeyBits, typename Members>
class sp::BitfieldMap< KeyBits, Members >

An associative container backed by a sorted list of integers.

The KeyBits most significant bits of each element determines its key, and the remainder is the value. For read or erase operations, you may specify a smaller number of bits to use for keying, allowing you to treat this structure as a map of maps. You can extract the range of elements with keys that share a prefix.

To avoid corruption of the structure, insertions always use exactly KeyBits-many key bits.

Member Typedef Documentation

◆ copyFrom

template<int KeyBits, typename Members >
template<typename OtherMap >
using sp::BitfieldMap< KeyBits, Members >::copyFrom = BitfieldMap<KeyBits, decltype(BitfieldMapCopyFromHelper<KeyBits> (AsList{}, typename OtherMap::AsList{}, sp::make_int_sequence<Size + OtherMap::Size>{}))>

Copy mappings from OtherMap into this one, overwriting any that already exist.

◆ erase

template<int KeyBits, typename Members >
template<ValueType Key, int KB = KeyBits>
using sp::BitfieldMap< KeyBits, Members >::erase = decltype(eraseHelper<Key, KB>())

Remove mappings with keys prefixed by the top KB bits of Key. If KB == KeyBits, at most one removal occurs.

◆ map

template<int KeyBits, typename Members >
template<typename Lambda >
using sp::BitfieldMap< KeyBits, Members >::map = BitfieldMap<KeyBits, typename Members::template map<Lambda> >

Functional map, applied to the underlying list.

◆ put

template<int KeyBits, typename Members >
template<ValueType NewMapping>
using sp::BitfieldMap< KeyBits, Members >::put = decltype(putHelper<NewMapping>())

Add a new mapping.

Member Function Documentation

◆ containsKey()

template<int KeyBits, typename Members >
template<int KB = KeyBits>
static constexpr bool sp::BitfieldMap< KeyBits, Members >::containsKey ( ValueType  I)
staticconstexpr

Determine if any values with the specified key prefix are present.

◆ get()

template<int KeyBits, typename Members >
static constexpr ValueType sp::BitfieldMap< KeyBits, Members >::get ( ValueType  I)
staticconstexpr

Get the single value mapped by the key prefix of the input.

◆ lookupKey()

template<int KeyBits, typename Members >
template<int KB = KeyBits>
constexpr static int sp::BitfieldMap< KeyBits, Members >::lookupKey ( ValueType  Key)
staticconstexpr

Find a (unique) key in the map, or -1 if it doesn't exist.