quick start:g++ [flags ...] file ... #include <HashTable.h> HashTable(ALLOCATION alloc = SYSTEM, long initial_capacity = DEF_CAPACITY, float load_factor = DEF_LOAD_FACTOR)); TObject* get(const THashable& key); const TObject* get(const THashable& key) const; boolean insert(THashable& key, TObject* value); boolean keys(Vector& keys_list) const; boolean values(Vector<TObject>& items_list) const;
description:// declare a character hash table and insert a character in it // HashTable<String,Char> table0; Char item(L'a'); String key(L"test_key"); table0.insert(key, &item); // get the item out // if(table0.get(key)->ne(item)) { // error // }
static const String CLASS_NAME = L"HashTable";
static const String DEF_PARAM = L"HashTable";
static const String PARAM_NODES = L"hash_table";
static const String PARAM_LOAD_FACTOR = L"load_factor";
static const float DEF_LOAD_FACTOR = 0.75;
static const long DEF_CAPACITY = 100;
static const float LOAD_LOWER_BOUND = 0.10;
static const long ERR = 40800;
typedef Pair< THashable, Node<TObject> > HashNode;
typedef HashTable<THashable, TObject> Type;
Vector< SingleLinkedList<HashNode> > table_d;
Float load_factor_d;
Long num_items_d;
ALLOCATION alloc_d;
static Integral::DEBUG debug_level_d;
static MemoryManager mgr_d;
static const String& name();
static boolean diagnose(Integral::DEBUG debug_level);
static boolean setDebug(Integral::DEBUG debug_level);
boolean debug(const unichar* message) const;
~HashTable();
HashTable(ALLOCATION alloc = SYSTEM, long initial_capacity = DEF_CAPACITY, float load_factor = DEF_LOAD_FACTOR);
HashTable(const HashTable<THashable, TObject>& copy_table);
boolean assign(const HashTable<THashable, TObject>& copy_table);
HashTable& operator=(const HashTable<THashable, TObject>& arg);
long sofSize() const;
boolean read(Sof& sof, long tag);
boolean write(Sof& sof, long tag) const;
boolean read(Sof& sof, long tag, const String& name);
boolean write(Sof& sof, long tag, const String& name) const;
boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param_a = true,boolean nested_a = false);
boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;
boolean eq(const HashTable<THashable, TObject>& compare_node) const;
void* operator new(size_t size);
void* operator new[](size_t size);
void operator delete(void* ptr);
void operator delete[](void* ptr);
static boolean setGrowSize(long grow_size);
boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE);
boolean ne(const HashTable<THashable, TObject>& compare_table) const;
TObject* get(const String& key);
boolean insert(THashable& key, TObject* value);
boolean remove(const THashable& key, TObject*& value);
boolean remove(const THashable& key);
boolean keys(Vector<THashable>& keys_vector) const;
boolean values(Vector<TObject>& values) const;
long getCapacity() const;
boolean setCapacity(long capacity);
boolean setLoadFactor(float factor);
long getNumItems() const;
boolean isEmpty() const;
boolean containsKey(const THashable& key);
boolean containsValue(TObject* item);
ALLOCATION getAllocationMode() const;
boolean setAllocationMode(ALLOCATION alloc) const;
boolean findKey(long& index, const THashable& key);
boolean rehash(long new_capacity);
const THashable& getCurrKey(long i) const;
THashable& getCurrKey(long i);
const TObject* getCurrObject(long i) const;
TObject* getCurrObject(long i);
boolean setCurrObject(long i, TObject* arg);
boolean getList(SingleLinkedList<HashNode>& arg_a);
boolean assignFromList(SingleLinkedList<HashNode>& arg_a);
friend class HashTableDiagnose;examples:
#include <HashTable.h> int main() { // local variables // HashTable<String, Long> ages; String name; Long age; // insert 4 peoples names and ages // name.assign(L"Rick"); age.assign(23); ages.insert(name, &age); name.assign(L"Jon"); age.assign(26); ages.insert(name, &age); name.assign(L"Shivali"); age.assign(24); ages.insert(name, &age); name.assign(L"Issac"); age.assign(21); ages.insert(name, &age); // extract a name and print out the age // name.assign(L"Rick"); ages.get(name)->debug(L"Rick's age"); // delete Shivali's entry // name.assign(L"Shivali"); ages.remove(name); // exit gracefully // Integral::exit(); }
#include <HashTable.h> int main() { // local variables // HashTable<String, Long> ages(USER); String name; Long* age; // insert 4 peoples names and ages // name.assign(L"Rick"); age = new Long(23); ages.insert(name, age); name.assign(L"Jon"); age = new Long(26); ages.insert(name, age); name.assign(L"Shivali"); age = new Long(24); ages.insert(name, age); name.assign(L"Issac"); age = new Long(21); ages.insert(name, age); // extract a name and print out the age // name.assign(L"Rick"); ages.get(name)->debug(L"Rick's age"); // remove Shivali's entry // name.assign(L"Shivali"); age = (Long*)NULL; ages.remove(name, age); delete age; // cleanup memory // ages.clear(Integral::FREE); }