CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::MapStringDatabase Class Reference

A database that uses a highly optimized hash table. More...

#include <CeresEngine/Foundation/StringID.hpp>

Inheritance diagram for CeresEngine::MapStringDatabase:
CeresEngine::StringDatabase

Public Member Functions

 MapStringDatabase (std::size_t size=1024, double maxLoadFactor=1.0)
 Creates a new database with given number of buckets and maximum load factor.
 
 ~MapStringDatabase () noexcept override
 
StringID::Status insert (StringID::Hash hash, StringView string) override
 Inserts a new hash-string-pair with prefix (optional) into the internal database.
 
StringID::Status insertPrefix (StringID::Hash hash, StringID::Hash prefix, StringView string) override
 Inserts a hash-string-pair with given prefix into the internal database.
 
StringView lookup (StringID::Hash hash) const noexcept override
 Returns the string stored with a given hash.
 
- Public Member Functions inherited from CeresEngine::StringDatabase
 StringDatabase (const StringDatabase &)=delete
 
 StringDatabase (StringDatabase &&)=delete
 
virtual ~StringDatabase ()=default
 

Private Member Functions

void rehash ()
 

Private Attributes

std::unique_ptr< NodeList[]> mBuckets
 
std::size_t mItemCount
 
std::size_t mBucketCount
 
double mMaximumLoadFactor
 
std::size_t mNextResize
 

Additional Inherited Members

- Static Public Member Functions inherited from CeresEngine::StringDatabase
static StringDatabasegetDefault () noexcept
 
- Protected Member Functions inherited from CeresEngine::StringDatabase
 StringDatabase ()=default
 

Detailed Description

A database that uses a highly optimized hash table.

Constructor & Destructor Documentation

◆ MapStringDatabase()

CeresEngine::MapStringDatabase::MapStringDatabase ( std::size_t  size = 1024,
double  maxLoadFactor = 1.0 
)
explicit

Creates a new database with given number of buckets and maximum load factor.

◆ ~MapStringDatabase()

CeresEngine::MapStringDatabase::~MapStringDatabase ( )
overridenoexcept

Member Function Documentation

◆ insert()

StringID::Status CeresEngine::MapStringDatabase::insert ( StringID::Hash  hash,
StringView  string 
)
overridevirtual

Inserts a new hash-string-pair with prefix (optional) into the internal database.

Note
The string must be copied prior to storing, it may not stay valid.
Parameters
hashThe hash of the string.
stringThe string which does not need to be null-terminated.
Returns
The status of the insertion.

Implements CeresEngine::StringDatabase.

◆ insertPrefix()

StringID::Status CeresEngine::MapStringDatabase::insertPrefix ( StringID::Hash  hash,
StringID::Hash  prefix,
StringView  string 
)
overridevirtual

Inserts a hash-string-pair with given prefix into the internal database.

Note
The default implementation performs a lookup of the prefix string and appends it, then it calls insert. Override it if you can do it more efficiently.
Parameters
hashThe hash of the string plus prefix.
prefixThe hash of the prefix-string.
stringThe suffix which does not need to be null-terminated.
Returns
The status of the insertion.

Reimplemented from CeresEngine::StringDatabase.

◆ lookup()

StringView CeresEngine::MapStringDatabase::lookup ( StringID::Hash  hash) const
overridevirtualnoexcept

Returns the string stored with a given hash.

Note
It is guaranteed that the hash value has been inserted before.
Returns
A null-terminated string belonging to the hash code or an error message if the database does not store anything. The return value must stay valid as long as the database exists.

Implements CeresEngine::StringDatabase.

◆ rehash()

void CeresEngine::MapStringDatabase::rehash ( )
private

Member Data Documentation

◆ mBucketCount

std::size_t CeresEngine::MapStringDatabase::mBucketCount
private

◆ mBuckets

std::unique_ptr<NodeList[]> CeresEngine::MapStringDatabase::mBuckets
private

◆ mItemCount

std::size_t CeresEngine::MapStringDatabase::mItemCount
private

◆ mMaximumLoadFactor

double CeresEngine::MapStringDatabase::mMaximumLoadFactor
private

◆ mNextResize

std::size_t CeresEngine::MapStringDatabase::mNextResize
private

The documentation for this class was generated from the following file: