Astaroth  3.1
Scalable Multi-GPU Stencil Computations
Loading...
Searching...
No Matches
hash.h
Go to the documentation of this file.
1#pragma once
2
3#include <hashtable.h>
4
5extern struct hashmap_s string_intern_hashmap;
6
7static inline const char*
8intern(const char* buffer)
9{
10 if(!buffer)
11 return NULL;
12 const char* str_from_map = (const char*)hashmap_get(&string_intern_hashmap, buffer, strlen(buffer));
13 if(str_from_map)
14 return str_from_map;
15 const char* dup = strdup(buffer);
16 hashmap_put(&string_intern_hashmap,dup, strlen(dup),(void*)dup);
17 return dup;
18}
struct hashmap_s string_intern_hashmap
HASHMAP_WEAK void * hashmap_get(const struct hashmap_s *const hashmap, const void *const key, const hashmap_uint32_t len)
Get an element from the hashmap.
Definition hashtable.h:364
HASHMAP_WEAK int hashmap_put(struct hashmap_s *const hashmap, const void *const key, const hashmap_uint32_t len, void *const value)
Put an element into the hashmap.
Definition hashtable.h:334