headers/bsd: Add sys/queue.h.
[haiku.git] / src / servers / app / HashTable.h
blob9b48513c99d7bec68b40978ff38869276e829675
1 /*
2 * Copyright 2005, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Axel Dörfler, axeld@pinc-software.de
7 */
8 #ifndef _HASH_TABLE_H_
9 #define _HASH_TABLE_H_
12 #include <SupportDefs.h>
15 class Hashable {
16 public:
17 virtual ~Hashable() {};
18 virtual uint32 Hash() const = 0;
19 virtual bool CompareTo(Hashable& hashable) const = 0;
22 class HashTable {
23 public:
24 HashTable(bool owning = false, int32 capacity = 100, float loadFactor = 0.75);
25 ~HashTable();
27 void MakeEmpty(bool deleteValues = true);
28 bool IsEmpty() const { return fCount == 0; }
29 bool ContainsKey(Hashable& key) const { return _GetHashEntry(key) != NULL; }
30 int32 CountItems() const { return fCount; }
32 Hashable *GetValue(Hashable& key) const;
34 bool AddItem(Hashable* value);
35 Hashable *RemoveItem(Hashable& key);
37 protected:
38 struct entry;
40 bool _Rehash();
41 entry *_GetHashEntry(Hashable& key) const;
43 entry** fTable;
44 int32 fCapacity, fCount, fThreshold;
45 float fLoadFactor;
46 bool fOwning;
49 #endif /* HASHTABLE_H */