blob: d7e48a3b625d900458564bbd7bb064b6449f1ee1 [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 Lattner697954c2002-01-20 22:54:45 +000014#include <ext/hash_map>
15
16// Cannot specialize hash template from outside of the std namespace.
17namespace std {
Chris Lattner57dbb3a2001-07-23 17:46:59 +000018
19template <> struct hash<string> {
20 size_t operator()(string const &str) const {
21 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