libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
hash.c
Go to the documentation of this file.
1// Copyright (C) 2023 Ethan Uppal. All rights reserved.
2
3#include <string.h>
4#include "hash.h"
5
6// This algorithm was taken from Wikipedia:
7// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
8
9#define FNV_OFFSET_BASIS 0xcbf29ce484222325
10#define FNV_PRIME 0x100000001b3
11
14 for (usize i = 0; str[i]; i++) {
15 hash ^= str[i];
16 hash *= FNV_PRIME;
17 }
18 return hash;
19}
20
22 return strcmp(a, b) == 0;
23}
#define STR
Definition def.h:40
#define usize
Definition def.h:50
bool ps_str_is_equal(STR a, STR b)
Compares the given strings.
Definition hash.c:21
hash_t ps_str_hash(STR str)
Hashes the given string according to the FNV-1a algorithm.
Definition hash.c:12
#define FNV_OFFSET_BASIS
Definition hash.c:9
#define FNV_PRIME
Definition hash.c:10
Hashing and equality functions for common data types.
u64 hash_t
Numeric type for hashes.
Definition hash.h:12