Skip to content

Commit

Permalink
Bring Bimap API closer to Lopmap
Browse files Browse the repository at this point in the history
  • Loading branch information
oblivioncth committed Dec 16, 2024
1 parent 025240a commit 933e701
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 9 deletions.
13 changes: 11 additions & 2 deletions lib/core/include/qx/core/qx-bimap.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@ class Bimap

//-Aliases------------------------------------------------------------------------------------------------------
public:
using iterator = const_iterator;
using left_type = Left;
using right_type = Right;
using ConstIterator = const_iterator;
using difference_type = typename QHash<Left, const Right*>::difference_type;
using size_type = typename QHash<Left, const Right*>::size_type;

//-Instance Variables-------------------------------------------------------------------------------------------
private:
Expand Down Expand Up @@ -193,9 +196,11 @@ class Bimap
}

public:
iterator begin() { return iterator(mL2R.begin()); }
const_iterator begin() const { return constBegin(); }
const_iterator cbegin() const { return constBegin(); }
const_iterator constBegin() const { return const_iterator(mL2R.cbegin()); }
iterator end() { return iterator(mL2R.end()); }
const_iterator end() const { return constEnd(); }
const_iterator cend() const { return constEnd(); }
const_iterator constEnd() const { return const_iterator(mL2R.cend()); }
Expand All @@ -209,10 +214,14 @@ class Bimap
return const_iterator(rItr != mR2L.cend() ? mL2R.constFind(*(*rItr)) : mL2R.cend());
}

iterator find(const Left& l) requires asymmetric_bimap<Left, Right> { return findLeft(l); }
const_iterator find(const Left& l) const requires asymmetric_bimap<Left, Right> { return findLeft(l); }
iterator find(const Right& r) requires asymmetric_bimap<Left, Right> { return findRight(r); }
const_iterator find(const Right& r) const requires asymmetric_bimap<Left, Right> { return findRight(r); }
const_iterator findLeft(const Left& l) const { return const_iterator(constFindLeft(l)); }
const_iterator findRight(const Right& r) const { return const_iterator(constFindRight(r)); }
iterator findLeft(const Left& l) { return iterator(constFindLeft(l)); }
const_iterator findLeft(const Left& l) const { return iterator(constFindLeft(l)); }
iterator findRight(const Right& r) { return iterator(constFindRight(r)); }
const_iterator findRight(const Right& r) const { return iterator(constFindRight(r)); }

const_iterator erase(const_iterator pos)
{
Expand Down
71 changes: 64 additions & 7 deletions lib/core/src/qx-bimap.dox
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@ namespace Qx
* 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.
*/

//-Aliases--------------------------------------------------------------------------------------------------
//Public:
/*!
* @typedef Bimap<Left, Right>::iterator
*
* Typedef for const_iterator.
*/

/*!
* @typedef Bimap<Left, Right>::left_type
*
Expand All @@ -67,6 +76,18 @@ namespace Qx
* Qt-style synonym for Bimap::const_iterator.
*/

/*!
* @typedef Bimap<Left, Right>::difference_type
*
* Typedef for ptrdiff_t. Provided for STL compatibility.
*/

/*!
* @typedef Bimap<Left, Right>::size_type
*
* Typedef for int. Provided for STL compatibility.
*/

//-Constructor----------------------------------------------------------------------------------------------
//Public:
/*!
Expand All @@ -86,11 +107,17 @@ namespace Qx
//-Instance Functions----------------------------------------------------------------------------------------------
//Public:
/*!
* @fn const_iterator Bimap<Left, Right>::begin() const
* @fn iterator Bimap<Left, Right>::begin()
*
* Same as constBegin().
*/

/*!
* @fn const_iterator Bimap<Left, Right>::begin() const
*
* @overload
*/

/*!
* @fn const_iterator Bimap<Left, Right>::cbegin() const
*
Expand All @@ -109,11 +136,17 @@ namespace Qx
*/

/*!
* @fn const_iterator Bimap<Left, Right>::end() const
* @fn iterator Bimap<Left, Right>::end()
*
* Same as constEnd().
*/

/*!
* @fn const_iterator Bimap<Left, Right>::end() const
*
* @overload
*/

/*!
* @fn const_iterator Bimap<Left, Right>::cend() const
*
Expand All @@ -123,7 +156,7 @@ namespace Qx
/*!
* @fn const_iterator Bimap<Left, Right>::constEnd() const
*
* Returns an STL-style iterator pointing to the first relationship in the bimap.
* Returns an STL-style iterator pointing to the last relationship in the bimap.
*
* @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.
Expand Down Expand Up @@ -166,29 +199,53 @@ namespace Qx
*/

/*!
* @fn const_iterator Bimap<Left, Right>::find(const Left& l) const
* @fn iterator Bimap<Left, Right>::find(const Left& l)
*
* Same as constFindLeft().
*/

/*!
* @fn const_iterator Bimap<Left, Right>::find(const Right& l) const
* @fn const_iterator Bimap<Left, Right>::find(const Left& l) const
*
* @overload
*/

/*!
* @fn iterator Bimap<Left, Right>::find(const Right& r)
*
* Same as constFindRight().
*/

/*!
* @fn const_iterator Bimap<Left, Right>::findLeft(const Left& l) const
* @fn const_iterator Bimap<Left, Right>::find(const Right& r) const
*
* @overload
*/

/*!
* @fn iterator Bimap<Left, Right>::findLeft(const Left& r)
*
* Same as constFindLeft().
*/

/*!
* @fn const_iterator Bimap<Left, Right>::findRight(const Right& l) const
* @fn const_iterator Bimap<Left, Right>::findLeft(const Left& r) const
*
* @overload
*/

/*!
* @fn iterator Bimap<Left, Right>::findRight(const Right& r)
*
* Same as constFindRight().
*/

/*!
* @fn const_iterator Bimap<Left, Right>::findRight(const Right& r) const
*
* @overload
*/

/*!
* @fn const_iterator Bimap<Left, Right>::erase(const_iterator pos)
*
Expand Down

0 comments on commit 933e701

Please sign in to comment.