btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / bin / bfs_tools / lib / Hashtable.h
blobd673fd167fbca3a666ee621e7a82cfc7eb1ba23c
1 #ifndef HASHTABLE_H
2 #define HASHTABLE_H
3 /* Hashtable - a general purpose hash table
4 **
5 ** Copyright 2001 pinc Software. All Rights Reserved.
6 ** Released under the terms of the MIT license.
7 */
10 #include "SupportDefs.h"
13 #define HASH_EMPTY_NONE 0
14 #define HASH_EMPTY_FREE 1
15 #define HASH_EMPTY_DELETE 2
17 class Hashtable
19 public:
20 Hashtable(int capacity = 100, float loadFactor = 0.75);
21 ~Hashtable();
23 void SetHashFunction(uint32 (*func)(const void *));
24 void SetCompareFunction(bool (*func)(const void *, const void *));
26 bool IsEmpty() const;
27 bool ContainsKey(const void *key);
28 void *GetValue(const void *key);
30 bool Put(const void *key, void *value);
31 void *Remove(const void *key);
33 status_t GetNextEntry(void **value);
34 void Rewind();
36 void MakeEmpty(int8 keyMode = HASH_EMPTY_NONE,int8 valueMode = HASH_EMPTY_NONE);
37 size_t Size() const;
39 protected:
40 class Entry
42 public:
43 Entry(Entry *_next, const void *_key, void *_value)
44 : next(_next), key(_key), value(_value) {}
46 Entry *next;
47 const void *key;
48 void *value;
51 bool Rehash();
52 Entry *GetHashEntry(const void *key);
54 int32 fCapacity,fCount,fThreshold,fModCount;
55 float fLoadFactor;
56 Entry **fTable;
57 uint32 (*fHashFunc)(const void *);
58 bool (*fCompareFunc)(const void *, const void *);
60 int32 fIteratorIndex;
61 Entry *fIteratorEntry;
64 #endif // HASHTABLE_H