blob: f648a28c099c58e38934c6b5edd27479cefea653 [file] [log] [blame]
Chris Lattner48486892003-09-30 18:37:50 +00001//===-- HashExtras.h - Useful functions for STL hash containers -*- C++ -*-===//
Chris Lattner57dbb3a2001-07-23 17:46:59 +00002//
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
Brian Gaekea9f6e4a2003-06-17 00:35:55 +000010#ifndef SUPPORT_HASHEXTRAS_H
11#define SUPPORT_HASHEXTRAS_H
Chris Lattner57dbb3a2001-07-23 17:46:59 +000012
Chris Lattner4a63b722002-10-28 02:11:53 +000013#include "Support/hash_map"
Misha Brukman53523e52003-08-15 17:52:02 +000014#include <string>
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