2004-09-01 22:55:40 +00:00
|
|
|
//===-- llvm/ADT/HashExtras.h - Useful functions for STL hash ---*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 19:46:57 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 19:46:57 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-23 17:46:59 +00:00
|
|
|
//
|
|
|
|
// This file contains some templates that are useful if you are working with the
|
|
|
|
// STL Hashed containers.
|
|
|
|
//
|
2009-04-01 21:33:08 +00:00
|
|
|
// No library is required when using these functions.
|
2001-07-23 17:46:59 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-09-01 22:55:40 +00:00
|
|
|
#ifndef LLVM_ADT_HASHEXTRAS_H
|
|
|
|
#define LLVM_ADT_HASHEXTRAS_H
|
2001-07-23 17:46:59 +00:00
|
|
|
|
2003-08-15 17:52:02 +00:00
|
|
|
#include <string>
|
2002-01-20 22:54:45 +00:00
|
|
|
|
|
|
|
// Cannot specialize hash template from outside of the std namespace.
|
2002-07-24 22:20:00 +00:00
|
|
|
namespace HASH_NAMESPACE {
|
2001-07-23 17:46:59 +00:00
|
|
|
|
2001-07-28 04:41:10 +00:00
|
|
|
// Provide a hash function for arbitrary pointers...
|
|
|
|
template <class T> struct hash<T *> {
|
2003-11-16 20:21:15 +00:00
|
|
|
inline size_t operator()(const T *Val) const {
|
|
|
|
return reinterpret_cast<size_t>(Val);
|
|
|
|
}
|
2001-07-28 04:41:10 +00:00
|
|
|
};
|
|
|
|
|
2004-12-08 20:59:18 +00:00
|
|
|
template <> struct hash<std::string> {
|
|
|
|
size_t operator()(std::string const &str) const {
|
|
|
|
return hash<char const *>()(str.c_str());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2002-01-20 22:54:45 +00:00
|
|
|
} // End namespace std
|
|
|
|
|
2001-07-23 17:46:59 +00:00
|
|
|
#endif
|