Chris Lattner | 57dbb3a | 2001-07-23 17:46:59 +0000 | [diff] [blame] | 1 | //===-- 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 Lattner | 4a63b72 | 2002-10-28 02:11:53 +0000 | [diff] [blame^] | 14 | #include "Support/hash_map" |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 15 | |
| 16 | // Cannot specialize hash template from outside of the std namespace. |
Chris Lattner | 8dc6716 | 2002-07-24 22:20:00 +0000 | [diff] [blame] | 17 | namespace HASH_NAMESPACE { |
Chris Lattner | 57dbb3a | 2001-07-23 17:46:59 +0000 | [diff] [blame] | 18 | |
Chris Lattner | 8dc6716 | 2002-07-24 22:20:00 +0000 | [diff] [blame] | 19 | template <> struct hash<std::string> { |
| 20 | size_t operator()(std::string const &str) const { |
Chris Lattner | 57dbb3a | 2001-07-23 17:46:59 +0000 | [diff] [blame] | 21 | return hash<char const *>()(str.c_str()); |
| 22 | } |
| 23 | }; |
| 24 | |
Vikram S. Adve | bf2b7e8 | 2001-07-28 04:41:10 +0000 | [diff] [blame] | 25 | // Provide a hash function for arbitrary pointers... |
| 26 | template <class T> struct hash<T *> { |
| 27 | inline size_t operator()(const T *Val) const { return (size_t)Val; } |
| 28 | }; |
| 29 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 30 | } // End namespace std |
| 31 | |
Chris Lattner | 57dbb3a | 2001-07-23 17:46:59 +0000 | [diff] [blame] | 32 | #endif |