[llvm-commits] [poolalloc] r68225 - in /poolalloc/trunk/include/poolalloc/ADT: ./ HashExtras.h
John Criswell
criswell at uiuc.edu
Wed Apr 1 11:28:43 PDT 2009
Author: criswell
Date: Wed Apr 1 13:28:43 2009
New Revision: 68225
URL: http://llvm.org/viewvc/llvm-project?rev=68225&view=rev
Log:
Adding a GCC compatible header file which allows us to use hash_map
and hash_set on pointers and strings.
Added:
poolalloc/trunk/include/poolalloc/ADT/
poolalloc/trunk/include/poolalloc/ADT/HashExtras.h
Added: poolalloc/trunk/include/poolalloc/ADT/HashExtras.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc/ADT/HashExtras.h?rev=68225&view=auto
==============================================================================
--- poolalloc/trunk/include/poolalloc/ADT/HashExtras.h (added)
+++ poolalloc/trunk/include/poolalloc/ADT/HashExtras.h Wed Apr 1 13:28:43 2009
@@ -0,0 +1,49 @@
+//===-- poolalloc/ADT/HashExtras.h - STL hashing for LLVM -------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains some templates that are useful if you are working with the
+// STL Hashed containers.
+//
+// No library is required when using these functions.
+//
+// This header files is a modification of HashExtras.h from LLVM. It is GNU
+// C++ specific.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef POOLALLOC_ADT_HASHEXTRAS_H
+#define POOLALLOC_ADT_HASHEXTRAS_H
+
+#include <functional>
+#include <ext/hash_map>
+#include <ext/hash_set>
+#include <string>
+
+// Cannot specialize hash template from outside of the std namespace.
+namespace __gnu_cxx {
+
+// Provide a hash function for arbitrary pointers...
+template <class T> struct hash<T *> {
+ inline size_t operator()(const T *Val) const {
+ return reinterpret_cast<size_t>(Val);
+ }
+};
+
+template <> struct hash<std::string> {
+ size_t operator()(std::string const &str) const {
+ return hash<char const *>()(str.c_str());
+ }
+};
+
+} // End namespace std
+
+// Use the namespace so that we don't need to state it explictly.
+using namespace __gnu_cxx;
+
+#endif
More information about the llvm-commits
mailing list