source: webkit/trunk/JavaScriptCore/wtf/HashMap.h@ 14256

Last change on this file since 14256 was 14256, checked in by mjs, 19 years ago

JavaScriptCore:

Rubber stamped by Anders.


  • renamed kxmlcore to wtf


kxmlcore --> wtf
KXMLCore --> WTF
WKC --> WTF

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bindings/c/c_instance.cpp:
  • bindings/objc/WebScriptObject.mm:
  • kjs/JSImmediate.h:
  • kjs/Parser.cpp:
  • kjs/Parser.h:
  • kjs/array_object.cpp:
  • kjs/collector.cpp: (KJS::Collector::registerThread):
  • kjs/collector.h:
  • kjs/config.h:
  • kjs/function.cpp: (KJS::isStrWhiteSpace):
  • kjs/function.h:
  • kjs/identifier.cpp:
  • kjs/internal.cpp:
  • kjs/internal.h:
  • kjs/lexer.cpp: (Lexer::shift): (Lexer::isWhiteSpace): (Lexer::isIdentStart): (Lexer::isIdentPart):
  • kjs/lookup.cpp:
  • kjs/nodes.cpp:
  • kjs/nodes.h:
  • kjs/number_object.cpp:
  • kjs/object.h:
  • kjs/property_map.cpp:
  • kjs/property_map.h:
  • kjs/string_object.cpp: (StringProtoFunc::callAsFunction):
  • kjs/testkjs.cpp: (testIsInteger):
  • kjs/ustring.cpp:
  • kjs/ustring.h:
  • kxmlcore: Removed.
  • kxmlcore/AlwaysInline.h: Removed.
  • kxmlcore/Assertions.cpp: Removed.
  • kxmlcore/Assertions.h: Removed.
  • kxmlcore/FastMalloc.cpp: Removed.
  • kxmlcore/FastMalloc.h: Removed.
  • kxmlcore/FastMallocInternal.h: Removed.
  • kxmlcore/Forward.h: Removed.
  • kxmlcore/HashCountedSet.h: Removed.
  • kxmlcore/HashFunctions.h: Removed.
  • kxmlcore/HashMap.h: Removed.
  • kxmlcore/HashSet.h: Removed.
  • kxmlcore/HashTable.cpp: Removed.
  • kxmlcore/HashTable.h: Removed.
  • kxmlcore/HashTraits.h: Removed.
  • kxmlcore/ListRefPtr.h: Removed.
  • kxmlcore/Noncopyable.h: Removed.
  • kxmlcore/OwnArrayPtr.h: Removed.
  • kxmlcore/OwnPtr.h: Removed.
  • kxmlcore/PassRefPtr.h: Removed.
  • kxmlcore/Platform.h: Removed.
  • kxmlcore/RefPtr.h: Removed.
  • kxmlcore/TCPageMap.h: Removed.
  • kxmlcore/TCSpinLock.h: Removed.
  • kxmlcore/TCSystemAlloc.cpp: Removed.
  • kxmlcore/TCSystemAlloc.h: Removed.
  • kxmlcore/UnusedParam.h: Removed.
  • kxmlcore/Vector.h: Removed.
  • kxmlcore/VectorTraits.h: Removed.
  • kxmlcore/unicode: Removed.
  • kxmlcore/unicode/Unicode.h: Removed.
  • kxmlcore/unicode/UnicodeCategory.h: Removed.
  • kxmlcore/unicode/icu: Removed.
  • kxmlcore/unicode/icu/UnicodeIcu.h: Removed.
  • kxmlcore/unicode/posix: Removed.
  • kxmlcore/unicode/qt3: Removed.
  • kxmlcore/unicode/qt4: Removed.
  • kxmlcore/unicode/qt4/UnicodeQt4.h: Removed.
  • pcre/pcre_get.c:
  • wtf: Added.
  • wtf/Assertions.cpp:
  • wtf/Assertions.h:
  • wtf/FastMalloc.cpp: (WTF::TCMalloc_ThreadCache::Scavenge): (WTF::do_malloc): (WTF::do_free): (WTF::TCMallocGuard::TCMallocGuard): (WTF::malloc): (WTF::free): (WTF::calloc): (WTF::cfree): (WTF::realloc):
  • wtf/FastMalloc.h:
  • wtf/FastMallocInternal.h:
  • wtf/Forward.h:
  • wtf/HashCountedSet.h:
  • wtf/HashFunctions.h:
  • wtf/HashMap.h:
  • wtf/HashSet.h:
  • wtf/HashTable.cpp:
  • wtf/HashTable.h:
  • wtf/HashTraits.h:
  • wtf/ListRefPtr.h:
  • wtf/Noncopyable.h:
  • wtf/OwnArrayPtr.h:
  • wtf/OwnPtr.h:
  • wtf/PassRefPtr.h:
  • wtf/RefPtr.h:
  • wtf/TCSystemAlloc.cpp: (TCMalloc_SystemAlloc):
  • wtf/Vector.h:
  • wtf/VectorTraits.h:
  • wtf/unicode/UnicodeCategory.h:
  • wtf/unicode/icu/UnicodeIcu.h:

JavaScriptGlue:

Rubber stamped by Anders.


  • renamed kxmlcore to wtf


kxmlcore --> wtf
KXMLCore --> WTF
WKC --> WTF

  • config.h:
  • kxmlcore: Removed.
  • kxmlcore/AlwaysInline.h: Removed.
  • kxmlcore/Assertions.h: Removed.
  • kxmlcore/FastMalloc.h: Removed.
  • kxmlcore/Forward.h: Removed.
  • kxmlcore/HashCountedSet.h: Removed.
  • kxmlcore/HashSet.h: Removed.
  • kxmlcore/Noncopyable.h: Removed.
  • kxmlcore/OwnArrayPtr.h: Removed.
  • kxmlcore/OwnPtr.h: Removed.
  • kxmlcore/PassRefPtr.h: Removed.
  • kxmlcore/Platform.h: Removed.
  • kxmlcore/RefPtr.h: Removed.
  • kxmlcore/Vector.h: Removed.
  • wtf: Added.

WebCore:

Rubber stamped by Anders.


  • renamed kxmlcore to wtf


kxmlcore --> wtf
KXMLCore --> WTF
WKC --> WTF

  • ForwardingHeaders/kxmlcore: Removed.
  • ForwardingHeaders/kxmlcore/AlwaysInline.h: Removed.
  • ForwardingHeaders/kxmlcore/Assertions.h: Removed.
  • ForwardingHeaders/kxmlcore/FastMalloc.h: Removed.
  • ForwardingHeaders/kxmlcore/Forward.h: Removed.
  • ForwardingHeaders/kxmlcore/HashCountedSet.h: Removed.
  • ForwardingHeaders/kxmlcore/HashMap.h: Removed.
  • ForwardingHeaders/kxmlcore/HashSet.h: Removed.
  • ForwardingHeaders/kxmlcore/HashTraits.h: Removed.
  • ForwardingHeaders/kxmlcore/Noncopyable.h: Removed.
  • ForwardingHeaders/kxmlcore/OwnArrayPtr.h: Removed.
  • ForwardingHeaders/kxmlcore/OwnPtr.h: Removed.
  • ForwardingHeaders/kxmlcore/PassRefPtr.h: Removed.
  • ForwardingHeaders/kxmlcore/Platform.h: Removed.
  • ForwardingHeaders/kxmlcore/RefPtr.h: Removed.
  • ForwardingHeaders/kxmlcore/Vector.h: Removed.
  • ForwardingHeaders/wtf: Added.
  • bindings/js/JSHTMLElementWrapperFactory.h:
  • bindings/js/kjs_binding.cpp:
  • bindings/js/kjs_window.h:
  • bindings/objc/DOMImplementationFront.h:
  • bridge/JavaAppletWidget.h:
  • bridge/mac/WebCoreFrameNamespaces.mm:
  • bridge/mac/WebCorePageBridge.mm: (initializeLogChannel):
  • bridge/mac/WebCoreStringTruncator.mm:
  • bridge/mac/WebCoreViewFactory.m:
  • config.h:
  • css/css_base.h:
  • css/css_valueimpl.h:
  • css/csshelper.cpp:
  • css/cssparser.h:
  • dom/DOMImplementation.h:
  • dom/Document.h:
  • dom/NamedNodeMap.h:
  • dom/Node.h:
  • dom/NodeList.h:
  • dom/QualifiedName.cpp:
  • dom/Range.h:
  • dom/StyledElement.cpp:
  • dom/dom2_traversalimpl.h:
  • dom/xml_tokenizer.h:
  • editing/RebalanceWhitespaceCommand.cpp:
  • editing/RemoveCSSPropertyCommand.cpp:
  • editing/RemoveNodeAttributeCommand.cpp:
  • editing/RemoveNodeCommand.cpp:
  • editing/RemoveNodePreservingChildrenCommand.cpp:
  • editing/ReplaceSelectionCommand.h:
  • editing/Selection.cpp:
  • editing/SetNodeAttributeCommand.cpp:
  • editing/SplitElementCommand.cpp:
  • editing/SplitTextNodeCommand.cpp:
  • editing/SplitTextNodeContainingElementCommand.cpp:
  • editing/TextIterator.h:
  • editing/htmlediting.h:
  • editing/markup.h:
  • html/CanvasGradient.h:
  • html/CanvasRenderingContext2D.h:
  • html/CanvasStyle.cpp:
  • html/HTMLCollection.h:
  • html/HTMLElementFactory.h:
  • kcanvas/KCanvasFilters.cpp:
  • kcanvas/KCanvasPath.h:
  • kcanvas/RenderPath.cpp:
  • kcanvas/RenderSVGImage.cpp:
  • kcanvas/RenderSVGText.cpp:
  • kcanvas/device/quartz/KCanvasItemQuartz.mm:
  • kcanvas/device/quartz/KRenderingPaintServerGradientQuartz.mm:
  • kcanvas/device/quartz/QuartzSupport.mm:
  • ksvg2/misc/KSVGTimeScheduler.h:
  • ksvg2/misc/SVGDocumentExtensions.h:
  • ksvg2/scripts/make_names.pl:
  • ksvg2/svg/SVGDOMImplementation.cpp:
  • ksvg2/svg/SVGExternalResourcesRequired.h:
  • ksvg2/svg/SVGFilterPrimitiveStandardAttributes.cpp:
  • ksvg2/svg/SVGForeignObjectElement.cpp:
  • ksvg2/svg/SVGImageElement.cpp:
  • ksvg2/svg/SVGMaskElement.cpp:
  • ksvg2/svg/SVGStyledElement.cpp:
  • ksvg2/svg/SVGTests.h:
  • ksvg2/svg/SVGTransform.h:
  • ksvg2/svg/SVGTransformable.cpp:
  • kwq/AccessibilityObjectCache.h:
  • kwq/KWQCString.cpp:
  • kwq/KWQFormData.mm:
  • kwq/KWQListBox.mm:
  • kwq/KWQResourceLoader.mm:
  • kwq/KWQTextEdit.mm:
  • loader/Cache.h:
  • loader/CachedObject.h:
  • loader/CachedObjectClientWalker.h:
  • loader/Decoder.h:
  • loader/DocLoader.h:
  • loader/loader.cpp:
  • loader/loader.h:
  • page/DOMWindow.h:
  • page/Frame.h:
  • page/FramePrivate.h:
  • page/FrameTree.cpp:
  • page/Page.cpp:
  • page/Page.h:
  • page/Plugin.h:
  • platform/Arena.cpp:
  • platform/ArrayImpl.h:
  • platform/AtomicString.cpp:
  • platform/CharsetNames.cpp:
  • platform/Color.cpp:
  • platform/DeprecatedPtrListImpl.cpp:
  • platform/DeprecatedValueListImpl.h:
  • platform/FontFallbackList.h:
  • platform/GraphicsContext.h:
  • platform/GraphicsTypes.cpp:
  • platform/Image.h:
  • platform/KURL.cpp:
  • platform/Logging.cpp:
  • platform/Logging.h:
  • platform/PlatformString.h:
  • platform/PlugInInfoStore.h:
  • platform/StreamingTextDecoder.cpp:
  • platform/StreamingTextDecoder.h:
  • platform/String.cpp:
  • platform/StringHash.h:
  • platform/StringImpl.cpp:
  • platform/StringImpl.h:
  • platform/TextEncoding.cpp:
  • platform/Timer.cpp:
  • platform/Timer.h:
  • platform/TransferJob.h:
  • platform/TransferJobInternal.h:
  • platform/mac/BlockExceptions.mm:
  • platform/mac/ColorMac.mm:
  • platform/mac/FontData.mm:
  • platform/mac/KURLMac.mm:
  • platform/mac/QStringMac.mm:
  • platform/mac/SharedTimerMac.cpp:
  • platform/mac/TextEncodingMac.cpp:
  • platform/mac/WebCoreImageRendererFactory.m:
  • platform/mac/WebCoreKeyGenerator.m:
  • platform/mac/WebCoreTextArea.mm:
  • platform/mac/WebCoreTextField.mm:
  • platform/mac/WebTextRendererFactory.h:
  • platform/mac/WebTextRendererFactory.mm:
  • platform/win/TemporaryLinkStubs.cpp: (JavaAppletWidget::JavaAppletWidget):
  • rendering/InlineTextBox.cpp:
  • rendering/RenderText.cpp:
  • rendering/RenderTreeAsText.cpp:
  • rendering/bidi.cpp:
  • xml/XSLTProcessor.h:
  • xpath/impl/XPathExpressionNode.h:
  • xpath/impl/XPathParser.h:
  • xpath/impl/XPathPath.h:
  • xpath/impl/XPathUtil.h:

WebKit:

Rubber stamped by Anders.


  • renamed kxmlcore to wtf


kxmlcore --> wtf
KXMLCore --> WTF
WKC --> WTF

  • Misc/WebKitLogging.h:
  • Misc/WebKitLogging.m: (initializeLogChannel):
  • Property svn:eol-style set to native
File size: 12.3 KB
Line 
1// -*- mode: c++; c-basic-offset: 4 -*-
2/*
3 * This file is part of the KDE libraries
4 *
5 * Copyright (C) 2005, 2006 Apple Computer, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#ifndef KXMLCORE_HASH_MAP_H
25#define KXMLCORE_HASH_MAP_H
26
27#include "HashTable.h"
28
29namespace WTF {
30
31 template<typename PairType> struct PairFirstExtractor;
32
33 template<typename KeyArg, typename MappedArg, typename HashArg = typename DefaultHash<KeyArg>::Hash,
34 typename KeyTraitsArg = HashTraits<KeyArg>, typename MappedTraitsArg = HashTraits<MappedArg> >
35 class HashMap {
36 private:
37 typedef KeyTraitsArg KeyTraits;
38 typedef MappedTraitsArg MappedTraits;
39 typedef PairBaseHashTraits<KeyTraits, MappedTraits> ValueTraits;
40
41 public:
42 typedef typename KeyTraits::TraitType KeyType;
43 typedef typename MappedTraits::TraitType MappedType;
44 typedef typename ValueTraits::TraitType ValueType;
45
46 private:
47 typedef HashArg HashFunctions;
48
49 typedef typename HashKeyStorageTraits<HashFunctions, KeyTraits>::Hash StorageHashFunctions;
50
51 typedef typename HashKeyStorageTraits<HashFunctions, KeyTraits>::Traits KeyStorageTraits;
52 typedef typename MappedTraits::StorageTraits MappedStorageTraits;
53 typedef PairHashTraits<KeyStorageTraits, MappedStorageTraits> ValueStorageTraits;
54
55 typedef typename KeyStorageTraits::TraitType KeyStorageType;
56 typedef typename MappedStorageTraits::TraitType MappedStorageType;
57 typedef typename ValueStorageTraits::TraitType ValueStorageType;
58
59 typedef HashTable<KeyStorageType, ValueStorageType, PairFirstExtractor<ValueStorageType>,
60 StorageHashFunctions, ValueStorageTraits, KeyStorageTraits> HashTableType;
61
62 public:
63 typedef HashTableIteratorAdapter<HashTableType, ValueType> iterator;
64 typedef HashTableConstIteratorAdapter<HashTableType, ValueType> const_iterator;
65
66 HashMap();
67 HashMap(const HashMap&);
68 HashMap& operator=(const HashMap&);
69 ~HashMap();
70
71 int size() const;
72 int capacity() const;
73 bool isEmpty() const;
74
75 // iterators iterate over pairs of keys and values
76 iterator begin();
77 iterator end();
78 const_iterator begin() const;
79 const_iterator end() const;
80
81 iterator find(const KeyType&);
82 const_iterator find(const KeyType&) const;
83 bool contains(const KeyType&) const;
84 MappedType get(const KeyType&) const;
85
86 // replaces value but not key if key is already present
87 // return value is a pair of the iterator to the key location,
88 // and a boolean that's true if a new value was actually added
89 pair<iterator, bool> set(const KeyType&, const MappedType&);
90
91 // does nothing if key is already present
92 // return value is a pair of the iterator to the key location,
93 // and a boolean that's true if a new value was actually added
94 pair<iterator, bool> add(const KeyType&, const MappedType&);
95
96 void remove(const KeyType&);
97 void remove(iterator it);
98 void clear();
99
100 private:
101 pair<iterator, bool> inlineAdd(const KeyType&, const MappedType&);
102 void refAll();
103 void derefAll();
104
105 HashTableType m_impl;
106 };
107
108 template<typename PairType> struct PairFirstExtractor {
109 static const typename PairType::first_type& extract(const PairType& p) { return p.first; }
110 };
111
112 template<bool canReplaceDeletedKey, typename ValueType, typename ValueStorageTraits, typename HashFunctions>
113 struct HashMapTranslator;
114
115 template<typename ValueType, typename ValueStorageTraits, typename HashFunctions>
116 struct HashMapTranslator<true, ValueType, ValueStorageTraits, HashFunctions> {
117 typedef typename ValueType::first_type KeyType;
118 typedef typename ValueType::second_type MappedType;
119 typedef typename ValueStorageTraits::TraitType ValueStorageType;
120 typedef typename ValueStorageTraits::FirstTraits KeyStorageTraits;
121 typedef typename KeyStorageTraits::TraitType KeyStorageType;
122
123 static unsigned hash(const KeyType& key) { return HashFunctions::hash(key); }
124 static bool equal(const KeyStorageType& a, const KeyType& b) { return HashFunctions::equal(*(KeyType*)&a, b); }
125 static void translate(ValueStorageType& location, const KeyType& key, const MappedType& mapped, unsigned)
126 {
127 *(KeyType*)&location.first = key;
128 *(MappedType*)&location.second = mapped;
129 }
130 };
131
132 template<typename ValueType, typename ValueStorageTraits, typename HashFunctions>
133 struct HashMapTranslator<false, ValueType, ValueStorageTraits, HashFunctions> {
134 typedef typename ValueType::first_type KeyType;
135 typedef typename ValueType::second_type MappedType;
136 typedef typename ValueStorageTraits::TraitType ValueStorageType;
137 typedef typename ValueStorageTraits::FirstTraits KeyStorageTraits;
138 typedef typename KeyStorageTraits::TraitType KeyStorageType;
139
140 static unsigned hash(const KeyType& key) { return HashFunctions::hash(key); }
141 static bool equal(const KeyStorageType& a, const KeyType& b) { return HashFunctions::equal(*(KeyType*)&a, b); }
142 static void translate(ValueStorageType& location, const KeyType& key, const MappedType& mapped, unsigned)
143 {
144 if (location.first == KeyStorageTraits::deletedValue())
145 location.first = KeyStorageTraits::emptyValue();
146 *(KeyType*)&location.first = key;
147 *(MappedType*)&location.second = mapped;
148 }
149 };
150
151 template<typename T, typename U, typename V, typename W, typename X>
152 inline void HashMap<T, U, V, W, X>::refAll()
153 {
154 HashTableRefCounter<HashTableType, ValueTraits>::refAll(m_impl);
155 }
156
157 template<typename T, typename U, typename V, typename W, typename X>
158 inline void HashMap<T, U, V, W, X>::derefAll()
159 {
160 HashTableRefCounter<HashTableType, ValueTraits>::derefAll(m_impl);
161 }
162
163 template<typename T, typename U, typename V, typename W, typename X>
164 inline HashMap<T, U, V, W, X>::HashMap()
165 {
166 }
167
168 template<typename T, typename U, typename V, typename W, typename X>
169 inline HashMap<T, U, V, W, X>::HashMap(const HashMap& other)
170 : m_impl(other.m_impl)
171 {
172 refAll();
173 }
174
175 template<typename T, typename U, typename V, typename W, typename X>
176 inline HashMap<T, U, V, W, X>& HashMap<T, U, V, W, X>::operator=(const HashMap& other)
177 {
178 HashMap tmp(other);
179 m_impl.swap(tmp.m_impl);
180 return *this;
181 }
182
183 template<typename T, typename U, typename V, typename W, typename X>
184 inline HashMap<T, U, V, W, X>::~HashMap()
185 {
186 derefAll();
187 }
188
189 template<typename T, typename U, typename V, typename W, typename X>
190 inline int HashMap<T, U, V, W, X>::size() const
191 {
192 return m_impl.size();
193 }
194
195 template<typename T, typename U, typename V, typename W, typename X>
196 inline int HashMap<T, U, V, W, X>::capacity() const
197 {
198 return m_impl.capacity();
199 }
200
201 template<typename T, typename U, typename V, typename W, typename X>
202 inline bool HashMap<T, U, V, W, X>::isEmpty() const
203 {
204 return m_impl.isEmpty();
205 }
206
207 template<typename T, typename U, typename V, typename W, typename X>
208 inline typename HashMap<T, U, V, W, X>::iterator HashMap<T, U, V, W, X>::begin()
209 {
210 return m_impl.begin();
211 }
212
213 template<typename T, typename U, typename V, typename W, typename X>
214 inline typename HashMap<T, U, V, W, X>::iterator HashMap<T, U, V, W, X>::end()
215 {
216 return m_impl.end();
217 }
218
219 template<typename T, typename U, typename V, typename W, typename X>
220 inline typename HashMap<T, U, V, W, X>::const_iterator HashMap<T, U, V, W, X>::begin() const
221 {
222 return m_impl.begin();
223 }
224
225 template<typename T, typename U, typename V, typename W, typename X>
226 inline typename HashMap<T, U, V, W, X>::const_iterator HashMap<T, U, V, W, X>::end() const
227 {
228 return m_impl.end();
229 }
230
231 template<typename T, typename U, typename V, typename W, typename X>
232 inline typename HashMap<T, U, V, W, X>::iterator HashMap<T, U, V, W, X>::find(const KeyType& key)
233 {
234 return m_impl.find(*(const KeyStorageType*)&key);
235 }
236
237 template<typename T, typename U, typename V, typename W, typename X>
238 inline typename HashMap<T, U, V, W, X>::const_iterator HashMap<T, U, V, W, X>::find(const KeyType& key) const
239 {
240 return m_impl.find(*(const KeyStorageType*)&key);
241 }
242
243 template<typename T, typename U, typename V, typename W, typename X>
244 inline bool HashMap<T, U, V, W, X>::contains(const KeyType& key) const
245 {
246 return m_impl.contains(*(const KeyStorageType*)&key);
247 }
248
249 template<typename T, typename U, typename V, typename W, typename X>
250 inline pair<typename HashMap<T, U, V, W, X>::iterator, bool>
251 HashMap<T, U, V, W, X>::inlineAdd(const KeyType& key, const MappedType& mapped)
252 {
253 const bool canReplaceDeletedKey = !KeyTraits::needsDestruction || KeyStorageTraits::needsDestruction;
254 typedef HashMapTranslator<canReplaceDeletedKey, ValueType, ValueStorageTraits, HashFunctions> TranslatorType;
255 return m_impl.template add<KeyType, MappedType, TranslatorType>(key, mapped);
256 }
257
258 template<typename T, typename U, typename V, typename W, typename X>
259 pair<typename HashMap<T, U, V, W, X>::iterator, bool>
260 HashMap<T, U, V, W, X>::set(const KeyType& key, const MappedType& mapped)
261 {
262 pair<iterator, bool> result = inlineAdd(key, mapped);
263 if (!result.second)
264 // add call above didn't change anything, so set the mapped value
265 result.first->second = mapped;
266 return result;
267 }
268
269 template<typename T, typename U, typename V, typename W, typename X>
270 pair<typename HashMap<T, U, V, W, X>::iterator, bool>
271 HashMap<T, U, V, W, X>::add(const KeyType& key, const MappedType& mapped)
272 {
273 return inlineAdd(key, mapped);
274 }
275
276 template<typename T, typename U, typename V, typename W, typename MappedTraits>
277 inline typename HashMap<T, U, V, W, MappedTraits>::MappedType
278 HashMap<T, U, V, W, MappedTraits>::get(const KeyType& key) const
279 {
280 const_iterator it = find(key);
281 if (it == end())
282 return MappedTraits::emptyValue();
283 return it->second;
284 }
285
286 template<typename T, typename U, typename V, typename W, typename X>
287 inline void HashMap<T, U, V, W, X>::remove(iterator it)
288 {
289 if (it.m_impl == m_impl.end())
290 return;
291 RefCounter<ValueTraits, ValueStorageTraits>::deref(*it.m_impl);
292 m_impl.remove(it.m_impl);
293 }
294
295 template<typename T, typename U, typename V, typename W, typename X>
296 inline void HashMap<T, U, V, W, X>::remove(const KeyType& key)
297 {
298 remove(find(key));
299 }
300
301 template<typename T, typename U, typename V, typename W, typename X>
302 inline void HashMap<T, U, V, W, X>::clear()
303 {
304 derefAll();
305 m_impl.clear();
306 }
307
308 template<typename MappedType, typename HashTableType>
309 void deleteAllPairSeconds(HashTableType& collection)
310 {
311 typedef typename HashTableType::iterator iterator;
312 iterator end = collection.end();
313 for (iterator it = collection.begin(); it != end; ++it)
314 delete *(MappedType*)&it->second;
315 }
316
317 template<typename T, typename U, typename V, typename W, typename X>
318 inline void deleteAllValues(HashMap<T, U, V, W, X>& collection)
319 {
320 deleteAllPairSeconds<typename HashMap<T, U, V, W, X>::MappedType>(collection);
321 }
322
323} // namespace WTF
324
325using WTF::HashMap;
326
327#endif /* KXMLCORE_HASH_MAP_H */
Note: See TracBrowser for help on using the repository browser.