home *** CD-ROM | disk | FTP | other *** search
- // This may look like C code, but it is really -*- C++ -*-
- /*
- Copyright (C) 1988 Free Software Foundation
- written by Doug Lea (dl@rocky.oswego.edu)
-
- This file is part of GNU CC.
-
- GNU CC is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY. No author or distributor
- accepts responsibility to anyone for the consequences of using it
- or for whether it serves any particular purpose or works at all,
- unless he says so in writing. Refer to the GNU CC General Public
- License for full details.
-
- Everyone is granted permission to copy, modify and redistribute
- GNU CC, but only under the conditions described in the
- GNU CC General Public License. A copy of this license is
- supposed to have been given to you along with GNU CC so you
- can know your rights and responsibilities. It should be in a
- file named COPYING. Among other things, the copyright notice
- and this notice must be preserved on all copies.
- */
-
-
- #ifndef _<T>ChainedHashTable_h
- #define _<T>ChainedHashTable_h 1
-
- #ifndef _<T>_typedefs
- #define _<T>_typedefs 1
- typedef void (*<T>Procedure)(<T&>);
- typedef <T> (*<T>Mapper)(<T&>);
- typedef <T> (*<T>Combiner)(<T&>, <T&>);
- typedef int (*<T>Predicate)(<T&>);
- typedef int (*<T>Comparator)(<T&>, <T&>);
- #endif
-
- #ifndef _<U>_HashFunction
- #define _<U>_HashFunction 1
- typedef unsigned int (*<U>HashFunction)(<U&>);
- typedef <U&> (*<T>KeyAccess)(<T&>);
- #endif
-
- #include "<T>SLListNode.h"
- class <T>ChainedHashTable;
- class <T>ChainedHashTableTrav;
-
-
- class <T>ChainedHashTable
- {
- friend class <T>ChainedHashTableTrav;
-
- <T>SLListNode** tab;
- int size;
- int cnt;
- <U>HashFunction hash;
- <T>KeyAccess getkey;
-
- public:
- <T>ChainedHashTable(int sz,
- <U>HashFunction h,
- <T>KeyAccess acc);
- ~<T>ChainedHashTable();
-
- int count();
- int empty();
- void clear();
-
- int add(<T&> item);
- int add_or_access(<T>& item);
- int access(<U&> key, <T>& item);
- int contains(<U&> key);
- int del(<U&> key);
-
- void apply(<T>Procedure f);
-
- friend int operator == (<T>ChainedHashTable& a,
- <T>ChainedHashTable& b);
- friend int operator != (<T>ChainedHashTable& a,
- <T>ChainedHashTable& b);
-
- void error(const char* msg);
- };
-
- class <T>ChainedHashTableTrav
- {
- <T>ChainedHashTable* h;
- <T>SLListNode* p;
- int pos;
-
-
- public:
- <T>ChainedHashTableTrav(<T>ChainedHashTable& l);
- ~<T>ChainedHashTableTrav();
-
- int null();
- int valid();
- const void* operator void* ();
- int operator ! ();
- void advance();
- <T&> get();
- };
-
-
- inline <T>ChainedHashTable::~<T>ChainedHashTable()
- {
- clear();
- delete tab;
- }
-
- inline int <T>ChainedHashTable::count()
- {
- return cnt;
- }
-
- inline int <T>ChainedHashTable::empty()
- {
- return cnt == 0;
- }
-
- inline int operator != (<T>ChainedHashTable& x, <T>ChainedHashTable& y)
- {
- return !(x == y);
- }
-
- inline <T>ChainedHashTableTrav::~<T>ChainedHashTableTrav() {}
-
- inline int <T>ChainedHashTableTrav::null()
- {
- return pos < 0;
- }
-
- inline int <T>ChainedHashTableTrav::valid()
- {
- return pos >= 0;
- }
-
- inline const void* <T>ChainedHashTableTrav::operator void* ()
- {
- return (pos < 0)? 0 : this;
- }
-
- inline int <T>ChainedHashTableTrav::operator ! ()
- {
- return (pos >= 0);
- }
-
-
- inline <T&> <T>ChainedHashTableTrav::get()
- {
- if (p == 0)
- h->error("operation on null traverser");
- return p->hd;
- }
-
-
- extern void default_<T>ChainedHashTable_error_handler(char*);
- extern one_arg_error_handler_t <T>ChainedHashTable_error_handler;
-
- extern one_arg_error_handler_t
- set_<T>ChainedHashTable_error_handler(one_arg_error_handler_t f);
-
-
- #endif
-