|
Packit Service |
80a84b |
#pragma once
|
|
Packit Service |
80a84b |
|
|
Packit Service |
80a84b |
#include <stdbool.h>
|
|
Packit Service |
80a84b |
#include <string.h>
|
|
Packit Service |
80a84b |
|
|
Packit Service |
80a84b |
struct hash;
|
|
Packit Service |
80a84b |
|
|
Packit Service |
80a84b |
struct hash_iter {
|
|
Packit Service |
80a84b |
const struct hash *hash;
|
|
Packit Service |
80a84b |
unsigned int bucket;
|
|
Packit Service |
80a84b |
unsigned int entry;
|
|
Packit Service |
80a84b |
};
|
|
Packit Service |
80a84b |
|
|
Packit Service |
80a84b |
struct hash *hash_new(unsigned int n_buckets, void (*free_value)(void *value));
|
|
Packit Service |
80a84b |
void hash_free(struct hash *hash);
|
|
Packit Service |
80a84b |
int hash_add_bin(struct hash *hash,
|
|
Packit Service |
80a84b |
const char *key, size_t keylen, const void *value);
|
|
Packit Service |
80a84b |
int hash_add_unique_bin(struct hash *hash,
|
|
Packit Service |
80a84b |
const char *key, size_t keylen, const void *value);
|
|
Packit Service |
80a84b |
int hash_del_bin(struct hash *hash, const char *key, size_t keylen);
|
|
Packit Service |
80a84b |
void *hash_find_bin(const struct hash *hash, const char *key, size_t keylen);
|
|
Packit Service |
80a84b |
unsigned int hash_get_count(const struct hash *hash);
|
|
Packit Service |
80a84b |
void hash_iter_init(const struct hash *hash, struct hash_iter *iter);
|
|
Packit Service |
80a84b |
bool hash_iter_next_bin(struct hash_iter *iter, const char **key, size_t *keylen,
|
|
Packit Service |
80a84b |
const void **value);
|
|
Packit Service |
80a84b |
|
|
Packit Service |
80a84b |
|
|
Packit Service |
80a84b |
static inline int hash_add(struct hash *hash, const char *key, const void *value)
|
|
Packit Service |
80a84b |
{
|
|
Packit Service |
80a84b |
size_t keylen = strlen(key);
|
|
Packit Service |
80a84b |
return hash_add_bin(hash, key, keylen, value);
|
|
Packit Service |
80a84b |
}
|
|
Packit Service |
80a84b |
static inline int hash_add_unique(struct hash *hash,
|
|
Packit Service |
80a84b |
const char *key, const void *value)
|
|
Packit Service |
80a84b |
{
|
|
Packit Service |
80a84b |
size_t keylen = strlen(key);
|
|
Packit Service |
80a84b |
return hash_add_unique_bin(hash, key, keylen, value);
|
|
Packit Service |
80a84b |
}
|
|
Packit Service |
80a84b |
static inline int hash_del(struct hash *hash, const char *key)
|
|
Packit Service |
80a84b |
{
|
|
Packit Service |
80a84b |
size_t keylen = strlen(key);
|
|
Packit Service |
80a84b |
return hash_del_bin(hash, key, keylen);
|
|
Packit Service |
80a84b |
}
|
|
Packit Service |
80a84b |
static inline void *hash_find(const struct hash *hash, const char *key)
|
|
Packit Service |
80a84b |
{
|
|
Packit Service |
80a84b |
size_t keylen = strlen(key);
|
|
Packit Service |
80a84b |
return hash_find_bin(hash, key, keylen);
|
|
Packit Service |
80a84b |
}
|
|
Packit Service |
80a84b |
static inline bool hash_iter_next(struct hash_iter *iter, const char **key,
|
|
Packit Service |
80a84b |
const void **value)
|
|
Packit Service |
80a84b |
{
|
|
Packit Service |
80a84b |
return hash_iter_next_bin(iter, key, NULL, value);
|
|
Packit Service |
80a84b |
}
|