blob: 68a49eac9e9251480db48ff1dddbeea3042e0741 [file] [log] [blame]
Chris Lattner57dbb3a2001-07-23 17:46:59 +00001//===-- HashExtras.h - Useful functions for STL hash containers --*- C++ -*--=//
2//
3// This file contains some templates that are useful if you are working with the
4// STL Hashed containers.
5//
6// No library is required when using these functinons.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_SUPPORT_HASHEXTRAS_H
11#define LLVM_SUPPORT_HASHEXTRAS_H
12
13#include <string>
Chris Lattner4a63b722002-10-28 02:11:53 +000014#include "Support/hash_map"
Chris Lattner697954c2002-01-20 22:54:45 +000015
16// Cannot specialize hash template from outside of the std namespace.
Chris Lattner8dc67162002-07-24 22:20:00 +000017namespace HASH_NAMESPACE {
Chris Lattner57dbb3a2001-07-23 17:46:59 +000018
Chris Lattner8dc67162002-07-24 22:20:00 +000019template <> struct hash<std::string> {
20 size_t operator()(std::string const &str) const {
Chris Lattner57dbb3a2001-07-23 17:46:59 +000021 return hash<char const *>()(str.c_str());
22 }
23};
24
Vikram S. Advebf2b7e82001-07-28 04:41:10 +000025// Provide a hash function for arbitrary pointers...
26template <class T> struct hash<T *> {
27 inline size_t operator()(const T *Val) const { return (size_t)Val; }
28};
29
Chris Lattner697954c2002-01-20 22:54:45 +000030} // End namespace std
31
Chris Lattner57dbb3a2001-07-23 17:46:59 +000032#endif