![]() |
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,2012 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU Lesser General Public License as published by * 00010 * the Free Software Foundation; either version 3 of the License, or * 00011 * (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 * 00016 * GNU Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00020 ********************************************************************************/ 00021 #ifndef FXHASH_H 00022 #define FXHASH_H 00023 00024 namespace FX { 00025 00026 00031 class FXAPI FXHash { 00032 protected: 00033 struct Entry { 00034 void* name; 00035 void* data; 00036 }; 00037 protected: 00038 FXArray<Entry> table; // Hash table 00039 FXuint used; // Number of used entries 00040 FXuint free; // Number of free entries 00041 protected: 00042 static const Entry init; // Initialization value 00043 private: 00044 FXHash(const FXHash&); 00045 FXHash &operator=(const FXHash&); 00046 public: 00047 00051 FXHash(); 00052 00057 FXbool size(FXuint m); 00058 00062 FXuint size() const { return table.no(); } 00063 00067 FXuint no() const { return used; } 00068 00073 void* insert(void* name,void* data=NULL); 00074 00079 void* replace(void* name,void* data=NULL); 00080 00084 void* remove(void* name); 00085 00089 void* find(void* name) const; 00090 00094 FXbool empty(FXuint pos) const { return (table[pos].name==NULL)||(table[pos].name==(void*)-1L); } 00095 00099 void* key(FXuint pos) const { return table[pos].name; } 00100 00104 void* value(FXuint pos) const { return table[pos].data; } 00105 00109 void clear(); 00110 00112 virtual ~FXHash(); 00113 }; 00114 00115 00116 } 00117 00118 #endif
|
|