227 std::unique_ptr<NodeList[]> mBuckets;
228 std::
size_t mItemCount, mBucketCount;
229 double mMaximumLoadFactor;
249 return super::insert(
hash,
string);
255 return super::insertPrefix(
hash, prefix,
string);
261 return super::lookup(
hash);
278 :
RuntimeError(
"CollisionError: strings {0} and {1} are both producing the value {2}", a, b,
hash), mFirstString(a), mSecondString(b),
295template<>
struct std::hash<
CeresEngine::StringID> {
296 size_t operator()(
const CeresEngine::StringID& arg)
const noexcept {
return static_cast<size_t>(arg.getHashCode()); }
A database that doesn't store the string-values.
Definition StringID.hpp:195
StringID::Status insertPrefix(StringID::Hash, StringID::Hash, StringView) override
Inserts a hash-string-pair with given prefix into the internal database.
Definition StringID.hpp:201
StringView lookup(StringID::Hash) const noexcept override
Returns the string stored with a given hash.
Definition StringID.hpp:204
StringID::Status insert(StringID::Hash, StringView) override
Inserts a new hash-string-pair with prefix (optional) into the internal database.
Definition StringID.hpp:198
The class Lock is a mutex wrapper that provides a convenient RAII-style mechanism for owning one or m...
Definition Threading.hpp:246
A database that uses a highly optimized hash table.
Definition StringID.hpp:208
~MapStringDatabase() noexcept override
MapStringDatabase(std::size_t size=1024, double maxLoadFactor=1.0)
Creates a new database with given number of buckets and maximum load factor.
Definition Exception.hpp:115
The interface for all databases. You can derive own databases from it.
Definition StringID.hpp:143
virtual ~StringDatabase()=default
StringDatabase(StringDatabase &&)=delete
StringDatabase(const StringDatabase &)=delete
virtual StringView lookup(StringID::Hash hash) const noexcept=0
Returns the string stored with a given hash.
virtual StringID::Status insertPrefix(StringID::Hash hash, StringID::Hash prefix, StringView string)
Inserts a hash-string-pair with given prefix into the internal database.
static StringDatabase & getDefault() noexcept
virtual StringID::Status insert(StringID::Hash hash, StringView string)=0
Inserts a new hash-string-pair with prefix (optional) into the internal database.
The exception class thrown by the default CollisionHandler.
Definition StringID.hpp:270
StringID::Hash mHashCode
Definition StringID.hpp:273
StringIDCollisionError(StringID::Hash hash, StringView a, StringView b)
Creates a new exception, same parameter as CollisionError.
Definition StringID.hpp:277
StringID::Hash getHashCode() const noexcept
Returns the hash code of the collided strings.
Definition StringID.hpp:289
StringView getFirstString() const noexcept
Returns the first string that collided.
Definition StringID.hpp:283
StringView getSecondString() const noexcept
Returns the second string that collided.
Definition StringID.hpp:286
String mFirstString
Definition StringID.hpp:272
The string identifier class.
Definition StringID.hpp:37
StringID()=default
Constructs a new empty StringID.
StringDatabase * mDatabase
Definition StringID.hpp:56
StringID(StringDatabase &database, StringView string, Status &status)
Same as other constructors versions but instead of calling the CollisionHandler, they set the output ...
friend bool operator!=(const StringID &a, const StringID &b) noexcept
Definition StringID.hpp:114
UInt64 Hash
The type of a hashed string.
Definition StringID.hpp:40
Hash mID
Definition StringID.hpp:55
friend bool operator==(const StringID &a, const StringID::Hash b) noexcept
Definition StringID.hpp:113
friend bool operator==(const StringID::Hash a, const StringID &b) noexcept
Definition StringID.hpp:112
StringID(const StringID &prefix, StringView string, Status &status)
Same as other constructors versions but instead of calling the CollisionHandler, they set the output ...
StringID(StringDatabase &database, StringView string)
Creates a new id by hashing a given string.
StringView getString() const noexcept
StringID(StringView string)
Creates a new id by hashing a given string.
friend bool operator!=(const StringID::Hash a, const StringID &b) noexcept
Definition StringID.hpp:115
StringID::Hash getHashCode() const noexcept
Definition StringID.hpp:101
static CollisionHandler getCollisionHandler()
Returns the current CollisionHandler.
static CollisionHandler setCollisionHandler(CollisionHandler h)
Exchanges the CollisionHandler.
StringID(const StringID &prefix, StringView string)
Creates a new id with a given prefix.
Status
The status of an insert operation.
Definition StringID.hpp:43
@ Collision
Two different strings collide on the same value.
@ OldString
The string already existed inside the database.
@ NewString
A new string was inserted.
void(*)(StringID::Hash hash, StringView a, StringView b) CollisionHandler
The type of the collision handler.
Definition StringID.hpp:124
friend bool operator!=(const StringID &a, const StringID::Hash b) noexcept
Definition StringID.hpp:116
A thread-safe database adapter.
Definition StringID.hpp:235
StringView lookup(StringID::Hash hash) const noexcept override
Returns the string stored with a given hash.
Definition StringID.hpp:259
MutexType mMutex
Definition StringID.hpp:239
ThreadSafeStringDatabase(Args &&... args)
Definition StringID.hpp:243
Parent super
Definition StringID.hpp:236
StringID::Status insertPrefix(StringID::Hash hash, StringID::Hash prefix, StringView string) override
Inserts a hash-string-pair with given prefix into the internal database.
Definition StringID.hpp:253
StringID::Status insert(StringID::Hash hash, StringView string) override
Inserts a new hash-string-pair with prefix (optional) into the internal database.
Definition StringID.hpp:247
Definition Application.hpp:19
std::uint64_t UInt64
Definition DataTypes.hpp:26
decltype(auto) lock(Func &&func, Ts &... objects)
Definition Threading.hpp:667
BasicStringView< char > StringView
Narrow string view used for handling narrow encoded text in UTF-8.
Definition String.hpp:190
constexpr UInt64 staticHash64(BasicStringView< T > string, const UInt64 value=0xcbf29ce484222325) noexcept
Definition Hash.hpp:82
std::mutex Mutex
The Mutex class is a synchronization primitive that can be used to protect shared data from being sim...
Definition Threading.hpp:73
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25