Coda Distributed File System
ohash.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 * ohash.h -- Specification of hash-table type where each bucket is a singly-linked
22 * list (an olist).
23 *
24 */
25
26#ifndef _UTIL_HTAB_H_
27#define _UTIL_HTAB_H_ 1
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include <stdint.h>
34#include <stdio.h>
35
36#ifdef __cplusplus
37}
38#endif
39
40#include "olist.h"
41
42class ohashtab;
44
45class ohashtab {
46 friend class ohashtab_iterator;
47 int sz; // size of the array
48 olist *a; // array of olists
49 intptr_t (*hfn)(void *); // the hash function
50 int cnt;
51
52public:
53 ohashtab(int size, intptr_t (*hashfn)(void *));
54 ohashtab(ohashtab &); // not supported!
55 int operator=(ohashtab &); // not supported!
56 virtual ~ohashtab();
57 void insert(void *, olink *); // add at head of list
58 void append(void *, olink *); // add at tail of list
59 olink *remove(void *, olink *); // remove specified entry
60 olink *first(); // return first element of table
61 olink *last(); // return last element of table
62 olink *get(void *); // return and remove head of list
63 void clear(); // remove all entries
64 int count();
65 int IsMember(void *, olink *);
66 int bucket(void *); // returns bucket number of key
67 virtual void print();
68 virtual void print(FILE *);
69 virtual void print(int);
70
71 /* find object with matching tag in a hash table;
72 return NULL if no such object; key and tag are separate because
73 hash buckets may use different field from tag (Satya, May04) */
74 olink *FindObject(void *key, void *tag, otagcompare_t cmpfn);
75};
76
78 ohashtab *chashtab; // current ohashtab
79 int allbuckets; // iterate over all or single bucket
80 int cbucket; // current bucket
81 olist_iterator *nextlink; // current olist iterator
82public:
83 ohashtab_iterator(ohashtab &, void * = (void *)-1);
85 olink *operator()(); // return next object or 0
86};
87
88#endif /* _UTIL_HTAB_H_ */
Definition: ohash.h:77
~ohashtab_iterator()
Definition: ohash.cc:207
ohashtab_iterator(ohashtab &, void *=(void *) -1)
Definition: ohash.cc:199
olink * operator()()
Definition: ohash.cc:212
Definition: ohash.h:45
int bucket(void *)
Definition: ohash.cc:171
void clear()
Definition: ohash.cc:142
void append(void *, olink *)
Definition: ohash.cc:93
ohashtab(int size, intptr_t(*hashfn)(void *))
Definition: ohash.cc:47
virtual void print()
Definition: ohash.cc:176
olink * remove(void *, olink *)
Definition: ohash.cc:100
void insert(void *, olink *)
Definition: ohash.cc:86
int count()
Definition: ohash.cc:150
int IsMember(void *, olink *)
Definition: ohash.cc:155
int operator=(ohashtab &)
Definition: ohash.cc:71
olink * last()
Definition: ohash.cc:121
virtual ~ohashtab()
Definition: ohash.cc:77
olink * get(void *)
Definition: ohash.cc:136
olink * first()
Definition: ohash.cc:106
olink * FindObject(void *key, void *tag, otagcompare_t cmpfn)
Definition: ohash.cc:161
Definition: olist.h:75
Definition: olist.h:47
int(* otagcompare_t)(void *tag, void *object)
Definition: olist.h:45
TYPE_TAG tag
Definition: symtab.c:72