File: hashtable.h

package info (click to toggle)
amoeba 1.1-13
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 732 kB
  • ctags: 971
  • sloc: cpp: 8,315; makefile: 178
file content (49 lines) | stat: -rw-r--r-- 1,297 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef _HASH_H
#define _HASH_H 1

#define BUCKET_BITS 4
#define NUM_BUCKETS (1<<BUCKET_BITS)
#define BUCKET_MASK (NUM_BUCKETS-1)
#define CASE_INSENSITIVE_HASHES 1

typedef void (*hash_callback)(const char * const key,
	      	              const void * const obj,
		   	      const void * const user_data);

class Hashtable {
protected:
	static unsigned int string_hash(const char *str);

	struct linked_list {
		char *key;
		unsigned int hash;
		void *obj;
		struct linked_list *next;
	};
	linked_list *buckets[NUM_BUCKETS];
	bool curves; 

public:
	Hashtable(bool curves = false);
	Hashtable(Hashtable *h);
	~Hashtable();

	void insert(const char * const key, void * const obj);
	void insert(const char * const key, char * const str);
	void remove(const char * const key);
	void *lookup(const char * const key) const;
	void destroy_values();

	bool exists(const char * const key) const;
	char *get_str(const char * const key) const;
	int get_int(const char * const key) const;
	float get_float(const char * const key) const;
	bool get_bool(const char * const key) const;
	
	/* curve specific -- undefined on other values ;-) */
	void finish_curvedata(const float stop, const float start);

	void foreach(hash_callback callback, const void * const user_data);
};

#endif /* !defined(_HASH_H) */