Template Class PositionIndex

Nested Relationships

Nested Types

Class Documentation

template<class T, class H = FastHash<const T*>>
class PositionIndex

the positions of objects of type T, by their addresses

Public Types

using Position = std::uint32_t

the type of the positions

Public Functions

inline explicit PositionIndex(std::size_t n = 0, H h = H())

an empty index with room for n keys

Position find(const T *p) const

the position of p, NONE if absent

bool contains(const T *p) const

true if p is in the index

bool insert(const T *p, Position i)

gives p the position i; true if p was absent, false if its position was replaced

Pre:

p is not nil and i < NONE

bool erase(const T *p)

removes p; false if it was absent

template<std::ranges::random_access_range R>
void assign(const R &v)

the index of the vector v of pointers (any range with v[ i ]): v[ i ] at the position i, all the other keys gone

Pre:

no v[ i ] is nil, and v has fewer than NONE items

void renumber(std::span<const Position> E)

the erasure of the positions E from the vector: the keys at a position in E go away, and each other position p becomes p minus the number of the positions of E below p

Pre:

E is strictly increasing

inline std::size_t size(void) const

the number of keys

inline bool empty(void) const
inline std::size_t capacity(void) const

the number of places of the table

inline void reserve(std::size_t n)

room for n keys with no rebuild

inline void clear(void)

removes all the keys, keeping the places

template<class F>
inline void forEach(F &&f) const

f( p , i ) for each key p at the position i, in the order of the places

inline void swap(PositionIndex &o) noexcept

Public Static Attributes

static constexpr Position NONE = std::numeric_limits<Position>::max()

the position of a key absent