String ID library & debugging tools
by Ming-Lun "Allen" Chou / AllenChou.net / @TheAllenChou / Patreon
String ID (SID) is a tool that converts strings into fix-sized hashed values, commonly used in games for looking up resources. The hash function is chosen to support string concatenation. This project uses FNV-1a hash.
Notable advantages of SIDs over strings:
Main disadvantage and solutions:
For more explanations, check out these articles:
This repository contains several projects:
The core library (sid), database library example (siddb), and local database terminal example (sidbot) are platform-agnostic. The rest are targeted for Windows.
To build the projects on Windows, you need:
/*
The SID macro evaluates to a StringId object.
The SID_VAL macro evaluates to a StringId's underlying raw integer data.
These macros evaluate to constants at compiled-time if given compile-time constant strings.
StringId::GerValue() returns a StringId's underlying raw integer data.
There is intentionally no implicit conversion between StringId and the underlying raw integer type.
*/
// comparison
const StringId sid0 = SID("123");
const StringId sid1 = SID("abc");
ASSERT(sid0 != sid1);
// concatenation
const StringId sid2 = SID("12");
const StringId sid3 = sid2.Concat("3");
ASSERT(sid0 == sid3);
// switch cases
const StringId sid4 = SID("print");
switch (sid4.GetValue())
{
case SID_VAL("print"):
printStuff();
break;
case SID_VAL("draw"):
drawStuff();
break;
}
// asset look-up
Texture* pTexture = g_textureMgr.FindTexture(SID("cloud"));