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 | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame^] | 14 | #include <ext/hash_map> |
| 15 | |
| 16 | // Cannot specialize hash template from outside of the std namespace. |
| 17 | namespace std { |
Chris Lattner | 57dbb3a | 2001-07-23 17:46:59 +0000 | [diff] [blame] | 18 | |
| 19 | template <> struct hash<string> { |
| 20 | size_t operator()(string const &str) const { |
| 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 |