live
HashTable.hh
Go to the documentation of this file.
1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// Copyright (c) 1996-2024 Live Networks, Inc. All rights reserved.
17// Generic Hash Table
18// C++ header
19
20#ifndef _HASH_TABLE_HH
21#define _HASH_TABLE_HH
22
23#ifndef _BOOLEAN_HH
24#include "Boolean.hh"
25#endif
26
27class HashTable {
28public:
29 virtual ~HashTable();
30
31 // The following must be implemented by a particular
32 // implementation (subclass):
33 static HashTable* create(int keyType);
34
35 virtual void* Add(char const* key, void* value) = 0;
36 // Returns the old value if different, otherwise 0
37 virtual Boolean Remove(char const* key) = 0;
38 virtual void* Lookup(char const* key) const = 0;
39 // Returns 0 if not found
40 virtual unsigned numEntries() const = 0;
41 Boolean IsEmpty() const { return numEntries() == 0; }
42
43 // Used to iterate through the members of the table:
44 class Iterator {
45 public:
46 // The following must be implemented by a particular
47 // implementation (subclass):
48 static Iterator* create(HashTable const& hashTable);
49
50 virtual ~Iterator();
51
52 virtual void* next(char const*& key) = 0; // returns 0 if none
53
54 protected:
55 Iterator(); // abstract base class
56 };
57
58 // A shortcut that can be used to successively remove each of
59 // the entries in the table (e.g., so that their values can be
60 // deleted, if they happen to be pointers to allocated memory).
61 void* RemoveNext();
62
63 // Returns the first entry in the table.
64 // (This is useful for deleting each entry in the table, if the entry's destructor also removes itself from the table.)
65 void* getFirst();
66
67protected:
68 HashTable(); // abstract base class
69};
70
71// Warning: The following are deliberately the same as in
72// Tcl's hash table implementation
73int const STRING_HASH_KEYS = 0;
74int const ONE_WORD_HASH_KEYS = 1;
75
76#endif
unsigned char Boolean
Definition: Boolean.hh:25
int const ONE_WORD_HASH_KEYS
Definition: HashTable.hh:74
int const STRING_HASH_KEYS
Definition: HashTable.hh:73
static Iterator * create(HashTable const &hashTable)
virtual void * next(char const *&key)=0
virtual void * Lookup(char const *key) const =0
void * RemoveNext()
virtual Boolean Remove(char const *key)=0
Boolean IsEmpty() const
Definition: HashTable.hh:41
virtual unsigned numEntries() const =0
static HashTable * create(int keyType)
virtual ~HashTable()
void * getFirst()
virtual void * Add(char const *key, void *value)=0