DataStructures
July 1, 2023 ยท View on GitHub
Members
enum MapMode
| Values | Descriptions |
|---|---|
| Fast | |
| Stable |
Set ae::Map to Fast mode to allow reording of elements.
Stable to maintain the order of inserted elements.
public inline std::ostream & operator<<(std::ostream & os,const ae::Dict & dict)
ae::Str class
A fixed length string class.
The templated value is the total size of the string in memory.
public Str()
public template<>
Str(const Str< N2 > & str)
public Str(const char * str)
public Str(uint32_t length,const char * str)
public Str(uint32_t length,char c)
public template<>
Str(const char * format,Args... args)
public explicit operator const char *() const
public template<>
void operator=(const Str< N2 > & str)
public template<>
Str< N > operator+(const Str< N2 > & str) const
public template<>
void operator+=(const Str< N2 > & str)
public template<>
bool operator==(const Str< N2 > & str) const
public template<>
bool operator!=(const Str< N2 > & str) const
public template<>
bool operator<(const Str< N2 > & str) const
public template<>
bool operator>(const Str< N2 > & str) const
public template<>
bool operator<=(const Str< N2 > & str) const
public template<>
bool operator>=(const Str< N2 > & str) const
public Str< N > operator+(const char * str) const
public void operator+=(const char * str)
public bool operator==(const char * str) const
public bool operator!=(const char * str) const
public bool operator<(const char * str) const
public bool operator>(const char * str) const
public bool operator<=(const char * str) const
public bool operator>=(const char * str) const
public char & operator[](uint32_t i)
public const char operator[](uint32_t i) const
public const char * c_str() const
public template<>
void Append(const Str< N2 > & str)
public void Append(const char * str)
public void Trim(uint32_t len)
public uint32_t Length() const
public uint32_t Size() const
public bool Empty() const
ae::Array class
public Array()
Static array (N > 0) only.
public Array(const T & val,uint32_t length)
Static array (N > 0) only. Appends 'length' number of 'val's.
public Array(std::initializer_list< T > initList)
Static array (N > 0) only. Construct from a standard initializer list.
public Array(ae::Tag tag)
Dynamic array (N == 0) only.
public Array(ae::Tag tag,uint32_t size)
Dynamic array (N == 0) only. Reserve size (with length of 0).
public Array(ae::Tag tag,const T & val,uint32_t length)
Dynamic array (N == 0) only.
Reserves 'length' and appends 'length' number of 'val's.
public void Reserve(uint32_t total)
Dynamic array (N == 0) only.
Expands array storage to avoid copying data unneccesarily on Append(). Retrieve the current storage limit with Size().
public Array(const Array< T, N > & other)
Copy constructor.
The ae::Tag of other will be used for the newly constructed array if the array is dynamic (N == 0).
public Array(Array< T, N > && other) noexcept
Move constructor falls back to the regular copy constructor for static arrays (N > 0) or if the given ae::Tags don't match.
public void operator=(const Array< T, N > & other)
Assignment operator.
public void operator=(Array< T, N > && other) noexcept
Move assignment operator falls back to the regular assignment operator for static arrays (N > 0) or if the given ae::Tags don't match.
public ~Array()
public T & Append(const T & value)
Adds one copy of value to the end of the array.
Can reallocate internal storage for dynamic arrays (N == 0), so take care when taking the address of any elements. Returns a reference to the added entry.
public T * Append(const T & value,uint32_t count)
Adds count copies of value to the end of the array.
Can reallocate internal storage for dynamic arrays (N == 0), so take care when taking the address of any elements. Returns a pointer to the first new element added, or one past the end of the array if count is zero.
public T * AppendArray(const T * values,uint32_t count)
Adds count elements from values.
Can reallocate internal storage for dynamic arrays (N == 0), so take care when taking the address of any elements. Returns a pointer to the first new element added, or one past the end of the array if count is zero.
public T & Insert(uint32_t index,const T & value)
Adds one copy of value at index.
index must be less than or equal to Length(). Can reallocate internal storage for dynamic arrays (N == 0), so take care when taking the address of any elements. Returns a reference to the added entry.
public T * Insert(uint32_t index,const T & value,uint32_t count)
Adds count copies of value at index.
index must be less than or equal to Length(). Can reallocate internal storage for dynamic arrays (N == 0), so take care when taking the address of any elements. Returns a pointer to the first new element added, or the address of the element at index if count is zero.
public T * InsertArray(uint32_t index,const T * values,uint32_t count)
Adds count elements from values at index.
index must be less than or equal to Length(). Can reallocate internal storage for dynamic arrays (N == 0), so take care when taking the address of any elements. Returns a pointer to the first new element added, or the address of the element at index if count is zero.
public template<>
int32_t Find(const U & value) const
Returns the index of the first matching element or -1 when not found.
public template<>
int32_t FindLast(const U & value) const
Returns the index of the last matching element or -1 when not found.
public template<>
int32_t FindFn(Fn testFn) const
Returns the index of the first matching element or -1 when not found.
The function signature should match 'bool (*)( const T2& )' or '[...]( const T2& ) -> bool'. Return true from the predicate for a any matching element.
public template<>
int32_t FindLastFn(Fn testFn) const
Returns the index of the last matching element or -1 when not found.
The function signature should match 'bool (*)( const U& )' or '[...]( const T2& ) -> bool'. Return true from the predicate for any matching element.
public template<>
uint32_t RemoveAll(const U & value)
Remove all elements that match value.
Returns the number of elements that were removed.
public template<>
uint32_t RemoveAllFn(Fn testFn)
Remove elements based on predicate testFn.
The function signature should match 'bool (*)( const U& )' and '[]( const U& ) -> bool'. Return true from the predicate for removal of the given element. Returns the number of elements that were removed.
public void Remove(uint32_t index,uint32_t count)
Removes count elements at index.
index plus count must be less than or equal to Length().
public void Clear()
Destructs all elements in the array and resets the array to length zero.
Does not affect the size of the array.
public const T & operator[](int32_t index) const
Performs bounds checking in debug mode. Use 'GetData()' to get raw array.
public T & operator[](int32_t index)
Performs bounds checking in debug mode. Use 'GetData()' to get raw array.
public inline T * Data()
Returns a pointer to the first element of the array, but can return null when the array length is zero.
public inline const T * Data() const
Returns a pointer to the first element of the array, but can return null when the array length is zero.
public inline uint32_t Length() const
Returns the number of elements currently in the array.
public inline _AE_DYNAMIC_STORAGE uint32_t Size(...) const
Returns the total size of a dynamic array (N == 0)
public inline ae::Tag Tag() const
Returns the tag provided to the constructor for dynamic arrays (N == 0).
Returns ae::Tag() for all static arrays (N > 0).
public inline T * begin()
For ranged-based looping.
Returns a pointer to the first element of the array, but can return null when array length is zero. Lowercase to match the c++ standard.
public inline T * end()
For ranged-based looping.
Returns a pointer one past the last element of the array, but can return null when array length is zero. Lowercase to match the c++ standard.
public inline const T * begin() const
For ranged-based looping.
Returns a pointer to the first element of the array, but can return null when array length is zero. Lowercase to match the c++ standard.
public inline const T * end() const
For ranged-based looping.
Returns a pointer one past the last element of the array, but can return null when array length is zero. Lowercase to match the c++ standard.
ae::HashMap class
public HashMap()
Constructor for a hash map with static allocated storage (N > 0).
public HashMap(ae::Tag pool)
Constructor for a hash map with dynamically allocated storage (N == 0).
public void Reserve(uint32_t size)
Expands the storage if necessary so a size number of key/index pairs can be added without any internal allocations.
Asserts if using static storage and size is greater than N.
public HashMap(const HashMap< N > & other)
public void operator=(const HashMap< N > & other)
public ~HashMap()
Releases allocated storage.
public bool Set(uint32_t key,uint32_t index)
Adds an entry for lookup with ae::HashMap::Get().
If the key already exists the index will be updated. In both cases the return value will be true, and false otherwise.
public int32_t Remove(uint32_t key)
Removes the entry with key if it exists.
Returns the index associated with the removed key on success, -1 otherwise.
public void Decrement(uint32_t index)
Decrements the existing index values supplied to ae::HashMap::Insert() of all entries greater than index.
Useful when index values represent offsets into another array being compacted after the removal of an entry.
public int32_t Get(uint32_t key) const
Returns the index associated with the given key, or -1 if the key is not found.
public void Clear()
Removes all entries.
public uint32_t Length() const
Returns the number of entries.
public inline _AE_DYNAMIC_STORAGE uint32_t Size(...) const
Returns the number of allocated entries.
ae::Map class
public Map()
Constructor for a map with static allocated storage (N > 0)
public Map(ae::Tag pool)
Constructor for a map with dynamically allocated storage (N == 0)
public void Reserve(uint32_t count)
Expands the map storage if necessary so a count number of key/value pairs can be added without any internal allocations.
Asserts if using static storage and count is less than N.
public Value & Set(const Key & key,const Value & value)
Add or replace a key/value pair in the map.
Can be retrieved with ae::Map::Get(). The value is updated in place if the element is found, otherwise the new pair is appended. It's not safe to keep a pointer to the value across non-const operations.
public Value & Get(const Key & key)
Returns a modifiable reference to the value set with key.
Asserts when key/value pair is missing.
public const Value & Get(const Key & key) const
Returns the value set with key. Asserts when key/value pair is missing.
public const Value & Get(const Key & key,const Value & defaultValue) const
Returns the value set with key.
Returns defaultValue otherwise when the key/value pair is missing.
public Value * TryGet(const Key & key)
Returns a pointer to the value set with key.
Returns null otherwise when the key/value pair is missing.
public const Value * TryGet(const Key & key) const
Returns a pointer to the value set with key.
Returns null otherwise when the key/value pair is missing.
public bool TryGet(const Key & key,Value * valueOut)
Returns true when key matches an existing key/value pair.
A copy of the value is set to valueOut.
public bool TryGet(const Key & key,Value * valueOut) const
Returns true when key matches an existing key/value pair.
A copy of the value is set to valueOut.
public bool Remove(const Key & key,Value * valueOut)
Performs a constant time removal of an element with key while potentially re-ordering elements with ae::MapMode::Fast.
Performs a linear time removal of an element with key with ae::MapMode::Stable. Returns true on success, and a copy of the value is set to valueOut if it is not null.
public void RemoveIndex(uint32_t index,Value * valueOut)
Removes an element by index. See ae::Map::Remove() for more details.
public void Clear()
Remove all key/value pairs from the map.
public const Key & GetKey(int32_t index) const
Access elements by index. Returns the nth key in the map.
public const Value & GetValue(int32_t index) const
Access elements by index. Returns the nth value in the map.
public Value & GetValue(int32_t index)
Access elements by index.
Returns a modifiable reference to the nth value in the map.
public int32_t GetIndex(const Key & key) const
Returns the index of a key/value pair in the map.
Returns -1 when key/value pair is missing.
public uint32_t Length() const
Returns the number of key/value pairs in the map.
public inline _AE_DYNAMIC_STORAGE uint32_t Size(...) const
Returns the number of allocated entries.
public inline ae::Pair< Key, Value > * begin()
public inline ae::Pair< Key, Value > * end()
public inline const ae::Pair< Key, Value > * begin() const
public inline const ae::Pair< Key, Value > * end() const
ae::Dict class
public Dict(ae::Tag tag)
public void SetString(const char * key,const char * value)
public inline void SetString(const char * key,char * value)
public void SetInt(const char * key,int32_t value)
public void SetUint(const char * key,uint32_t value)
public void SetFloat(const char * key,float value)
public void SetDouble(const char * key,double value)
public void SetBool(const char * key,bool value)
public void SetVec2(const char * key,ae::Vec2 value)
public void SetVec3(const char * key,ae::Vec3 value)
public void SetVec4(const char * key,ae::Vec4 value)
public void SetInt2(const char * key,ae::Int2 value)
public void SetMatrix4(const char * key,const ae::Matrix4 & value)
public void Clear()
public const char * GetString(const char * key,const char * defaultValue) const
public int32_t GetInt(const char * key,int32_t defaultValue) const
public uint32_t GetUint(const char * key,uint32_t defaultValue) const
public float GetFloat(const char * key,float defaultValue) const
public double GetDouble(const char * key,double defaultValue) const
public bool GetBool(const char * key,bool defaultValue) const
public ae::Vec2 GetVec2(const char * key,ae::Vec2 defaultValue) const
public ae::Vec3 GetVec3(const char * key,ae::Vec3 defaultValue) const
public ae::Vec4 GetVec4(const char * key,ae::Vec4 defaultValue) const
public ae::Int2 GetInt2(const char * key,ae::Int2 defaultValue) const
public ae::Matrix4 GetMatrix4(const char * key,const ae::Matrix4 & defaultValue) const
public bool Has(const char * key) const
public const char * GetKey(uint32_t idx) const
public const char * GetValue(uint32_t idx) const
public inline uint32_t Length() const
public inline ae::Pair< ae::Str128](DataStructures.md#classae_1_1_str), [ae::Str128> *begin()
public inline ae::Pair< ae::Str128](DataStructures.md#classae_1_1_str), [ae::Str128> *end()
public inline const ae::Pair< ae::Str128](DataStructures.md#classae_1_1_str), [ae::Str128> *begin() const
public inline const ae::Pair< ae::Str128](DataStructures.md#classae_1_1_str), [ae::Str128> *end() const
ae::List class
public List()
public ~List()
public void Append(ListNode< T > & node)
public void Clear()
public T * GetFirst()
public T * GetLast()
public const T * GetFirst() const
public const T * GetLast() const
public template<>
T * Find(const U & value)
public template<>
T * FindFn(Fn predicateFn)
public uint32_t Length() const
ae::ListNode class
public ListNode(T * owner)
public ~ListNode()
public void Remove()
public T * GetFirst()
public T * GetNext()
public T * GetPrev()
public T * GetLast()
public const T * GetFirst() const
public const T * GetNext() const
public const T * GetPrev() const
public const T * GetLast() const
public List< T > * GetList()
public const List< T > * GetList() const
ae::RingBuffer class
public RingBuffer()
Constructor for a ring buffer with static allocated storage (N > 0).
public RingBuffer(ae::Tag tag,uint32_t size)
Constructor for a ring buffer with dynamically allocated storage (N == 0).
public T & Append(const T & val)
Appends an element to the current end of the ring buffer.
It's safe to call this when the ring buffer is full, although in this case the element previously at index 0 to be destroyed.
public void Clear()
Resets Length() to 0. Does not affect Size().
public T & Get(uint32_t index)
Returns the element at the given index, which must be less than Length().
public const T & Get(uint32_t index) const
Returns the element at the given index, which must be less than Length().
public inline uint32_t Length() const
Returns the number of appended entries up to Size().
public inline _AE_DYNAMIC_STORAGE uint32_t Size(...) const
Returns the max number of entries.
ae::FreeList class
ae::FreeList can be used along side a separate data array to track allocated elements.
Given a size, ae::FreeList allows allocation and release of array indices from 0 to size - 1.
public FreeList()
public FreeList(const ae::Tag & tag,uint32_t size)
public int32_t Allocate()
Returns (0 <= index < N) on success, and negative on failure.
public void Free(int32_t idx)
Releases idx for future calls to ae::FreeList::Allocate().
idx must be an allocated index or negative (a result of ae::FreeList::Allocate() failure).
public void FreeAll()
Frees all allocated indices.
public int32_t GetFirst() const
Returns the index of the first allocated object.
Returns a negative value if there are no allocated objects.
public int32_t GetNext(int32_t idx) const
Returns the index of the next allocated object after idx.
Returns a negative value if there are no more allocated objects. idx must be an allocated index or negative. A negative value will be returned if idx is negative.
public bool IsAllocated(int32_t idx) const
Returns true if the given idx is currently allocated.
idx must be negative or less than N.
public bool HasFree() const
Returns true if the next Allocate() will succeed.
public uint32_t Length() const
Returns the number of allocated elements.
public inline _AE_DYNAMIC_STORAGE uint32_t Size(...) const
Returns the maximum length of the list.
ae::ObjectPool class
public ObjectPool()
Constructor for static ae::ObjectPool's only.
public ObjectPool(const ae::Tag & tag)
Constructor for paged ae::ObjectPool's only.
public ~ObjectPool()
All objects allocated with ae::ObjectPool::New() must be destroyed before the ae::ObjectPool is destroyed.
public T * New()
Returns a pointer to a freshly constructed object T or null if there are no free objects.
Call ae::ObjectPool::Delete() to destroy the object. ae::ObjectPool::Delete() must be called on every object returned by ae::ObjectPool::New().
public void Delete(T * obj)
Destructs and releases the object obj for future use by ae::ObjectPool::New().
It is safe for the obj parameter to be null.
public void DeleteAll()
Destructs and releases all objects for future use by ae::ObjectPool::New().
public const T * GetFirst() const
Returns the first allocated object in the pool or null if the pool is empty.
public const T * GetNext(const T * obj) const
Returns the next allocated object after obj or null if there are no more objects.
Null will be returned if obj is null.
public T * GetFirst()
Returns the first allocated object in the pool or null if the pool is empty.
public T * GetNext(T * obj)
Returns the next allocated object after obj or null if there are no more objects.
Null will be returned if obj is null.
public bool HasFree() const
Returns true if the pool has any unallocated objects available.
This always returns true for paged pools.
public uint32_t Length() const
Returns the number of allocated objects.
public inline _AE_PAGED_POOL uint32_t Size(...) const
Returns the total number of objects in the pool.
ae::OpaquePool class
ae::OpaquePool is useful for dynamically allocating memory for many object instances when the object type is not known at compile time.
It's particularly useful in conjunction with ae::Type (see constructor for more info on this). It's possible to iterate over an ae::OpaquePool by calling ae::OpaquePool::Iterate< T > (where the template parameter is required because ae::OpaquePool is not templated itself). Additionally, a static ae::Map of ae::OpaquePool's is a great way to allocate game objects or components loaded from a level file.
public OpaquePool(const ae::Tag & tag,uint32_t objectSize,uint32_t objectAlignment,uint32_t poolSize,bool paged)
Constructs an ae::OpaquePool with dynamic internal storage.
tag will be used for all internal allocations. All objects returned by the pool will have objectSize and objectAlignment. If the pool is paged it will allocate pages of size poolSize as necessary. If the pool is not paged, then objects can be allocated at a time. It may be useful to use this in conjunction with registered ae::Type's, passing the results of ae::Type::GetSize() to objectSize and ae::Type::GetAlignment() to objectAlignment.
public ~OpaquePool()
All objects allocated with ae::OpaquePool::Allocate/New() must be destroyed before the ae::OpaquePool is destroyed.
public template<>
T * New()
Returns a pointer to a freshly constructed object T.
If the pool is not paged and there are no free objects null will be returned. Call ae::OpaquePool::Delete() to destroy the object. ae::OpaquePool::Delete() must be called on every object returned by ae::OpaquePool::New(), although it is safe to mix calls to ae::OpaquePool::Allocate/New() and ae::OpaquePool::Free/Delete() as long as constructors and destructors are called manually with ae::OpaquePool::Allocate() and ae::OpaquePool::Free().
public template<>
void Delete(T * obj)
Destructs and releases the object obj for future use. It is safe for obj to be null.
public template<>
void DeleteAll()
Destructs and releases all objects for future use.
public void * Allocate()
Returns a pointer to an object.
If the pool is not paged and there are no free objects null will be returned. The user is responsible for any constructor calls. ae::OpaquePool::Free() must be called on every object returned by ae::OpaquePool::Allocate(). It is safe to mix calls to ae::OpaquePool::Allocate/New() and ae::OpaquePool::Free/Delete() as long as constructors and destructors are called manually with ae::OpaquePool::Allocate() and ae::OpaquePool::Free().
public void Free(void * obj)
Releases the object obj for future use. It is safe for obj to be null.
public void FreeAll()
Releases all objects for future use by ae::OpaquePool::Allocate().
THIS FUNCTION DOES NOT CALL THE OBJECTS DESTRUCTORS, so please use with caution!
public bool HasFree() const
Returns true if the pool has any unallocated objects available.
public inline uint32_t Length() const
Returns the number of allocated objects.
public inline uint32_t Size() const
Returns the total number of objects in the pool.
Note that this number can grow and shrink for paged pools.
public inline uint32_t PageSize() const
Returns the maximum number of objects per page.
public template<>
Iterator< T > Iterate()
Returns an ae::OpaquePool::Iterator which is stl conformant.
public template<>
Iterator< const T > Iterate() const
Returns an ae::OpaquePool::Iterator which is stl conformant.