FE 0.17.1
Fast, Effecient FrontEnds
Loading...
Searching...
No Matches
fe::BiMap< L, R, LHash, LEq, RHash, REq > Class Template Reference

A bijection between L and R, kept as one ankerl::unordered_dense::map per direction. More...

#include <fe/bimap.h>

Public Types

using Left = ankerl::unordered_dense::map<L, R, LHash, LEq>
using Right = ankerl::unordered_dense::map<R, L, RHash, REq>

Public Member Functions

Getters
const Left & left () const noexcept
const Right & right () const noexcept
size_t size () const noexcept
bool empty () const noexcept
auto begin () const noexcept
auto end () const noexcept
Lookup

at_left() and at_right() throw std::out_of_range if the key is unbound.

bool contains_left (const auto &l) const
bool contains_right (const auto &r) const
const R & at_left (const auto &l) const
const L & at_right (const auto &r) const
Modifiers

They take their arguments by value, so a reference into this BiMap cannot dangle halfway through.

bool insert (L l, R r)
 Binds l to r unless either is already bound; yields whether it did.
void insert_or_assign (L l, R r)
 Binds l to r after unbinding whatever either was bound to.
bool erase_left (const auto &l)
 Unbinds l and its partner; yields whether l was bound.
bool erase_right (const auto &r)
 Unbinds r and its partner; yields whether r was bound.
void reserve (size_t n)
void clear () noexcept

Friends

bool operator== (const BiMap &a, const BiMap &b)

Detailed Description

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
class fe::BiMap< L, R, LHash, LEq, RHash, REq >

A bijection between L and R, kept as one ankerl::unordered_dense::map per direction.

Look up through left() and right(); a transparent hasher and equality enable heterogeneous lookup there as well. Iterating a BiMap yields its std::pair<L, R>s in left() order.

Note
Every pair is stored once per direction, so keep L and R cheap to copy - a Sym or a pointer, say. Otherwise, or if you need a pair's address to survive an insert, use BiNodeMap.

Definition at line 37 of file bimap.h.

Member Typedef Documentation

◆ Left

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
using fe::BiMap< L, R, LHash, LEq, RHash, REq >::Left = ankerl::unordered_dense::map<L, R, LHash, LEq>

Definition at line 39 of file bimap.h.

◆ Right

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
using fe::BiMap< L, R, LHash, LEq, RHash, REq >::Right = ankerl::unordered_dense::map<R, L, RHash, REq>

Definition at line 40 of file bimap.h.

Member Function Documentation

◆ at_left()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
const R & fe::BiMap< L, R, LHash, LEq, RHash, REq >::at_left ( const auto & l) const
inlinenodiscard

Definition at line 57 of file bimap.h.

◆ at_right()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
const L & fe::BiMap< L, R, LHash, LEq, RHash, REq >::at_right ( const auto & r) const
inlinenodiscard

Definition at line 58 of file bimap.h.

◆ begin()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
auto fe::BiMap< L, R, LHash, LEq, RHash, REq >::begin ( ) const
inlinenodiscardnoexcept

Definition at line 48 of file bimap.h.

◆ clear()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
void fe::BiMap< L, R, LHash, LEq, RHash, REq >::clear ( )
inlinenoexcept

Definition at line 101 of file bimap.h.

◆ contains_left()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
bool fe::BiMap< L, R, LHash, LEq, RHash, REq >::contains_left ( const auto & l) const
inlinenodiscard

Definition at line 55 of file bimap.h.

◆ contains_right()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
bool fe::BiMap< L, R, LHash, LEq, RHash, REq >::contains_right ( const auto & r) const
inlinenodiscard

Definition at line 56 of file bimap.h.

◆ empty()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
bool fe::BiMap< L, R, LHash, LEq, RHash, REq >::empty ( ) const
inlinenodiscardnoexcept

Definition at line 47 of file bimap.h.

◆ end()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
auto fe::BiMap< L, R, LHash, LEq, RHash, REq >::end ( ) const
inlinenodiscardnoexcept

Definition at line 49 of file bimap.h.

◆ erase_left()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
bool fe::BiMap< L, R, LHash, LEq, RHash, REq >::erase_left ( const auto & l)
inline

Unbinds l and its partner; yields whether l was bound.

Definition at line 79 of file bimap.h.

Referenced by insert_or_assign().

◆ erase_right()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
bool fe::BiMap< L, R, LHash, LEq, RHash, REq >::erase_right ( const auto & r)
inline

Unbinds r and its partner; yields whether r was bound.

Definition at line 88 of file bimap.h.

Referenced by insert_or_assign().

◆ insert()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
bool fe::BiMap< L, R, LHash, LEq, RHash, REq >::insert ( L l,
R r )
inline

Binds l to r unless either is already bound; yields whether it did.

Definition at line 66 of file bimap.h.

◆ insert_or_assign()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
void fe::BiMap< L, R, LHash, LEq, RHash, REq >::insert_or_assign ( L l,
R r )
inline

Binds l to r after unbinding whatever either was bound to.

Definition at line 72 of file bimap.h.

References erase_left(), and erase_right().

◆ left()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
const Left & fe::BiMap< L, R, LHash, LEq, RHash, REq >::left ( ) const
inlinenodiscardnoexcept

Definition at line 44 of file bimap.h.

◆ reserve()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
void fe::BiMap< L, R, LHash, LEq, RHash, REq >::reserve ( size_t n)
inline

Definition at line 96 of file bimap.h.

◆ right()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
const Right & fe::BiMap< L, R, LHash, LEq, RHash, REq >::right ( ) const
inlinenodiscardnoexcept

Definition at line 45 of file bimap.h.

◆ size()

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
size_t fe::BiMap< L, R, LHash, LEq, RHash, REq >::size ( ) const
inlinenodiscardnoexcept

Definition at line 46 of file bimap.h.

◆ operator==

template<class L, class R, class LHash = ankerl::unordered_dense::hash<L>, class LEq = std::equal_to<L>, class RHash = ankerl::unordered_dense::hash<R>, class REq = std::equal_to<R>>
bool operator== ( const BiMap< L, R, LHash, LEq, RHash, REq > & a,
const BiMap< L, R, LHash, LEq, RHash, REq > & b )
friend

Definition at line 107 of file bimap.h.


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