- Fixed naming issue from copying set as multiset.h

This commit is contained in:
2025-08-17 11:55:53 -04:00
parent e6c0a60ea9
commit fcf9c6adcb

View File

@@ -22,7 +22,7 @@
// https://programming.guide/robin-hood-hashing.html
#include <fennec/containers/optional.h>
#include <fennec/containers/set.h>
#include <fennec/containers/multiset.h>
#include <fennec/lang/compare.h>
#include <fennec/math/ext/primes.h>
#include <fennec/memory/allocator.h>
@@ -33,9 +33,9 @@ namespace fennec
///
///
/// \brief wrapper for sets of elements
/// \brief wrapper for multisets of elements
/// \details
/// This data-structure behaves like a set, but does not use pointers, instead storing the table in-array
/// This data-structure behaves like a multiset, but does not use pointers, instead storing the table in-array
///
/// | Property | Value |
/// |:----------|:----------:|
@@ -47,7 +47,7 @@ namespace fennec
///
/// \tparam TypeT The type to contain
template<typename TypeT, class Hash = hash<TypeT>, class Equals = equality<TypeT>, class Alloc = allocator<TypeT>>
struct set {
struct multiset {
// Definitions =========================================================================================================
public:
@@ -74,8 +74,8 @@ private:
public:
///
/// \brief Default Constructor, initializes empty set
constexpr set()
/// \brief Default Constructor, initializes empty multiset
constexpr multiset()
: _alloc()
, _hash()
, _size(0)
@@ -84,8 +84,8 @@ public:
};
///
/// \brief Hash Copy Constructor, initializes empty set with a hash
constexpr set(const hash_t& hash)
/// \brief Hash Copy Constructor, initializes empty multiset with a hash
constexpr multiset(const hash_t& hash)
: _alloc()
, _hash(hash)
, _size(0)
@@ -94,8 +94,8 @@ public:
}
///
/// \brief Hash Move Constructor, initializes empty set with a hash
constexpr set(hash_t&& hash) noexcept
/// \brief Hash Move Constructor, initializes empty multiset with a hash
constexpr multiset(hash_t&& hash) noexcept
: _alloc()
, _hash(hash)
, _size(0)
@@ -104,8 +104,8 @@ public:
}
///
/// \brief Alloc Copy Constructor, initializes empty set with an allocator
constexpr set(const alloc_t& alloc)
/// \brief Alloc Copy Constructor, initializes empty multiset with an allocator
constexpr multiset(const alloc_t& alloc)
: _alloc(alloc)
, _hash()
, _size(0)
@@ -114,8 +114,8 @@ public:
}
///
/// \brief Alloc Move Constructor, initializes empty set with an allocator
constexpr set(alloc_t&& alloc) noexcept
/// \brief Alloc Move Constructor, initializes empty multiset with an allocator
constexpr multiset(alloc_t&& alloc) noexcept
: _alloc(alloc)
, _hash()
, _size(0)
@@ -124,8 +124,8 @@ public:
}
///
/// \brief Hash Alloc Copy Constructor, initializes empty set with a hash and allocator
constexpr set(const hash_t& hash, const alloc_t& alloc)
/// \brief Hash Alloc Copy Constructor, initializes empty multiset with a hash and allocator
constexpr multiset(const hash_t& hash, const alloc_t& alloc)
: _alloc(alloc)
, _hash(hash)
, _size(0)
@@ -134,8 +134,8 @@ public:
}
///
/// \brief Hash Copy Alloc Move Constructor, initializes empty set with a hash and allocator
constexpr set(const hash_t& hash, alloc_t&& alloc) noexcept
/// \brief Hash Copy Alloc Move Constructor, initializes empty multiset with a hash and allocator
constexpr multiset(const hash_t& hash, alloc_t&& alloc) noexcept
: _alloc(alloc)
, _hash(hash)
, _size(0)
@@ -144,8 +144,8 @@ public:
}
///
/// \brief Hash Move Alloc Move Constructor, initializes empty set with a hash and allocator
constexpr set(hash_t&& hash, alloc_t&& alloc) noexcept
/// \brief Hash Move Alloc Move Constructor, initializes empty multiset with a hash and allocator
constexpr multiset(hash_t&& hash, alloc_t&& alloc) noexcept
: _alloc(alloc)
, _hash(hash)
, _size(0)
@@ -154,8 +154,8 @@ public:
}
///
/// \brief Hash Move Alloc Copy Constructor, initializes empty set with a hash and allocator
constexpr set(hash_t&& hash, const alloc_t& alloc) noexcept
/// \brief Hash Move Alloc Copy Constructor, initializes empty multiset with a hash and allocator
constexpr multiset(hash_t&& hash, const alloc_t& alloc) noexcept
: _alloc(alloc)
, _hash(hash)
, _size(0)
@@ -165,29 +165,29 @@ public:
///
/// \brief Set Copy Constructor
/// \param set Set to copy
constexpr set(const set& set)
: _alloc(set._alloc)
, _hash(set._hash)
, _size(set._size)
, _sumpsl(set._sumpsl)
, _load(set._load) {
/// \param multiset Set to copy
constexpr multiset(const multiset& multiset)
: _alloc( multiset._alloc)
, _hash( multiset._hash)
, _size( multiset._size)
, _sumpsl( multiset._sumpsl)
, _load( multiset._load) {
}
///
/// \brief Set Move Constructor
/// \param set Set to move
constexpr set(set&& set) noexcept
: _alloc(fennec::move(set._alloc))
, _hash(fennec::move(set._hash))
, _size(fennec::move(set._size))
, _sumpsl(set._sumpsl)
, _load(set._load) {
/// \param multiset Set to move
constexpr multiset(multiset&& multiset) noexcept
: _alloc(fennec::move( multiset._alloc))
, _hash(fennec::move( multiset._hash))
, _size(fennec::move( multiset._size))
, _sumpsl( multiset._sumpsl)
, _load( multiset._load) {
}
///
/// \brief Destructor, destructs all elements and releases the allocation
constexpr ~set() {
constexpr ~multiset() {
for (size_t i = 0; i < capacity(); ++i) {
_alloc[i].value = nullopt;
}
@@ -197,13 +197,13 @@ public:
// Properties ==========================================================================================================
///
/// \returns Size of the set in elements
/// \returns Size of the multiset in elements
constexpr size_t size() const {
return _size;
}
///
/// \returns Capacity of the set in elements
/// \returns Capacity of the multiset in elements
constexpr size_t capacity() const {
return _alloc.capacity();
}
@@ -264,7 +264,7 @@ public:
}
///
/// \brief Check if a set contains a value
/// \brief Check if a multiset contains a value
/// \param val Value to check
/// \returns `true` if `val` can be found, `false` otherwise
constexpr bool contains(const elem_t& val) const {
@@ -398,12 +398,12 @@ public:
}
private:
const set* _set;
const multiset* _set;
size_t _i;
friend set;
friend multiset;
constexpr iterator(const set* set, size_t i)
: _set(set)
constexpr iterator(const multiset* multiset, size_t i)
: _set(multiset)
, _i(i) {
}
};
@@ -449,14 +449,14 @@ public:
}
private:
const set* _set;
const multiset* _set;
size_t _i;
int _psl;
elem_t _value;
friend set;
friend multiset;
constexpr value_iterator(const set* set, size_t i, int psl, const elem_t& value)
: _set(set)
constexpr value_iterator(const multiset* multiset, size_t i, int psl, const elem_t& value)
: _set(multiset)
, _i(i)
, _value(value) {
}
@@ -479,7 +479,7 @@ public:
private:
constexpr void _expand() {
set cpy; // Create a new set
multiset cpy; // Create a new multiset
cpy._alloc.callocate(
fennec::next_prime2(_alloc.capacity())
);