00001 /********** 00002 This library is free software; you can redistribute it and/or modify it under 00003 the terms of the GNU Lesser General Public License as published by the 00004 Free Software Foundation; either version 2.1 of the License, or (at your 00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) 00006 00007 This library is distributed in the hope that it will be useful, but WITHOUT 00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00009 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00010 more details. 00011 00012 You should have received a copy of the GNU Lesser General Public License 00013 along with this library; if not, write to the Free Software Foundation, Inc., 00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00015 **********/ 00016 // Copyright (c) 1996-2010 Live Networks, Inc. All rights reserved. 00017 // Generic Hash Table 00018 // C++ header 00019 00020 #ifndef _HASH_TABLE_HH 00021 #define _HASH_TABLE_HH 00022 00023 #ifndef _BOOLEAN_HH 00024 #include "Boolean.hh" 00025 #endif 00026 00027 class HashTable { 00028 public: 00029 virtual ~HashTable(); 00030 00031 // The following must be implemented by a particular 00032 // implementation (subclass): 00033 static HashTable* create(int keyType); 00034 00035 virtual void* Add(char const* key, void* value) = 0; 00036 // Returns the old value if different, otherwise 0 00037 virtual Boolean Remove(char const* key) = 0; 00038 virtual void* Lookup(char const* key) const = 0; 00039 // Returns 0 if not found 00040 virtual unsigned numEntries() const = 0; 00041 Boolean IsEmpty() const { return numEntries() == 0; } 00042 00043 // Used to iterate through the members of the table: 00044 class Iterator { 00045 public: 00046 // The following must be implemented by a particular 00047 // implementation (subclass): 00048 static Iterator* create(HashTable& hashTable); 00049 00050 virtual ~Iterator(); 00051 00052 virtual void* next(char const*& key) = 0; // returns 0 if none 00053 00054 protected: 00055 Iterator(); // abstract base class 00056 }; 00057 00058 // A shortcut that can be used to successively remove each of 00059 // the entries in the table (e.g., so that their values can be 00060 // deleted, if they happen to be pointers to allocated memory). 00061 void* RemoveNext(); 00062 00063 protected: 00064 HashTable(); // abstract base class 00065 }; 00066 00067 // Warning: The following are deliberately the same as in 00068 // Tcl's hash table implementation 00069 int const STRING_HASH_KEYS = 0; 00070 int const ONE_WORD_HASH_KEYS = 1; 00071 00072 #endif
1.5.2