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*/
7
8
9#include "SupportDefs.h"
10
11
12#define HASH_EMPTY_NONE 0
13#define HASH_EMPTY_FREE 1
14#define HASH_EMPTY_DELETE 2
15
16class Hashtable
17{
18	public:
19		Hashtable(int capacity = 100, float loadFactor = 0.75);
20		~Hashtable();
21
22		void	SetHashFunction(uint32 (*func)(const void *));
23		void	SetCompareFunction(bool (*func)(const void *, const void *));
24
25		bool	IsEmpty() const;
26		bool	ContainsKey(const void *key);
27		void	*GetValue(const void *key);
28
29		bool	Put(const void *key, void *value);
30		void	*Remove(const void *key);
31
32		status_t GetNextEntry(void **value);
33		void	Rewind();
34
35		void	MakeEmpty(int8 keyMode = HASH_EMPTY_NONE,int8 valueMode = HASH_EMPTY_NONE);
36		size_t	Size() const;
37
38	protected:
39		class Entry
40		{
41			public:
42				Entry(Entry *_next, const void *_key, void *_value)
43					: next(_next), key(_key), value(_value) {}
44
45				Entry		*next;
46				const void	*key;
47				void		*value;
48		};
49
50		bool	Rehash();
51		Entry	*GetHashEntry(const void *key);
52
53		int32	fCapacity,fCount,fThreshold,fModCount;
54		float	fLoadFactor;
55		Entry	**fTable;
56		uint32	(*fHashFunc)(const void *);
57		bool	(*fCompareFunc)(const void *, const void *);
58
59		int32	fIteratorIndex;
60		Entry	*fIteratorEntry;
61};
62
63#endif  // HASHTABLE_H
64