3#include <Foundation/Containers/Deque.h>
11template <
typename KeyType,
typename Comparer>
20 plUInt16 m_uiLevel = 0;
21 Node* m_pParent =
nullptr;
22 Node* m_pLink[2] = {
nullptr,
nullptr};
26 struct Node :
public NilNode
33 template <
bool REVERSE>
36 using iterator_category = std::forward_iterator_tag;
38 using difference_type = std::ptrdiff_t;
42 PL_DECLARE_POD_TYPE();
51 PL_ALWAYS_INLINE
bool IsValid()
const {
return (m_pElement !=
nullptr); }
58 PL_FORCE_INLINE
const KeyType&
Key()
const
60 PL_ASSERT_DEBUG(
IsValid(),
"Cannot access the 'key' of an invalid iterator.");
61 return m_pElement->m_Key;
65 PL_ALWAYS_INLINE
const KeyType&
operator*()
const {
return Key(); }
80 void Advance(plInt32 dir0, plInt32 dir1);
82 friend class plSetBase<KeyType, Comparer>;
92 using Iterator = IteratorBase<false>;
93 using ReverseIterator = IteratorBase<true>;
125 template <
typename CompatibleKeyType>
126 Iterator
Insert(CompatibleKeyType&& key);
129 template <
typename CompatibleKeyType>
130 bool Remove(
const CompatibleKeyType& key);
133 Iterator
Remove(
const Iterator& pos);
136 template <
typename CompatibleKeyType>
140 template <
typename CompatibleKeyType>
148 template <
typename CompatibleKeyType>
153 template <
typename CompatibleKeyType>
179 template <
typename CompatibleKeyType>
180 Node* Internal_Find(
const CompatibleKeyType& key)
const;
181 template <
typename CompatibleKeyType>
182 Node* Internal_LowerBound(
const CompatibleKeyType& key)
const;
183 template <
typename CompatibleKeyType>
184 Node* Internal_UpperBound(
const CompatibleKeyType& key)
const;
190 template <
typename CompatibleKeyType>
191 Node* AcquireNode(CompatibleKeyType&& key, plUInt16 uiLevel, Node* pParent);
194 void ReleaseNode(Node* pNode);
199 Node* SkewNode(Node* root);
200 Node* SplitNode(Node* root);
202 template <
typename CompatibleKeyType>
203 Node*
Insert(Node* root, CompatibleKeyType&& key, Node*& pInsertedNode);
204 template <
typename CompatibleKeyType>
205 Node*
Remove(Node* root,
const CompatibleKeyType& key,
bool& bRemoved);
208 Node* GetLeftMost()
const;
211 Node* GetRightMost()
const;
214 void SwapNilNode(Node*& pCurNode, NilNode* pOld, NilNode* pNew);
229 Node* m_pFreeElementStack;
236template <
typename KeyType,
typename Comparer = plCompareHelper<KeyType>,
typename AllocatorWrapper = plDefaultAllocatorWrapper>
252template <
typename KeyType,
typename Comparer>
258template <
typename KeyType,
typename Comparer>
264template <
typename KeyType,
typename Comparer>
270template <
typename KeyType,
typename Comparer>
276template <
typename KeyType,
typename Comparer>
282template <
typename KeyType,
typename Comparer>
289#include <Foundation/Containers/Implementation/Set_inl.h>
Base class for all memory allocators.
Definition Allocator.h:23
plUInt64 GetHeapMemoryUsage() const
Returns the amount of bytes that are currently allocated on the heap.
Definition Deque_inl.h:970
plAllocator * GetAllocator() const
Returns the allocator that is used by this instance.
Definition Deque.h:168
A set container that only stores whether an element resides in it or not. Similar to STL::set.
Definition Set.h:13
bool ContainsSet(const plSetBase< KeyType, Comparer > &operand) const
Checks whether all keys of the given set are in the container.
Definition Set_inl.h:242
void Intersection(const plSetBase< KeyType, Comparer > &operand)
Makes this set the intersection of itself and the operand.
Definition Set_inl.h:338
Iterator GetIterator() const
Returns a constant Iterator to the very first element.
Definition Set_inl.h:165
void Clear()
Destroys all elements in the set and resets its size to zero.
Definition Set_inl.h:133
void Union(const plSetBase< KeyType, Comparer > &operand)
Makes this set the union of itself and the operand.
Definition Set_inl.h:320
void operator=(const plSetBase< KeyType, Comparer > &rhs)
Copies all keys from the given set into this one.
Definition Set_inl.h:124
plSetBase(const Comparer &comparer, plAllocator *pAllocator)
Initializes the set to be empty.
Definition Set_inl.h:101
plUInt64 GetHeapMemoryUsage() const
Returns the amount of bytes that are currently allocated on the heap.
Definition Set.h:173
void Swap(plSetBase< KeyType, Comparer > &other)
Swaps this map with the other one.
Definition Set_inl.h:749
Iterator Insert(CompatibleKeyType &&key)
Inserts the key into the tree and returns an Iterator to it. O(log n) operation.
Definition Set_inl.h:351
void Difference(const plSetBase< KeyType, Comparer > &operand)
Makes this set the difference of itself and the operand, i.e. subtracts operand.
Definition Set_inl.h:329
plUInt32 GetCount() const
Returns the number of elements currently stored in the set. O(1) operation.
Definition Set_inl.h:158
ReverseIterator GetReverseIterator() const
Returns a constant ReverseIterator to the very last element.
Definition Set_inl.h:171
bool Remove(const CompatibleKeyType &key)
Erases the element with the given key, if it exists. O(log n) operation.
Definition Set_inl.h:364
bool operator==(const plSetBase< KeyType, Comparer > &rhs) const
Comparison operator.
Definition Set_inl.h:684
bool IsEmpty() const
Returns whether there are no elements in the set. O(1) operation.
Definition Set_inl.h:152
bool Contains(const CompatibleKeyType &key) const
Checks whether the given key is in the container.
plAllocator * GetAllocator() const
Returns the allocator that is used by this instance.
Definition Set.h:166
Iterator UpperBound(const CompatibleKeyType &key) const
Returns an Iterator to the element with a key that is LARGER than the given key. Returns an invalid i...
Iterator Find(const CompatibleKeyType &key) const
Searches for key, returns an Iterator to it or an invalid iterator, if no such key is found....
Iterator LowerBound(const CompatibleKeyType &key) const
Returns an Iterator to the element with a key equal or larger than the given key. Returns an invalid ...
~plSetBase()
Destroys all elements in the set.
Definition Set_inl.h:118
Base class for all iterators.
Definition Set.h:35
void Prev()
Advances the iterator to the previous element in the set. The iterator will not be valid anymore,...
Definition Set_inl.h:72
PL_ALWAYS_INLINE IteratorBase()
Constructs an invalid iterator.
Definition Set.h:45
PL_ALWAYS_INLINE void operator--()
Shorthand for 'Prev'.
Definition Set.h:77
void Next()
Advances the iterator to the next element in the set. The iterator will not be valid anymore,...
Definition Set_inl.h:58
PL_ALWAYS_INLINE bool operator==(const typename plSetBase< KeyType, Comparer >::IteratorBase< REVERSE > &it2) const
Checks whether the two iterators point to the same element.
Definition Set.h:54
PL_FORCE_INLINE const KeyType & Key() const
Returns the 'key' of the element that this iterator points to.
Definition Set.h:58
PL_ALWAYS_INLINE bool IsValid() const
Checks whether this iterator points to a valid element.
Definition Set.h:51
PL_ALWAYS_INLINE void operator++()
Shorthand for 'Next'.
Definition Set.h:74
PL_ALWAYS_INLINE const KeyType & operator*() const
Returns the 'key' of the element that this iterator points to.
Definition Set.h:65