|
| Bimap () |
|
| Bimap (std::initializer_list< std::pair< Left, Right > > list) |
|
iterator | begin () |
|
const_iterator | begin () const |
|
qsizetype | capacity () const |
|
const_iterator | cbegin () const |
|
const_iterator | cend () const |
|
void | clear () |
|
const_iterator | constBegin () const |
|
const_iterator | constEnd () const |
|
const_iterator | constFind (const Left &l) const |
|
const_iterator | constFind (const Right &r) const |
|
const_iterator | constFindLeft (const Left &l) const |
|
const_iterator | constFindRight (const Right &r) const |
|
bool | containsLeft (const Left &l) const |
|
bool | containsRight (const Right &r) const |
|
qsizetype | count () const |
|
bool | empty () const |
|
iterator | end () |
|
const_iterator | end () const |
|
const_iterator | erase (const_iterator pos) |
|
iterator | find (const Left &l) |
|
const_iterator | find (const Left &l) const |
|
iterator | find (const Right &r) |
|
const_iterator | find (const Right &r) const |
|
iterator | findLeft (const Left &l) |
|
const_iterator | findLeft (const Left &l) const |
|
iterator | findRight (const Right &r) |
|
const_iterator | findRight (const Right &r) const |
|
Right | from (const Left &l) const |
|
Right | from (const Left &l, const Right &defaultValue) const |
|
Left | from (const Right &r) const |
|
Left | from (const Right &r, const Left &defaultValue) const |
|
Right | fromLeft (const Left &l) const |
|
Right | fromLeft (const Left &l, const Right &defaultValue) const |
|
Left | fromRight (const Right &l) const |
|
Left | fromRight (const Right &l, const Left &defaultValue) const |
|
void | insert (const Bimap &other) |
|
const_iterator | insert (const Left &l, const Right &r) |
|
bool | isEmpty () const |
|
QList< Left > | lefts () const |
|
float | load_factor () const |
|
bool | operator!= (const Bimap &other) const =default |
|
bool | operator== (const Bimap &other) const |
|
Right | operator[] (const Left &l) const |
|
Left | operator[] (const Right &r) const |
|
QList< std::pair< Left, Right > > | relationships () const |
|
bool | remove (const Left &l) |
|
bool | remove (const Right &r) |
|
template<typename Predicate >
requires bimap_predicate<Left, Right, Predicate> |
qsizetype | removeIf (Predicate pred) |
|
bool | removeLeft (const Left &l) |
|
bool | removeRight (const Right &r) |
|
void | reserve (qsizetype size) |
|
QList< Right > | rights () const |
|
qsizetype | size () const |
|
void | squeeze () |
|
void | swap (Bimap< Left, Right > &other) |
|
Right | take (const Left &l) |
|
Left | take (const Right &r) |
|
Left | takeLeft (const Right &r) |
|
Right | takeRight (const Left &l) |
|
Left | toLeft (const Right &r) const |
|
Left | toLeft (const Right &r, const Left &defaultValue) const |
|
Right | toRight (const Left &l) const |
|
Right | toRight (const Left &l, const Right &defaultValue) const |
|
template<typename Left, typename Right>
class Qx::Bimap< Left, Right >
Qx::Bimap<Left, Right> is like QHash<Key, T>, except that instead of Key and Value there is Left and Right, meaning that no neither type in any specialization of the container is more significant than the other. Lookup of one of the "side's" values using the other is possible via fromLeft(), fromRight(), and other similarly named functions.
iterator is simply an alias for const_iterator as values cannot be modified through bimap iterators due to technical limitations.
Both the Left and Right types must provide operator==() and a global qHash() overload.
template<typename Left , typename Right >
qsizetype Qx::Bimap< Left, Right >::capacity |
( |
| ) |
const |
|
inline |
Returns the number of buckets in the bimap's internal table.
The sole purpose of this function is to provide a means of fine tuning Bimap's memory usage. In general, you will rarely ever need to call this function. If you want to know how many items are in the bimap, call size().
- See also
- reserve() and squeeze().
template<typename Left , typename Right >
Right Qx::Bimap< Left, Right >::fromLeft |
( |
const Left & | l, |
|
|
const Right & | defaultValue ) const |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the Right value associated with Left value l.
If the bimap does not contain a relationship with l, defaultValue is returned.
template<typename Left , typename Right >
Left Qx::Bimap< Left, Right >::fromRight |
( |
const Right & | r, |
|
|
const Left & | defaultValue ) const |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the Left value associated with Right value r.
If the bimap does not contain a relationship with r, defaultValue is returned.
template<typename Left , typename Right >
void Qx::Bimap< Left, Right >::insert |
( |
const Bimap< Left, Right > & | other | ) |
|
|
inline |
Inserts all the relationships in the other bimap into this bimap.
If a Left or Right value from any relationship is common to both bimaps, the relationship containing then will be replaced with the relation that contains said value(s) stored in other.
template<typename Left , typename Right >
Inserts a new relationship between the Left value l and Right value r.
If there is already a relationship for either value, that relationship is removed, effectively replacing it with the new relationship.
Returns an iterator pointing to the new relationship.
- Warning
- Returned iterators/references should be considered invalidated the next time you call a non-const function on the bimap, or when the bimap is destroyed.
template<typename Left , typename Right >
float Qx::Bimap< Left, Right >::load_factor |
( |
| ) |
const |
|
inline |
Returns the current load factor of the Bimap's internal table. This is the same as capacity()/size(). The implementation used will aim to keep the load factor between 0.25 and 0.5. This avoids having too many table collisions that would degrade performance.
Even with a low load factor, the implementation of the bimap table has a very low memory overhead.
This method purely exists for diagnostic purposes and you should rarely need to call it yourself.
- See also
- reserve() and squeeze().
template<typename Left , typename Right >
bool Qx::Bimap< Left, Right >::operator!= |
( |
const Bimap< Left, Right > & | other | ) |
const |
|
default |
Returns true
if other is not equal to this bimap; otherwise, returns false
.
Two bimap's are considered equal if they contain the same (right, left) relationships.
This function requires the Right and Left types to implement operator==().
- See also
- operator==().
template<typename Left , typename Right >
bool Qx::Bimap< Left, Right >::operator== |
( |
const Bimap< Left, Right > & | other | ) |
const |
|
inline |
Returns true
if other is equal to this bimap; otherwise, returns false
.
Two bimap's are considered equal if they contain the same (right, left) relationships.
This function requires the Right and Left types to implement operator==().
- See also
- operator!=().
template<typename Left , typename Right >
template<typename Predicate >
requires bimap_predicate<Left, Right, Predicate>
qsizetype Qx::Bimap< Left, Right >::removeIf |
( |
Predicate | pred | ) |
|
|
inline |
Removes all elements for which the predicate pred returns true from the bimap.
The function supports predicates which take either an argument of type Bimap<Left, Right>::const_iterator, or an argument of type std::pair<const Left&, const Right&>.
Returns the number of elements removed, if any.
- See also
- clear() and take().
template<typename Left , typename Right >
void Qx::Bimap< Left, Right >::reserve |
( |
qsizetype | size | ) |
|
|
inline |
Ensures that the bimap's internal table has space to store at least size items without having to grow the table.
This function is useful for code that needs to build a huge bimap and wants to avoid repeated reallocation.
In general, you will rarely ever need to call this function. Bimap's internal table automatically grows to provide good performance without wasting too much memory.
- See also
- squeeze() and capacity().
template<typename Left , typename Right >
Left Qx::Bimap< Left, Right >::takeLeft |
( |
const Right & | r | ) |
|
|
inline |
Removes the relationship with the Right value r from the bimap and returns the Left value associated with it.
If such a relationship does not exist in the bimap, the function simply returns a default-constructed value
If you don't use the return value, remove() is more efficient.
- See also
- remove().
template<typename Left , typename Right >
Right Qx::Bimap< Left, Right >::takeRight |
( |
const Left & | l | ) |
|
|
inline |
Removes the relationship with the Left value l from the bimap and returns the Right value associated with it.
If such a relationship does not exist in the bimap, the function simply returns a default-constructed value
If you don't use the return value, remove() is more efficient.
- See also
- remove().