blob: f1a010c9584c2e881fdd7ef10ba49591a34cb117 (
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/* apk_hash.h - Alpine Package Keeper (APK)
*
* Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. See http://www.gnu.org/ for details.
*/
#ifndef APK_HASH_H
#define APK_HASH_H
#include <malloc.h>
#include "apk_defines.h"
#include "apk_blob.h"
typedef void *apk_hash_item;
typedef unsigned long (*apk_hash_f)(apk_blob_t);
typedef int (*apk_hash_compare_f)(apk_blob_t, apk_blob_t);
typedef void (*apk_hash_delete_f)(apk_hash_item);
typedef int (*apk_hash_enumerator_f)(apk_hash_item, void *ctx);
struct apk_hash_ops {
ptrdiff_t node_offset;
apk_blob_t (*get_key)(apk_hash_item item);
unsigned long (*hash_key)(apk_blob_t key);
int (*compare)(apk_blob_t key, apk_blob_t itemkey);
void (*delete_item)(apk_hash_item item);
};
typedef struct hlist_node apk_hash_node;
APK_ARRAY(apk_hash_array, struct hlist_head);
struct apk_hash {
const struct apk_hash_ops *ops;
struct apk_hash_array *buckets;
int num_items;
};
void apk_hash_init(struct apk_hash *h, const struct apk_hash_ops *ops,
int num_buckets);
void apk_hash_free(struct apk_hash *h);
int apk_hash_foreach(struct apk_hash *h, apk_hash_enumerator_f e, void *ctx);
apk_hash_item apk_hash_get(struct apk_hash *h, apk_blob_t key);
void apk_hash_insert(struct apk_hash *h, apk_hash_item item);
void apk_hash_delete(struct apk_hash *h, apk_blob_t key);
#endif
|