Coda Distributed File System
dhash.h
Go to the documentation of this file.
1/* BLURB gpl
2
3 Coda File System
4 Release 6
5
6 Copyright (c) 1987-2003 Carnegie Mellon University
7 Additional copyrights listed below
8
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU General Public Licence Version 2, as shown in the
11file LICENSE. The technical and financial contributors to Coda are
12listed in the file CREDITS.
13
14 Additional copyrights
15 none currently
16
17#*/
18
19/*
20 *
21 * dhash.h -- Specification of hash-table type where each bucket is a
22 * doubly-linked list (a dlist).
23 *
24 */
25
26#ifndef _UTIL_DHTAB_H_
27#define _UTIL_DHTAB_H_ 1
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <stdio.h>
34
35#ifdef __cplusplus
36}
37#endif
38
39#include "dlist.h"
40
41class dlink;
42class dhashtab;
44
45class dhashtab {
46 friend class dhashtab_iterator;
47 int sz; // size of the array
48 dlist *a; // array of dlists
49 int (*hfn)(void *); // the hash function
50 int cnt;
51
52public:
53 dhashtab(int, int (*)(void *), CFN);
54 dhashtab(dhashtab &); // not supported!
55 int operator=(dhashtab &); // not supported!
56 virtual ~dhashtab();
57 void insert(void *, dlink *); // add in sorted order of list
58 void prepend(void *, dlink *); // add at head of list
59 void append(void *, dlink *); // add at tail of list
60 dlink *remove(void *, dlink *); // remove specified entry
61 dlink *first(); // return first element of table
62 dlink *last(); // return last element of table
63 dlink *get(void *,
64 DlGetType = DlGetMin); // return and remove head or tail of list
65 void clear(); // remove all entries
66 int count();
67 int IsMember(void *, dlink *);
68 int bucket(void *); // returns bucket number of key
69 virtual void print();
70 virtual void print(FILE *);
71 virtual void print(int);
72};
73
75{
78};
79
81 dhashtab *chashtab; // current dhashtab
82 int allbuckets; // iterate over all or single bucket
83 int cbucket; // current bucket
84 dlist_iterator *nextlink; // current dlist iterator
85 DhIterOrder order; // iteration order
86public:
88 void * = (void *)-1); // iterates in ASCENDING order!
89 dhashtab_iterator(dhashtab &, DhIterOrder, void * = (void *)-1);
91 dlink *operator()(); // return next object or 0
92};
93
94#endif /* _UTIL_HTAB_H_ */
Definition: dhash.h:80
dlink * operator()()
Definition: dhash.cc:232
~dhashtab_iterator()
Definition: dhash.cc:227
dhashtab_iterator(dhashtab &, void *=(void *) -1)
Definition: dhash.cc:203
Definition: dhash.h:45
virtual ~dhashtab()
Definition: dhash.cc:80
int IsMember(void *, dlink *)
Definition: dhash.cc:168
virtual void print()
Definition: dhash.cc:179
int count()
Definition: dhash.cc:163
void clear()
Definition: dhash.cc:155
dlink * last()
Definition: dhash.cc:131
void insert(void *, dlink *)
Definition: dhash.cc:89
dlink * first()
Definition: dhash.cc:116
void prepend(void *, dlink *)
Definition: dhash.cc:96
int operator=(dhashtab &)
Definition: dhash.cc:74
int bucket(void *)
Definition: dhash.cc:174
dhashtab(int, int(*)(void *), CFN)
Definition: dhash.cc:47
dlink * remove(void *, dlink *)
Definition: dhash.cc:110
dlink * get(void *, DlGetType=DlGetMin)
Definition: dhash.cc:146
void append(void *, dlink *)
Definition: dhash.cc:103
Definition: dlist.h:80
Definition: dlist.h:50
DhIterOrder
Definition: dhash.h:75
@ DhAscending
Definition: dhash.h:76
@ DhDescending
Definition: dhash.h:77
int(* CFN)(dlink *, dlink *)
Definition: dlist.h:42
DlGetType
Definition: dlist.h:45
@ DlGetMin
Definition: dlist.h:46