hash_utils.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2001  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef _HASH_UTILS_H_
00020 #define _HASH_UTILS_H_
00021 
00022 #include "exult_types.h"
00023 
00024 #ifdef DONT_HAVE_HASH_MAP
00025 #  include <map>
00026 #else
00027 #if HAVE_EXT_HASH_MAP
00028 #  include <ext/hash_map>
00029 #  if (defined(__GNUC__) && (__GNUC__ >= 3) && ( __GNUC_MINOR__ >= 0))
00030 using __gnu_cxx::hash_map;
00031 #  else
00032 using std::hash_map;
00033 #  endif
00034 #else
00035 #  include <hash_map>
00036 #endif
00037 #  ifdef MACOS
00038   using Metrowerks::hash_map;
00039 #  endif
00040 #endif
00041 
00042 #ifdef DONT_HAVE_HASH_SET
00043 #  include <set>
00044 #else
00045 #if HAVE_EXT_HASH_SET
00046 #  include <ext/hash_set>
00047 #  if (defined(__GNUC__) && (__GNUC__ >= 3) && ( __GNUC_MINOR__ >= 0))
00048 using __gnu_cxx::hash_set;
00049 #  else
00050 using std::hash_set;
00051 #  endif
00052 #else
00053 #  include <hash_set>
00054 #endif
00055 #  ifdef MACOS
00056   using Metrowerks::hash_set;
00057 #  endif
00058 #endif
00059 
00060 
00061 #if defined(DONT_HAVE_HASH_MAP) && defined(DONT_HAVE_HASH_SET)
00062 
00063 /*
00064  *  For testing if a string is "less" than another:
00065  */
00066 struct ltstr {
00067   bool operator()(const char* s1, const char* s2) const {
00068     return (std::strcmp(s1, s2) < 0);
00069   }
00070 };
00071 
00072 #else
00073 
00074 /*
00075  *  Hash function for strings:
00076  */
00077 struct hashstr
00078 {
00079   long operator() (const char *str) const
00080   {
00081     const uint32 m = 4294967291u;
00082     uint32 result = 0;
00083     for (; *str != '\0'; ++str)
00084       result = ((result << 8) + *str) % m;
00085     return long(result);
00086   }
00087 };
00088 
00089 /*
00090  *  For testing if two strings match:
00091  */
00092 struct eqstr
00093 {
00094   bool operator()(const char* s1, const char* s2) const {
00095     return std::strcmp(s1, s2) == 0;
00096   }
00097 };
00098 
00099 #endif
00100 
00101 #endif  /* _HASH_UTILS_H_ */

Generated on Mon Jul 9 14:42:47 2007 for ExultEngine by  doxygen 1.5.1