00001 //===-- basic/HashUtils.h ------------------------------------- -*- C++ -*-===// 00002 // 00003 // This file is distributed under the MIT license. See LICENSE.txt for details. 00004 // 00005 // Copyright (C) 2008, Stephen Wilson 00006 // 00007 //===----------------------------------------------------------------------===// 00008 00009 #ifndef COMMA_BASIC_HASHUTILS_HDR_GUARD 00010 #define COMMA_BASIC_HASHUTILS_HDR_GUARD 00011 00012 #include <cstddef> 00013 #include "llvm/Support/DataTypes.h" 00014 00015 namespace comma { 00016 00017 // The following functions provide hash code generation over a variety of basic 00018 // datatypes. 00019 00020 // Returns a hash for the given null terminated string. 00021 uint32_t hashString(const char *x); 00022 00023 // Returns a hash for the data pointed to be ptr, size bytes in length. 00024 uint32_t hashData(const void *ptr, size_t size); 00025 00026 // When using the standard library unordered_map or unordered_set containers 00027 // with C strings as keys the following structures provide functional objects 00028 // suitable for use as template parameters. 00029 struct StrHash { 00030 size_t operator() (const char *x) const; 00031 }; 00032 00033 struct StrEqual { 00034 bool operator() (const char *x, const char *y) const; 00035 }; 00036 00037 } // End comma namespace 00038 00039 #endif