Rizin
unix-like reverse engineering framework and cli tools
sdbht.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: MIT
3 
4 #ifndef __SDB_HT_H
5 #define __SDB_HT_H
6 
7 #include "ht_pp.h"
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
14 typedef struct sdb_kv {
15  // sub of HtPPKv so we can cast safely
16  HtPPKv base;
20 
21 static inline char *sdbkv_key(const SdbKv *kv) {
22  return (char *)kv->base.key;
23 }
24 
25 static inline char *sdbkv_value(const SdbKv *kv) {
26  return (char *)kv->base.value;
27 }
28 
29 static inline ut32 sdbkv_key_len(const SdbKv *kv) {
30  return kv->base.key_len;
31 }
32 
33 static inline ut32 sdbkv_value_len(const SdbKv *kv) {
34  return kv->base.value_len;
35 }
36 
37 RZ_API SdbKv *sdbkv_new2(const char *k, int kl, const char *v, int vl);
38 RZ_API SdbKv *sdbkv_new(const char *k, const char *v);
39 extern RZ_API void sdbkv_free(SdbKv *kv);
40 
41 extern RZ_API ut32 sdb_hash(const char *key);
42 
43 RZ_API HtPP *sdb_ht_new(void);
44 // Destroy a hashtable and all of its entries.
45 RZ_API void sdb_ht_free(HtPP *ht);
46 // Insert a new Key-Value pair into the hashtable. If the key already exists, returns false.
47 RZ_API bool sdb_ht_insert(HtPP *ht, const char *key, const char *value);
48 // Insert a new Key-Value pair into the hashtable, or updates the value if the key already exists.
49 RZ_API bool sdb_ht_insert_kvp(HtPP *ht, SdbKv *kvp, bool update);
50 // Insert a new Key-Value pair into the hashtable, or updates the value if the key already exists.
51 RZ_API bool sdb_ht_update(HtPP *ht, const char *key, const char *value);
52 // Delete a key from the hashtable.
53 RZ_API bool sdb_ht_delete(HtPP *ht, const char *key);
54 // Find the value corresponding to the matching key.
55 RZ_API char *sdb_ht_find(HtPP *ht, const char *key, bool *found);
56 // Find the KeyValuePair corresponding to the matching key.
57 RZ_API SdbKv *sdb_ht_find_kvp(HtPP *ht, const char *key, bool *found);
58 
59 #ifdef __cplusplus
60 }
61 #endif
62 
63 #endif // __SDB_HT_H
static int value
Definition: cmd_api.c:93
#define RZ_API
static bool update(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto_aes.c:92
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
uint32_t ut32
const char * k
Definition: dsignal.c:11
const char * v
Definition: dsignal.c:12
RZ_API const KEY_TYPE bool * found
Definition: ht_inc.h:130
RZ_API SdbKv * sdbkv_new2(const char *k, int kl, const char *v, int vl)
Definition: sdb.c:493
RZ_API SdbKv * sdb_ht_find_kvp(HtPP *ht, const char *key, bool *found)
Definition: sdbht.c:55
RZ_API char * sdb_ht_find(HtPP *ht, const char *key, bool *found)
Definition: sdbht.c:59
static ut32 sdbkv_key_len(const SdbKv *kv)
Definition: sdbht.h:29
RZ_API HtPP * sdb_ht_new(void)
Definition: sdbht.c:11
RZ_API void sdb_ht_free(HtPP *ht)
Definition: sdbht.c:63
static char * sdbkv_key(const SdbKv *kv)
Definition: sdbht.h:21
RZ_API bool sdb_ht_update(HtPP *ht, const char *key, const char *value)
Definition: sdbht.c:51
struct sdb_kv SdbKv
RZ_API bool sdb_ht_insert_kvp(HtPP *ht, SdbKv *kvp, bool update)
Definition: sdbht.c:47
static ut32 sdbkv_value_len(const SdbKv *kv)
Definition: sdbht.h:33
RZ_API ut32 sdb_hash(const char *key)
Definition: util.c:22
RZ_API void sdbkv_free(SdbKv *kv)
Definition: sdb.c:524
RZ_API bool sdb_ht_insert(HtPP *ht, const char *key, const char *value)
Definition: sdbht.c:43
RZ_API bool sdb_ht_delete(HtPP *ht, const char *key)
Definition: sdbht.c:67
static char * sdbkv_value(const SdbKv *kv)
Definition: sdbht.h:25
RZ_API SdbKv * sdbkv_new(const char *k, const char *v)
Definition: sdb.c:489
Definition: sdbht.h:14
HtPPKv base
Definition: sdbht.h:16
ut64 expire
Definition: sdbht.h:18
ut32 cas
Definition: sdbht.h:17
ut64(WINAPI *w32_GetEnabledXStateFeatures)()