Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXHash.h

00001 /******************************************************************************** 00002 * * 00003 * H a s h T a b l e C l a s s * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2003,2004 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.6.2.1 2004/12/20 14:32:42 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* val; 00038 }; 00039 private: 00040 FXEntry *table; // Hash table 00041 FXuint used; // Number of used entries 00042 FXuint free; // Number of free entries 00043 FXuint max; // Maximum entry index 00044 private: 00045 void resize(FXuint m); 00046 private: 00047 FXHash(const FXHash&); 00048 FXHash &operator=(const FXHash&); 00049 public: 00050 00051 /// Construct empty hash table 00052 FXHash(); 00053 00054 /// Return number of items in table 00055 FXuint no() const { return used; } 00056 00057 /// Insert key into the table 00058 void* insert(void* key,void* val); 00059 00060 /// Replace key in table 00061 void* replace(void* key,void* val); 00062 00063 /// Remove key from the table 00064 void* remove(void* key); 00065 00066 /// Return value of key 00067 void* find(void* key) const; 00068 00069 /// Clear hash table 00070 void clear(); 00071 00072 /// Destructor 00073 virtual ~FXHash(); 00074 }; 00075 00076 00077 } 00078 00079 #endif

Copyright © 1997-2004 Jeroen van der Zijp