Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
00001 /******************************************************************************** 00002 * * 00003 * H a s h T a b l e C l a s s * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2003,2006 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXHash.h,v 1.12 2006/01/22 17:58:04 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXHASH_H 00025 #define FXHASH_H 00026 00027 namespace FX { 00028 00029 00030 /** 00031 * A hash table for associating pointers to pointers. 00032 */ 00033 class FXAPI FXHash { 00034 private: 00035 struct FXEntry { 00036 void* key; 00037 void* value; 00038 }; 00039 private: 00040 FXEntry *table; // Hash table 00041 FXuint total; // Table size 00042 FXuint used; // Number of used entries 00043 FXuint free; // Number of free entries 00044 private: 00045 FXHash(const FXHash&); 00046 FXHash &operator=(const FXHash&); 00047 public: 00048 00049 /// Construct empty hash table 00050 FXHash(); 00051 00052 /// Resize the table to the given size. 00053 void size(FXuint m); 00054 00055 /// Return the size of the table 00056 FXint size() const { return total; } 00057 00058 /// Return number of items in table 00059 FXuint no() const { return used; } 00060 00061 /// Insert key into the table 00062 void* insert(void* key,void* value); 00063 00064 /// Replace key in table 00065 void* replace(void* key,void* value); 00066 00067 /// Remove key from the table 00068 void* remove(void* key); 00069 00070 /// Return value of key 00071 void* find(void* key) const; 00072 00073 /// Return true if slot is empty 00074 bool empty(FXint pos) const { return (table[pos].key==NULL)||(table[pos].key==(void*)-1L); } 00075 00076 /// Return key at position pos 00077 void* key(FXint pos) const { return table[pos].key; } 00078 00079 /// Return data pointer at position pos 00080 void* value(FXint pos) const { return table[pos].value; } 00081 00082 /// Clear hash table 00083 void clear(); 00084 00085 /// Destructor 00086 virtual ~FXHash(); 00087 }; 00088 00089 00090 } 00091 00092 #endif
Copyright © 1997-2005 Jeroen van der Zijp |