Coda Distributed File System
ds_hash.h
Go to the documentation of this file.
1
2/*
3** The "hash" data structure; a hash table
4*/
5
6#ifndef _DS_HASH_H_
7#define _DS_HASH_H_
8
9#include <odytypes.h>
10#include <ds_list.h>
11
12/*
13 A hash table is a collection of ds_list_t's.
14 They are not thread safe
15
16 Hash tables have many of the same properties that lists do.
17 It's probably necessary to understand ds_list_t to understand
18 ds_hash_t. In particular, the ordering function determines whether
19 or not the buckets are sorted, and whether the member and duplicate
20 tests use pointer-equality or the ordering function for equality.
21
22*/
23
24typedef struct ds_hash_t ds_hash_t; /* opaque hashtable */
25
26#ifdef __STDC__ /* hash tables have hash functions */
27typedef long (*HFN)(void *);
28#else
29typedef long (*HFN)();
30#endif
31
32/*
33 The following operations are allowed on hash tables
34*/
35
36/*** Observers ***/
37
38extern bool ds_hash_valid(ds_hash_t *t);
39extern int ds_hash_count(ds_hash_t *t);
40extern void *ds_hash_first(ds_hash_t *t, void *e);
41extern void *ds_hash_last(ds_hash_t *t, void *e);
42extern void *ds_hash_member(ds_hash_t *t, void *e);
43
44/*** Mutators ***/
45
47 bool safe_destroy, bool dups_ok);
48extern void ds_hash_destroy(ds_hash_t *t);
49extern void *ds_hash_insert(ds_hash_t *t, void *e);
50extern void *ds_hash_append(ds_hash_t *t, void *e);
51extern void *ds_hash_get_first(ds_hash_t *t, void *e);
52extern void *ds_hash_get_last(ds_hash_t *t, void *e);
53extern void *ds_hash_remove(ds_hash_t *t, void *e);
54
55/*** Iterators ***/
56
57typedef struct ds_hash_iter_t ds_hash_iter_t; /* opaque */
58
59/*
60 You can create an interator, destroy an iterator, or ask for the
61 "next" element in the sequence. Iterators and hash tables
62 communicate with one another: if an iterator's "next" element is
63 removed from the iterator's table, the iterator will be advanced
64 one element. Once an iterator has reached the end of the table
65 (i.e. ds_hash_iter_next returns NULL) it is considered closed: new
66 items added to the table will not be picked up by the iterator.
67 New items added to a table may or may not be picked up by the
68 iterator. Frankly, twiddling the table while the iterator is
69 hooked up is kinda silly anyway.
70*/
71
74extern void *ds_hash_iter_next(ds_hash_iter_t *i);
75
76#endif /* _DS_HASH_H_ */
void * ds_hash_first(ds_hash_t *t, void *e)
Definition: ds_hash.c:35
int ds_hash_count(ds_hash_t *t)
Definition: ds_hash.c:29
void * ds_hash_remove(ds_hash_t *t, void *e)
Definition: ds_hash.c:170
void * ds_hash_insert(ds_hash_t *t, void *e)
Definition: ds_hash.c:109
ds_hash_iter_t * ds_hash_iter_create(ds_hash_t *t)
Definition: ds_hash.c:200
void * ds_hash_last(ds_hash_t *t, void *e)
Definition: ds_hash.c:46
void * ds_hash_append(ds_hash_t *t, void *e)
Definition: ds_hash.c:125
void * ds_hash_iter_next(ds_hash_iter_t *i)
Definition: ds_hash.c:226
void ds_hash_destroy(ds_hash_t *t)
Definition: ds_hash.c:92
void * ds_hash_get_last(ds_hash_t *t, void *e)
Definition: ds_hash.c:155
ds_hash_t * ds_hash_create(COMPFN c, HFN h, int nbuckets, bool safe_destroy, bool dups_ok)
Definition: ds_hash.c:68
long(* HFN)()
Definition: ds_hash.h:29
void * ds_hash_member(ds_hash_t *t, void *e)
Definition: ds_hash.c:57
void ds_hash_iter_destroy(ds_hash_iter_t *i)
Definition: ds_hash.c:214
void * ds_hash_get_first(ds_hash_t *t, void *e)
Definition: ds_hash.c:140
bool ds_hash_valid(ds_hash_t *t)
Definition: ds_hash.c:21
typdef int(* COMPFN)()
Definition: odytypes.h:54
Definition: ds_hash.private.h:37
Definition: ds_hash.private.h:29
int nbuckets
Definition: ds_hash.private.h:32
char c
Definition: tdb.c:54