summaryrefslogtreecommitdiffstats
path: root/src/nbt/nbtht.internal.h
blob: f3bc14b8029facb113a32fd694b9d96ff4c622a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef LIBWORLD_NBTHT_INTERNAL_H_INCLUDED
#define LIBWORLD_NBTHT_INTERNAL_H_INCLUDED

#include "nbt.h"
#include <string.h>
#include <stdlib.h>

#include <xxh3.h>

#define HT_PREFIX nbt__ht_

#define HT_VALTYPE nbt_tag_t *
#define HT_VALTYPE_CREF nbt_tag_t *

#define HT_VAL_SENTINEL NULL
#define HT_VAL_COPY(_v, _sz) nbt_incref(_v)
#define HT_VAL_FREE(_v) nbt_decref(_v)
#define HT_VAL_STATIC_LEN sizeof(nbt_tag_t *)

inline void *nbt__ht_memdup(const void *in, size_t sz)
{
  void *ret = malloc(sz);
  if (!ret) return NULL;
  memcpy(ret, in, sz);
  return ret;
}

#define HT_KEYTYPE char *
#define HT_KEYTYPE_CREF const char *
#define HT_KEY_EQ(_val1, _len1, _val2, _len2) (((_len1) == (_len2)) && !memcmp(_val1, _val2, _len1))
#define HT_KEY_GUESS_LEN(_k) strlen(_k)
#define HT_KEY_FREE(_k) free(_k)
#define HT_KEY_COPY(_k, _klen) nbt__ht_memdup(_k, _klen)

#define HT_KEY_FMT "%s"
#define HT_VAL_FMT "%p"

#define HT_HASHTYPE XXH64_hash_t
#define HT_KEY_HASH(_val, _sz) XXH3_64bits(_val, _sz)
#define HT_LOADFACTOR 0.75f

#include "../htgen.h"

#endif /* include guard */