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