/*
 * Copyright (c) 2005-2006 Tom N Harris.
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 *
 *     A copy of the GNU General Public License can be found at
 *     http://www.gnu.org/
 *
 * Written by Tom N Harris <telliamed@whoopdedo.org>
 *
 */

#ifndef STRING_HASH_FUN_H
#define STRING_HASH_FUN_H

#include <ext/hash_fun.h>

namespace __gnu_cxx
{
using std::size_t;

inline size_t __stl_hash_string(const wchar_t* __s)
{
  unsigned long __h = 0;
  for ( ; *__s; ++__s)
    __h = 5*__h + *__s;
  return size_t(__h);
}

inline size_t __stl_hash_string(const char* __s, size_t __len)
{
  unsigned long __h = 0;
  size_t __n = __len;
  for ( ; __n; ++__s, --__n)
    __h = 5*__h + *__s;
  return size_t(__h);
}

inline size_t __stl_hash_string(const wchar_t* __s, size_t __len)
{
  unsigned long __h = 0;
  size_t __n = __len;
  for ( ; __n; ++__s, --__n)
    __h = 5*__h + *__s;
  return size_t(__h);
}


template<> struct hash<std::string>
{
  size_t operator()(const std::string& __s) const
	  { return __stl_hash_string(__s.c_str(), __s.size()); }
};

};

#endif /* STRING_HASH_FUN_H */
