Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: Source/wtf/HashMap.h

Issue 1129373003: New return value syntax for HashTable and HashMap nested types Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/wtf/HashTable.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 return m_impl.capacity(); 280 return m_impl.capacity();
281 } 281 }
282 282
283 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 283 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
284 inline bool HashMap<T, U, V, W, X, Y>::isEmpty() const 284 inline bool HashMap<T, U, V, W, X, Y>::isEmpty() const
285 { 285 {
286 return m_impl.isEmpty(); 286 return m_impl.isEmpty();
287 } 287 }
288 288
289 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 289 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
290 inline typename HashMap<T, U, V, W, X, Y>::iterator HashMap<T, U, V, W, X, Y >::begin() 290 inline auto HashMap<T, U, V, W, X, Y>::begin() -> iterator
291 { 291 {
292 return m_impl.begin(); 292 return m_impl.begin();
293 } 293 }
294 294
295 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 295 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
296 inline typename HashMap<T, U, V, W, X, Y>::iterator HashMap<T, U, V, W, X, Y >::end() 296 inline auto HashMap<T, U, V, W, X, Y>::end() -> iterator
297 { 297 {
298 return m_impl.end(); 298 return m_impl.end();
299 } 299 }
300 300
301 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 301 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
302 inline typename HashMap<T, U, V, W, X, Y>::const_iterator HashMap<T, U, V, W , X, Y>::begin() const 302 inline auto HashMap<T, U, V, W, X, Y>::begin() const -> const_iterator
303 { 303 {
304 return m_impl.begin(); 304 return m_impl.begin();
305 } 305 }
306 306
307 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 307 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
308 inline typename HashMap<T, U, V, W, X, Y>::const_iterator HashMap<T, U, V, W , X, Y>::end() const 308 inline auto HashMap<T, U, V, W, X, Y>::end() const -> const_iterator
309 { 309 {
310 return m_impl.end(); 310 return m_impl.end();
311 } 311 }
312 312
313 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 313 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
314 inline typename HashMap<T, U, V, W, X, Y>::iterator HashMap<T, U, V, W, X, Y >::find(KeyPeekInType key) 314 inline auto HashMap<T, U, V, W, X, Y>::find(KeyPeekInType key) -> iterator
315 { 315 {
316 return m_impl.find(key); 316 return m_impl.find(key);
317 } 317 }
318 318
319 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 319 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
320 inline typename HashMap<T, U, V, W, X, Y>::const_iterator HashMap<T, U, V, W , X, Y>::find(KeyPeekInType key) const 320 auto HashMap<T, U, V, W, X, Y>::find(KeyPeekInType key) const -> const_itera tor
321 { 321 {
322 return m_impl.find(key); 322 return m_impl.find(key);
323 } 323 }
324 324
325 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 325 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
326 inline bool HashMap<T, U, V, W, X, Y>::contains(KeyPeekInType key) const 326 inline bool HashMap<T, U, V, W, X, Y>::contains(KeyPeekInType key) const
327 { 327 {
328 return m_impl.contains(key); 328 return m_impl.contains(key);
329 } 329 }
330 330
331 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 331 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
332 template<typename HashTranslator, typename TYPE> 332 template<typename HashTranslator, typename TYPE>
333 inline typename HashMap<T, U, V, W, X, Y>::iterator 333 auto HashMap<T, U, V, W, X, Y>::find(const TYPE& value) -> iterator
334 HashMap<T, U, V, W, X, Y>::find(const TYPE& value)
335 { 334 {
336 return m_impl.template find<HashMapTranslatorAdapter<ValueTraits, HashTr anslator>>(value); 335 return m_impl.template find<HashMapTranslatorAdapter<ValueTraits, HashTr anslator>>(value);
337 } 336 }
338 337
339 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 338 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
340 template<typename HashTranslator, typename TYPE> 339 template<typename HashTranslator, typename TYPE>
341 inline typename HashMap<T, U, V, W, X, Y>::const_iterator 340 auto HashMap<T, U, V, W, X, Y>::find(const TYPE& value) const -> const_itera tor
342 HashMap<T, U, V, W, X, Y>::find(const TYPE& value) const
343 { 341 {
344 return m_impl.template find<HashMapTranslatorAdapter<ValueTraits, HashTr anslator>>(value); 342 return m_impl.template find<HashMapTranslatorAdapter<ValueTraits, HashTr anslator>>(value);
345 } 343 }
346 344
347 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 345 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
348 template<typename HashTranslator, typename TYPE> 346 template<typename HashTranslator, typename TYPE>
349 inline bool 347 inline bool
350 HashMap<T, U, V, W, X, Y>::contains(const TYPE& value) const 348 HashMap<T, U, V, W, X, Y>::contains(const TYPE& value) const
351 { 349 {
352 return m_impl.template contains<HashMapTranslatorAdapter<ValueTraits, Ha shTranslator>>(value); 350 return m_impl.template contains<HashMapTranslatorAdapter<ValueTraits, Ha shTranslator>>(value);
353 } 351 }
354 352
355 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 353 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
356 typename HashMap<T, U, V, W, X, Y>::AddResult 354 auto HashMap<T, U, V, W, X, Y>::inlineAdd(KeyPeekInType key, MappedPassInRef erenceType mapped) -> AddResult
357 HashMap<T, U, V, W, X, Y>::inlineAdd(KeyPeekInType key, MappedPassInReferenc eType mapped)
358 { 355 {
359 return m_impl.template add<HashMapTranslator<ValueTraits, HashFunctions> >(key, mapped); 356 return m_impl.template add<HashMapTranslator<ValueTraits, HashFunctions> >(key, mapped);
360 } 357 }
361 358
362 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 359 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
363 typename HashMap<T, U, V, W, X, Y>::AddResult 360 auto HashMap<T, U, V, W, X, Y>::set(KeyPeekInType key, MappedPassInType mapp ed) -> AddResult
364 HashMap<T, U, V, W, X, Y>::set(KeyPeekInType key, MappedPassInType mapped)
365 { 361 {
366 AddResult result = inlineAdd(key, mapped); 362 AddResult result = inlineAdd(key, mapped);
367 if (!result.isNewEntry) { 363 if (!result.isNewEntry) {
368 // The inlineAdd call above found an existing hash table entry; we n eed to set the mapped value. 364 // The inlineAdd call above found an existing hash table entry; we n eed to set the mapped value.
369 MappedTraits::store(mapped, result.storedValue->value); 365 MappedTraits::store(mapped, result.storedValue->value);
370 } 366 }
371 return result; 367 return result;
372 } 368 }
373 369
374 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 370 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
375 template<typename HashTranslator, typename TYPE> 371 template<typename HashTranslator, typename TYPE>
376 typename HashMap<T, U, V, W, X, Y>::AddResult 372 auto HashMap<T, U, V, W, X, Y>::add(const TYPE& key, MappedPassInType value) -> AddResult
377 HashMap<T, U, V, W, X, Y>::add(const TYPE& key, MappedPassInType value)
378 { 373 {
379 return m_impl.template addPassingHashCode<HashMapTranslatorAdapter<Value Traits, HashTranslator>>(key, value); 374 return m_impl.template addPassingHashCode<HashMapTranslatorAdapter<Value Traits, HashTranslator>>(key, value);
380 } 375 }
381 376
382 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 377 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
383 typename HashMap<T, U, V, W, X, Y>::AddResult 378 auto HashMap<T, U, V, W, X, Y>::add(KeyPeekInType key, MappedPassInType mapp ed) -> AddResult
384 HashMap<T, U, V, W, X, Y>::add(KeyPeekInType key, MappedPassInType mapped)
385 { 379 {
386 return inlineAdd(key, mapped); 380 return inlineAdd(key, mapped);
387 } 381 }
388 382
389 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 383 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
390 typename HashMap<T, U, V, W, X, Y>::MappedPeekType 384 auto HashMap<T, U, V, W, X, Y>::get(KeyPeekInType key) const -> MappedPeekTy pe
391 HashMap<T, U, V, W, X, Y>::get(KeyPeekInType key) const
392 { 385 {
393 ValueType* entry = const_cast<HashTableType&>(m_impl).lookup(key); 386 ValueType* entry = const_cast<HashTableType&>(m_impl).lookup(key);
394 if (!entry) 387 if (!entry)
395 return MappedTraits::peek(MappedTraits::emptyValue()); 388 return MappedTraits::peek(MappedTraits::emptyValue());
396 return MappedTraits::peek(entry->value); 389 return MappedTraits::peek(entry->value);
397 } 390 }
398 391
399 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 392 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
400 inline void HashMap<T, U, V, W, X, Y>::remove(iterator it) 393 inline void HashMap<T, U, V, W, X, Y>::remove(iterator it)
401 { 394 {
402 m_impl.remove(it.m_impl); 395 m_impl.remove(it.m_impl);
403 } 396 }
404 397
405 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 398 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
406 inline void HashMap<T, U, V, W, X, Y>::remove(KeyPeekInType key) 399 inline void HashMap<T, U, V, W, X, Y>::remove(KeyPeekInType key)
407 { 400 {
408 remove(find(key)); 401 remove(find(key));
409 } 402 }
410 403
411 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 404 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
412 inline void HashMap<T, U, V, W, X, Y>::clear() 405 inline void HashMap<T, U, V, W, X, Y>::clear()
413 { 406 {
414 m_impl.clear(); 407 m_impl.clear();
415 } 408 }
416 409
417 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 410 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
418 typename HashMap<T, U, V, W, X, Y>::MappedPassOutType 411 auto HashMap<T, U, V, W, X, Y>::take(KeyPeekInType key) -> MappedPassOutType
419 HashMap<T, U, V, W, X, Y>::take(KeyPeekInType key)
420 { 412 {
421 iterator it = find(key); 413 iterator it = find(key);
422 if (it == end()) 414 if (it == end())
423 return MappedTraits::passOut(MappedTraits::emptyValue()); 415 return MappedTraits::passOut(MappedTraits::emptyValue());
424 MappedPassOutType result = MappedTraits::passOut(it->value); 416 MappedPassOutType result = MappedTraits::passOut(it->value);
425 remove(it); 417 remove(it);
426 return result; 418 return result;
427 } 419 }
428 420
429 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 421 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 struct NeedsTracing<HashMap<T, U, V, W, X>> { 491 struct NeedsTracing<HashMap<T, U, V, W, X>> {
500 static const bool value = false; 492 static const bool value = false;
501 }; 493 };
502 #endif 494 #endif
503 495
504 } // namespace WTF 496 } // namespace WTF
505 497
506 using WTF::HashMap; 498 using WTF::HashMap;
507 499
508 #endif /* WTF_HashMap_h */ 500 #endif /* WTF_HashMap_h */
OLDNEW
« no previous file with comments | « no previous file | Source/wtf/HashTable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698