source: webkit/trunk/JavaScriptCore/wtf/HashFunctions.h@ 21064

Last change on this file since 21064 was 17372, checked in by darin, 19 years ago

Reviewed by Geoff.

  • made changes so the code compiles with the highest warning level under MSVC (disabling some warnings, making some code fixes)
  • API/JSCallbackConstructor.cpp: (KJS::JSCallbackConstructor::construct):
  • API/JSCallbackFunction.cpp: (KJS::JSCallbackFunction::callAsFunction):
  • API/JSCallbackObject.cpp: (KJS::JSCallbackObject::init): (KJS::JSCallbackObject::construct): (KJS::JSCallbackObject::callAsFunction):
  • API/JSObjectRef.cpp: (JSPropertyNameArrayGetNameAtIndex):
  • API/JSStringRef.cpp: (JSStringCreateWithCharacters):
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • bindings/c/c_utility.cpp: (KJS::Bindings::convertUTF8ToUTF16): (KJS::Bindings::coerceValueToNPVariantStringType): (KJS::Bindings::convertValueToNPVariant):
  • kjs/DateMath.h: (KJS::GregorianDateTime::GregorianDateTime):
  • kjs/ExecState.h: (KJS::ExecState::hadException):
  • kjs/JSImmediate.h: (KJS::JSImmediate::fromDouble): (KJS::JSImmediate::toDouble): (KJS::JSImmediate::NanAsBits): (KJS::JSImmediate::oneAsBits):
  • kjs/Parser.h:
  • kjs/PropertyNameArray.h: (KJS::PropertyNameArray::size):
  • kjs/array_object.cpp: (ArrayObjectImp::callAsFunction):
  • kjs/bool_object.cpp: (BooleanObjectImp::callAsFunction):
  • kjs/collector.cpp: (KJS::Collector::allocate): (KJS::Collector::markCurrentThreadConservatively): (KJS::Collector::collect):
  • kjs/completion.h: (KJS::Completion::isValueCompletion):
  • kjs/date_object.cpp: (KJS::findMonth):
  • kjs/debugger.cpp: (Debugger::sourceParsed): (Debugger::sourceUnused): (Debugger::exception): (Debugger::atStatement): (Debugger::callEvent): (Debugger::returnEvent):
  • kjs/dtoa.cpp:
  • kjs/error_object.cpp: (ErrorObjectImp::callAsFunction): (NativeErrorImp::callAsFunction):
  • kjs/function.cpp: (KJS::FunctionImp::processVarDecls): (KJS::GlobalFuncImp::callAsFunction):
  • kjs/function_object.cpp: (FunctionPrototype::callAsFunction):
  • kjs/grammar.y:
  • kjs/identifier.cpp: (KJS::CStringTranslator::translate): (KJS::Identifier::add):
  • kjs/internal.h:
  • kjs/lexer.cpp: (Lexer::lex): (Lexer::isIdentStart): (Lexer::isIdentPart): (isDecimalDigit): (Lexer::isHexDigit): (Lexer::isOctalDigit): (Lexer::matchPunctuator): (Lexer::singleEscape): (Lexer::convertOctal): (Lexer::convertHex): (Lexer::convertUnicode): (Lexer::record8):
  • kjs/lexer.h:
  • kjs/math_object.cpp: (MathFuncImp::callAsFunction):
  • kjs/number_object.cpp: (integer_part_noexp): (intPow10): (NumberProtoFunc::callAsFunction): (NumberObjectImp::callAsFunction):
  • kjs/object.cpp: (KJS::JSObject::deleteProperty): (KJS::JSObject::callAsFunction): (KJS::JSObject::toBoolean): (KJS::JSObject::toObject):
  • kjs/object.h: (KJS::JSObject::getPropertySlot):
  • kjs/property_map.cpp: (KJS::isValid): (KJS::PropertyMap::put): (KJS::PropertyMap::insert): (KJS::PropertyMap::containsGettersOrSetters):
  • kjs/property_map.h: (KJS::PropertyMap::hasGetterSetterProperties):
  • kjs/property_slot.h:
  • kjs/string_object.cpp: (StringInstance::getPropertyNames): (StringObjectImp::callAsFunction): (StringObjectFuncImp::callAsFunction):
  • kjs/ustring.cpp: (KJS::UString::Rep::computeHash): (KJS::UString::UString): (KJS::UString::from): (KJS::UString::append): (KJS::UString::ascii): (KJS::UString::operator=): (KJS::UString::find): (KJS::UString::rfind):
  • kjs/ustring.h: (KJS::UChar::high): (KJS::UChar::low): (KJS::UCharReference::low): (KJS::UCharReference::high):
  • kjs/value.cpp: (KJS::JSValue::toUInt16):
  • kjs/value.h:
  • pcre/pcre_compile.c: (get_othercase_range):
  • pcre/pcre_exec.c: (match):
  • pcre/pcre_internal.h:
  • wtf/HashFunctions.h: (WTF::intHash): (WTF::PtrHash::hash):
  • wtf/MathExtras.h: (isnan): (lround): (lroundf):
  • wtf/StringExtras.h: (strncasecmp):
  • wtf/unicode/icu/UnicodeIcu.h: (WTF::Unicode::isPrintableChar):
  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1// -*- mode: c++; c-basic-offset: 4 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 2005, 2006 Apple Computer, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef WTF_HashFunctions_h
24#define WTF_HashFunctions_h
25
26#include "RefPtr.h"
27#include <stdint.h>
28
29namespace WTF {
30
31 template<size_t size> struct IntTypes;
32 template<> struct IntTypes<1> { typedef int8_t SignedType; typedef uint8_t UnsignedType; };
33 template<> struct IntTypes<2> { typedef int16_t SignedType; typedef uint16_t UnsignedType; };
34 template<> struct IntTypes<4> { typedef int32_t SignedType; typedef uint32_t UnsignedType; };
35 template<> struct IntTypes<8> { typedef int64_t SignedType; typedef uint64_t UnsignedType; };
36
37 // integer hash function
38
39 // Thomas Wang's 32 Bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm
40 inline unsigned intHash(uint32_t key)
41 {
42 key += ~(key << 15);
43 key ^= (key >> 10);
44 key += (key << 3);
45 key ^= (key >> 6);
46 key += ~(key << 11);
47 key ^= (key >> 16);
48 return key;
49 }
50
51 // Thomas Wang's 64 bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm
52 inline unsigned intHash(uint64_t key)
53 {
54 key += ~(key << 32);
55 key ^= (key >> 22);
56 key += ~(key << 13);
57 key ^= (key >> 8);
58 key += (key << 3);
59 key ^= (key >> 15);
60 key += ~(key << 27);
61 key ^= (key >> 31);
62 return static_cast<unsigned>(key);
63 }
64
65 template<typename T> struct IntHash {
66 static unsigned hash(T key) { return intHash(static_cast<typename IntTypes<sizeof(T)>::UnsignedType>(key)); }
67 static bool equal(T a, T b) { return a == b; }
68 };
69
70 // pointer identity hash function
71
72 template<typename T> struct PtrHash {
73 static unsigned hash(T key)
74 {
75#if COMPILER(MSVC)
76#pragma warning(push)
77#pragma warning(disable: 4244) // work around what seems to be a bug in MSVC's conversion warnings
78#endif
79 return IntHash<uintptr_t>::hash(reinterpret_cast<uintptr_t>(key));
80#if COMPILER(MSVC)
81#pragma warning(pop)
82#endif
83 }
84 static bool equal(T a, T b) { return a == b; }
85 };
86 template<typename P> struct PtrHash<RefPtr<P> > {
87 static unsigned hash(const RefPtr<P>& key) { return PtrHash<P*>::hash(key.get()); }
88 static bool equal(const RefPtr<P>& a, const RefPtr<P>& b) { return a == b; }
89 };
90
91 // default hash function for each type
92
93 template<typename T> struct DefaultHash;
94
95 // make IntHash the default hash function for many integer types
96
97 template<> struct DefaultHash<int> { typedef IntHash<unsigned> Hash; };
98 template<> struct DefaultHash<unsigned> { typedef IntHash<unsigned> Hash; };
99 template<> struct DefaultHash<long> { typedef IntHash<unsigned long> Hash; };
100 template<> struct DefaultHash<unsigned long> { typedef IntHash<unsigned long> Hash; };
101 template<> struct DefaultHash<long long> { typedef IntHash<unsigned long long> Hash; };
102 template<> struct DefaultHash<unsigned long long> { typedef IntHash<unsigned long long> Hash; };
103
104 // make PtrHash the default hash function for pointer types that don't specialize
105
106 template<typename P> struct DefaultHash<P*> { typedef PtrHash<P*> Hash; };
107 template<typename P> struct DefaultHash<RefPtr<P> > { typedef PtrHash<RefPtr<P> > Hash; };
108
109} // namespace WTF
110
111using WTF::DefaultHash;
112using WTF::IntHash;
113using WTF::PtrHash;
114
115#endif // WTF_HashFunctions_h
Note: See TracBrowser for help on using the repository browser.