blob: 67f65b5f3ac061a70172baa2f787d272dea10ade [file] [log] [blame]
Chris Lattner48486892003-09-30 18:37:50 +00001//===-- HashExtras.h - Useful functions for STL hash containers -*- C++ -*-===//
John Criswellb2109ce2003-10-20 19:46:57 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Chris Lattner57dbb3a2001-07-23 17:46:59 +00009//
10// This file contains some templates that are useful if you are working with the
11// STL Hashed containers.
12//
13// No library is required when using these functinons.
14//
15//===----------------------------------------------------------------------===//
16
Brian Gaekea9f6e4a2003-06-17 00:35:55 +000017#ifndef SUPPORT_HASHEXTRAS_H
18#define SUPPORT_HASHEXTRAS_H
Chris Lattner57dbb3a2001-07-23 17:46:59 +000019
Chris Lattner4a63b722002-10-28 02:11:53 +000020#include "Support/hash_map"
Misha Brukman53523e52003-08-15 17:52:02 +000021#include <string>
Chris Lattner697954c2002-01-20 22:54:45 +000022
23// Cannot specialize hash template from outside of the std namespace.
Chris Lattner8dc67162002-07-24 22:20:00 +000024namespace HASH_NAMESPACE {
Chris Lattner57dbb3a2001-07-23 17:46:59 +000025
Chris Lattner8dc67162002-07-24 22:20:00 +000026template <> struct hash<std::string> {
27 size_t operator()(std::string const &str) const {
Chris Lattner57dbb3a2001-07-23 17:46:59 +000028 return hash<char const *>()(str.c_str());
29 }
30};
31
Vikram S. Advebf2b7e82001-07-28 04:41:10 +000032// Provide a hash function for arbitrary pointers...
33template <class T> struct hash<T *> {
Chris Lattner8b70b782003-11-16 20:21:15 +000034 inline size_t operator()(const T *Val) const {
35 return reinterpret_cast<size_t>(Val);
36 }
Vikram S. Advebf2b7e82001-07-28 04:41:10 +000037};
38
Chris Lattner697954c2002-01-20 22:54:45 +000039} // End namespace std
40
Chris Lattner57dbb3a2001-07-23 17:46:59 +000041#endif