59 lines
994 B
C++
59 lines
994 B
C++
// hash.h
|
|
// Author: Josh Holtrop
|
|
// Date: 08/28/05
|
|
// Modified: 08/28/05
|
|
// Implements a basic hash table (u32_t -> void*)
|
|
|
|
#ifndef __HOS_HASH_H__
|
|
#define __HOS_HASH_H__ __HOS_HASH_H__
|
|
|
|
#include "hos_defines.h"
|
|
#include "lang/vector.h"
|
|
|
|
typedef struct
|
|
{
|
|
u32_t key;
|
|
void *data;
|
|
} hash_entry_t;
|
|
|
|
class hash
|
|
{
|
|
private:
|
|
/* index into hash_primes[] */
|
|
u32_t mySizeIndex;
|
|
|
|
/* How many values in the hash table */
|
|
u32_t mySize;
|
|
|
|
/* array of hash entries */
|
|
vector< vector<hash_entry_t> > myTable;
|
|
|
|
/* hash the key to a table index */
|
|
u32_t hash_key(u32_t key);
|
|
|
|
public:
|
|
/* Constructor */
|
|
hash();
|
|
|
|
/* Add a value to the hash table */
|
|
int add(u32_t key, void *val);
|
|
|
|
/* Retrieve a value from the hash table */
|
|
void *get(u32_t key);
|
|
|
|
/* Remove a value from the hash table */
|
|
int remove(u32_t key);
|
|
|
|
/* Check if the given key exists in the hash table */
|
|
int exists(u32_t key);
|
|
|
|
/* Dump a hash */
|
|
void dump();
|
|
|
|
/* How many values are in the hash table */
|
|
u32_t size();
|
|
};
|
|
|
|
#endif
|
|
|