2003-10-01 02:37:50 +08:00
|
|
|
//===-- HashExtras.h - Useful functions for STL hash containers -*- C++ -*-===//
|
2003-10-21 03:46:57 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-24 01:46:59 +08:00
|
|
|
//
|
|
|
|
// This file contains some templates that are useful if you are working with the
|
|
|
|
// STL Hashed containers.
|
|
|
|
//
|
|
|
|
// No library is required when using these functinons.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2003-06-17 08:35:55 +08:00
|
|
|
#ifndef SUPPORT_HASHEXTRAS_H
|
|
|
|
#define SUPPORT_HASHEXTRAS_H
|
2001-07-24 01:46:59 +08:00
|
|
|
|
2002-10-28 10:11:53 +08:00
|
|
|
#include "Support/hash_map"
|
2003-08-16 01:52:02 +08:00
|
|
|
#include <string>
|
2002-01-21 06:54:45 +08:00
|
|
|
|
|
|
|
// Cannot specialize hash template from outside of the std namespace.
|
2002-07-25 06:20:00 +08:00
|
|
|
namespace HASH_NAMESPACE {
|
2001-07-24 01:46:59 +08:00
|
|
|
|
2002-07-25 06:20:00 +08:00
|
|
|
template <> struct hash<std::string> {
|
|
|
|
size_t operator()(std::string const &str) const {
|
2001-07-24 01:46:59 +08:00
|
|
|
return hash<char const *>()(str.c_str());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2001-07-28 12:41:10 +08:00
|
|
|
// Provide a hash function for arbitrary pointers...
|
|
|
|
template <class T> struct hash<T *> {
|
|
|
|
inline size_t operator()(const T *Val) const { return (size_t)Val; }
|
|
|
|
};
|
|
|
|
|
2002-01-21 06:54:45 +08:00
|
|
|
} // End namespace std
|
|
|
|
|
2001-07-24 01:46:59 +08:00
|
|
|
#endif
|