00001 // -*- C++ -*-
00002 /*****************************************************************************
00003 *
00004 * |_|_|_ |_|_ |_ |_|_|_ |_ C O M M U N I C A T I O N
00005 * |_ |_ |_ |_ |_ |_ N E T W O R K S
00006 * |_ |_ |_ |_ |_ |_ C L A S S
00007 * |_|_|_ |_ |_|_ |_|_|_ |_|_|_|_ L I B R A R Y
00008 *
00009 * $Id: HashTable.h,v 1.4 2002/01/14 11:04:34 spee Exp $
00010 *
00011 * CNClass: CNHashTable --- Abstract base class for hash tables
00012 *
00013 *****************************************************************************
00014 * Copyright (C) 1992-2002 Communication Networks
00015 * Aachen University of Technology
00016 * D-52056 Aachen
00017 * Germany
00018 * Email: cncl-adm@comnets.rwth-aachen.de
00019 *****************************************************************************
00020 * This file is part of the CN class library. All files marked with
00021 * this header are free software; you can redistribute it and/or modify
00022 * it under the terms of the GNU Library General Public License as
00023 * published by the Free Software Foundation; either version 2 of the
00024 * License, or (at your option) any later version. This library is
00025 * distributed in the hope that it will be useful, but WITHOUT ANY
00026 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
00027 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
00028 * License for more details. You should have received a copy of the GNU
00029 * Library General Public License along with this library; if not, write
00030 * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
00031 * USA.
00032 *****************************************************************************/
00033
00034 #ifndef __HashTable_h
00035 #define __HashTable_h
00036
00037 #include <CNCL/Class.h>
00038 #include <CNCL/Param.h>
00039
00040 #include <CNCL/Object.h> // Base class
00041
00042 extern CNClassDesc CN_HASHTABLE; // CNClass CNHashTable description
00043
00044 #include <CNCL/Key.h>
00045
00046
00047 const unsigned long DEFAULT_HASH_TABLE_CAPACITY = 101;
00048
00049
00050 struct HashEntry {
00052 CNKey *he_CNKey;
00054 unsigned long he_HashValue;
00055 };
00056
00057 // forwards
00058 class CNHashIterator;
00059
00063 class CNHashTable : public CNObject
00064 {
00065 protected:
00066 friend class CNHashIterator;
00067
00069 virtual struct HashEntry *HashTable() const = 0;
00070
00072 enum rmKeyType
00073 {
00074 clearKeyOnly, freeMemOfKey, freeMemOfKeyAndObject
00075 };
00076
00077 public:
00085 virtual void store_key(CNKey *k) = 0;
00093 virtual void store_key(CNKey &k) = 0;
00094
00097 virtual CNKey *get_key(const CNKey *k) const = 0;
00100 virtual CNKey *get_key(const CNKey &k) const = 0;
00101
00105 virtual CNObject *get_object(const CNKey *k) const = 0;
00109 virtual CNObject *get_object(const CNKey &k) const = 0;
00110
00116 virtual bool reset_absolutely() = 0;
00122 virtual bool reset_absolutely_w_obj() = 0;
00128 virtual bool delete_key(const CNKey *k) = 0;
00134 virtual bool delete_key(const CNKey &k)
00135 { return delete_key(&k); }
00141 virtual bool delete_key_absolutely(const CNKey *k) = 0;
00147 virtual bool delete_key_absolutely(const CNKey &k) = 0;
00153 virtual bool delete_key_absolutely_w_obj(const CNKey *k) = 0;
00159 virtual bool delete_key_absolutely_w_obj(const CNKey &k) = 0;
00160
00163 virtual bool is_full() const = 0;
00166 virtual bool is_empty() const = 0;
00168 virtual unsigned long get_capacity() const = 0;
00170 virtual unsigned long get_num_entries() const = 0;
00171
00172 /****** Constructors ******************************************************/
00173 public:
00175 CNHashTable() {}
00177 CNHashTable(CNParam *) {}
00178
00179 /****** Member functions required by CNCL *********************************/
00180 public:
00181 virtual CNClassDesc class_desc() const // CNClass description
00182 {
00183 return CN_HASHTABLE;
00184 };
00185
00187 virtual bool is_a(CNClassDesc desc) const
00188 {
00189 return desc == CN_HASHTABLE ? TRUE : CNObject::is_a(desc);
00190 };
00191
00193 static CNHashTable *cast_from_object(CNObject *obj)
00194 {
00195 # ifdef NO_TYPE_CHECK
00196 return (CNHashTable *)obj;
00197 # else
00198 return (CNHashTable *)( !obj || obj->is_a(CN_HASHTABLE)
00199 ? obj : fatal_type(obj->class_desc(), CN_HASHTABLE) );
00200 # endif
00201 }
00202
00204 virtual void print(ostream &strm = cout) const = 0;
00206 virtual void dump (ostream &strm = cout) const = 0;
00207 };
00208
00209 #endif
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001