1
0
mirror of https://github.com/Wessel/boilerplate-c.git synced 2026-07-18 22:03:58 +02:00

feat: initial commit and populate repo

This commit is contained in:
2023-02-06 15:13:16 +01:00
parent 5f7d41f1a6
commit 1c3bb4e360
17 changed files with 159 additions and 237 deletions

20
lib/utils.c Normal file
View File

@@ -0,0 +1,20 @@
/* utils.c */
/** @brief Hash `str` to `hash` for use in a switch case
*
* A string needs to be hashed for it to be used
* inside of a switch statement. We want to use a switch
* statement instead of an if-else chain for it's
* simplicity and lower amount of low-level operations.
*
* @param str The string to hash
*
* @returns hash The hashed version of `str`
*/
unsigned long hash(const char *str) {
unsigned long hash = 5381;
unsigned long int c;
while ((c = *str++))
hash = ((hash << 5) + hash) + c;
return hash;
}