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 2004/02/08 17:17:33 fox Exp $                             *
00023 ********************************************************************************/
00024 #ifndef FXHASH_H
00025 #define FXHASH_H
00026 
00027 namespace FX {
00028 
00029 
00030 /**
00031 * A hash table for associating handles 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   /// Insert key into the table
00055   void* insert(void* key,void* val);
00056 
00057   /// Remove key from the table
00058   void* remove(void* key);
00059 
00060   /// Return value of key
00061   void* find(void* key) const;
00062 
00063   /// Destructor
00064   virtual ~FXHash();
00065   };
00066 
00067 
00068 }
00069 
00070 #endif

Copyright © 1997-2004 Jeroen van der Zijp