aboutsummaryrefslogtreecommitdiff
path: root/htable.h
blob: c373baa31527fcc22d68039ba20b32f87c07eee5 (plain)
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
// Copyright (C) 2023 Dzshy <dzshy@outlook.com>. All Rights Reserved.
// Licensed under Non-Profit Open Software License ("Non-Profit OSL") 3.0.

#ifndef HTABLE_H_
#define HTABLE_H_

#include <stdbool.h>
#include <stdint.h>

typedef struct {
    void *buf;
    int size;
    int cap;
    int taken;
    void *begin;
    int elemsz;
    uint32_t (*hash)(void *);
    bool (*eq)(void *, void *);
} HTable;

void htable_init(HTable *ht, int elemsz, int cap, uint32_t (*hash)(void *),
                 bool (*eq)(void *, void *));
bool htable_insert(HTable *ht, void *elem);
void htable_del(HTable *ht, void *iter);

// return a iterator
void *htable_find(HTable *ht, void *elem);
void *htable_begin(HTable *ht);
void *htable_next(HTable *ht, void *iter);

#endif