OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv
ed. |
3 * Copyright (C) 2011, Benjamin Poulain <ikipou@gmail.com> | 3 * Copyright (C) 2011, Benjamin Poulain <ikipou@gmail.com> |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 238 |
239 // An alternate version of find() that finds the object by hashing and compa
ring | 239 // An alternate version of find() that finds the object by hashing and compa
ring |
240 // with some other type, to avoid the cost of type conversion. | 240 // with some other type, to avoid the cost of type conversion. |
241 // The HashTranslator interface is defined in HashSet. | 241 // The HashTranslator interface is defined in HashSet. |
242 template<typename HashTranslator, typename T> iterator find(const T&); | 242 template<typename HashTranslator, typename T> iterator find(const T&); |
243 template<typename HashTranslator, typename T> const_iterator find(const T&)
const; | 243 template<typename HashTranslator, typename T> const_iterator find(const T&)
const; |
244 template<typename HashTranslator, typename T> bool contains(const T&) const; | 244 template<typename HashTranslator, typename T> bool contains(const T&) const; |
245 | 245 |
246 // The return value of add is a pair of a pointer to the stored value, | 246 // The return value of add is a pair of a pointer to the stored value, |
247 // and a bool that is true if an new entry was added. | 247 // and a bool that is true if an new entry was added. |
248 AddResult add(ValuePeekInType); | 248 template <typename IncomingValueType> |
| 249 AddResult add(IncomingValueType&&); |
249 | 250 |
250 // Same as add() except that the return value is an | 251 // Same as add() except that the return value is an |
251 // iterator. Useful in cases where it's needed to have the | 252 // iterator. Useful in cases where it's needed to have the |
252 // same return value as find() and where it's not possible to | 253 // same return value as find() and where it's not possible to |
253 // use a pointer to the storedValue. | 254 // use a pointer to the storedValue. |
254 iterator addReturnIterator(ValuePeekInType); | 255 template <typename IncomingValueType> |
| 256 iterator addReturnIterator(IncomingValueType&&); |
255 | 257 |
256 // Add the value to the end of the collection. If the value was already in | 258 // Add the value to the end of the collection. If the value was already in |
257 // the list, it is moved to the end. | 259 // the list, it is moved to the end. |
258 AddResult appendOrMoveToLast(ValuePeekInType); | 260 template <typename IncomingValueType> |
| 261 AddResult appendOrMoveToLast(IncomingValueType&&); |
259 | 262 |
260 // Add the value to the beginning of the collection. If the value was alread
y in | 263 // Add the value to the beginning of the collection. If the value was alread
y in |
261 // the list, it is moved to the beginning. | 264 // the list, it is moved to the beginning. |
262 AddResult prependOrMoveToFirst(ValuePeekInType); | 265 template <typename IncomingValueType> |
| 266 AddResult prependOrMoveToFirst(IncomingValueType&&); |
263 | 267 |
264 AddResult insertBefore(ValuePeekInType beforeValue, ValuePeekInType newValue
); | 268 template <typename IncomingValueType> |
265 AddResult insertBefore(iterator it, ValuePeekInType newValue) { return m_imp
l.template add<NodeHashFunctions>(newValue, it.node()); } | 269 AddResult insertBefore(ValuePeekInType beforeValue, IncomingValueType&& newV
alue); |
| 270 template <typename IncomingValueType> |
| 271 AddResult insertBefore(iterator it, IncomingValueType&& newValue) { return m
_impl.template add<NodeHashFunctions>(std::forward<IncomingValueType>(newValue),
it.node()); } |
266 | 272 |
267 void remove(ValuePeekInType); | 273 void remove(ValuePeekInType); |
268 void remove(iterator); | 274 void remove(iterator); |
269 void clear() { m_impl.clear(); } | 275 void clear() { m_impl.clear(); } |
270 template<typename Collection> | 276 template<typename Collection> |
271 void removeAll(const Collection& other) { WTF::removeAll(*this, other); } | 277 void removeAll(const Collection& other) { WTF::removeAll(*this, other); } |
272 | 278 |
273 template<typename VisitorDispatcher> | 279 template<typename VisitorDispatcher> |
274 void trace(VisitorDispatcher visitor) { m_impl.trace(visitor); } | 280 void trace(VisitorDispatcher visitor) { m_impl.trace(visitor); } |
275 | 281 |
(...skipping 20 matching lines...) Expand all Loading... |
296 template<typename Value, typename HashFunctions, typename Allocator> | 302 template<typename Value, typename HashFunctions, typename Allocator> |
297 struct LinkedHashSetTranslator { | 303 struct LinkedHashSetTranslator { |
298 STATIC_ONLY(LinkedHashSetTranslator); | 304 STATIC_ONLY(LinkedHashSetTranslator); |
299 typedef LinkedHashSetNode<Value, Allocator> Node; | 305 typedef LinkedHashSetNode<Value, Allocator> Node; |
300 typedef LinkedHashSetNodeBase NodeBase; | 306 typedef LinkedHashSetNodeBase NodeBase; |
301 typedef typename HashTraits<Value>::PeekInType ValuePeekInType; | 307 typedef typename HashTraits<Value>::PeekInType ValuePeekInType; |
302 static unsigned hash(const Node& node) { return HashFunctions::hash(node.m_v
alue); } | 308 static unsigned hash(const Node& node) { return HashFunctions::hash(node.m_v
alue); } |
303 static unsigned hash(const ValuePeekInType& key) { return HashFunctions::has
h(key); } | 309 static unsigned hash(const ValuePeekInType& key) { return HashFunctions::has
h(key); } |
304 static bool equal(const Node& a, const ValuePeekInType& b) { return HashFunc
tions::equal(a.m_value, b); } | 310 static bool equal(const Node& a, const ValuePeekInType& b) { return HashFunc
tions::equal(a.m_value, b); } |
305 static bool equal(const Node& a, const Node& b) { return HashFunctions::equa
l(a.m_value, b.m_value); } | 311 static bool equal(const Node& a, const Node& b) { return HashFunctions::equa
l(a.m_value, b.m_value); } |
306 static void translate(Node& location, ValuePeekInType key, NodeBase* anchor) | 312 template <typename IncomingValueType> |
| 313 static void translate(Node& location, IncomingValueType&& key, NodeBase* anc
hor) |
307 { | 314 { |
308 anchor->insertBefore(location); | 315 anchor->insertBefore(location); |
309 location.m_value = key; | 316 location.m_value = std::forward<IncomingValueType>(key); |
310 } | 317 } |
311 | 318 |
312 // Empty (or deleted) slots have the m_next pointer set to null, but we | 319 // Empty (or deleted) slots have the m_next pointer set to null, but we |
313 // don't do anything to the other fields, which may contain junk. | 320 // don't do anything to the other fields, which may contain junk. |
314 // Therefore you can't compare a newly constructed empty value with a | 321 // Therefore you can't compare a newly constructed empty value with a |
315 // slot and get the right answer. | 322 // slot and get the right answer. |
316 static const bool safeToCompareToEmptyOrDeleted = false; | 323 static const bool safeToCompareToEmptyOrDeleted = false; |
317 }; | 324 }; |
318 | 325 |
319 template<typename Value, typename Allocator> | 326 template<typename Value, typename Allocator> |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 return m_impl.template contains<LinkedHashSetTranslatorAdapter<HashTranslato
r>>(value); | 654 return m_impl.template contains<LinkedHashSetTranslatorAdapter<HashTranslato
r>>(value); |
648 } | 655 } |
649 | 656 |
650 template<typename T, typename U, typename V, typename W> | 657 template<typename T, typename U, typename V, typename W> |
651 inline bool LinkedHashSet<T, U, V, W>::contains(ValuePeekInType value) const | 658 inline bool LinkedHashSet<T, U, V, W>::contains(ValuePeekInType value) const |
652 { | 659 { |
653 return m_impl.template contains<NodeHashFunctions>(value); | 660 return m_impl.template contains<NodeHashFunctions>(value); |
654 } | 661 } |
655 | 662 |
656 template<typename Value, typename HashFunctions, typename Traits, typename Alloc
ator> | 663 template<typename Value, typename HashFunctions, typename Traits, typename Alloc
ator> |
657 typename LinkedHashSet<Value, HashFunctions, Traits, Allocator>::AddResult Linke
dHashSet<Value, HashFunctions, Traits, Allocator>::add(ValuePeekInType value) | 664 template<typename IncomingValueType> |
| 665 typename LinkedHashSet<Value, HashFunctions, Traits, Allocator>::AddResult Linke
dHashSet<Value, HashFunctions, Traits, Allocator>::add(IncomingValueType&& value
) |
658 { | 666 { |
659 return m_impl.template add<NodeHashFunctions>(value, &m_anchor); | 667 return m_impl.template add<NodeHashFunctions>(std::forward<IncomingValueType
>(value), &m_anchor); |
660 } | 668 } |
661 | 669 |
662 template<typename T, typename U, typename V, typename W> | 670 template<typename T, typename U, typename V, typename W> |
663 typename LinkedHashSet<T, U, V, W>::iterator LinkedHashSet<T, U, V, W>::addRetur
nIterator(ValuePeekInType value) | 671 template<typename IncomingValueType> |
| 672 typename LinkedHashSet<T, U, V, W>::iterator LinkedHashSet<T, U, V, W>::addRetur
nIterator(IncomingValueType&& value) |
664 { | 673 { |
665 typename ImplType::AddResult result = m_impl.template add<NodeHashFunctions>
(value, &m_anchor); | 674 typename ImplType::AddResult result = m_impl.template add<NodeHashFunctions>
(std::forward<IncomingValueType>(value), &m_anchor); |
666 return makeIterator(result.storedValue); | 675 return makeIterator(result.storedValue); |
667 } | 676 } |
668 | 677 |
669 template<typename T, typename U, typename V, typename W> | 678 template<typename T, typename U, typename V, typename W> |
670 typename LinkedHashSet<T, U, V, W>::AddResult LinkedHashSet<T, U, V, W>::appendO
rMoveToLast(ValuePeekInType value) | 679 template<typename IncomingValueType> |
| 680 typename LinkedHashSet<T, U, V, W>::AddResult LinkedHashSet<T, U, V, W>::appendO
rMoveToLast(IncomingValueType&& value) |
671 { | 681 { |
672 typename ImplType::AddResult result = m_impl.template add<NodeHashFunctions>
(value, &m_anchor); | 682 typename ImplType::AddResult result = m_impl.template add<NodeHashFunctions>
(std::forward<IncomingValueType>(value), &m_anchor); |
673 Node* node = result.storedValue; | 683 Node* node = result.storedValue; |
674 if (!result.isNewEntry) { | 684 if (!result.isNewEntry) { |
675 node->unlink(); | 685 node->unlink(); |
676 m_anchor.insertBefore(*node); | 686 m_anchor.insertBefore(*node); |
677 } | 687 } |
678 return result; | 688 return result; |
679 } | 689 } |
680 | 690 |
681 template<typename T, typename U, typename V, typename W> | 691 template<typename T, typename U, typename V, typename W> |
682 typename LinkedHashSet<T, U, V, W>::AddResult LinkedHashSet<T, U, V, W>::prepend
OrMoveToFirst(ValuePeekInType value) | 692 template<typename IncomingValueType> |
| 693 typename LinkedHashSet<T, U, V, W>::AddResult LinkedHashSet<T, U, V, W>::prepend
OrMoveToFirst(IncomingValueType&& value) |
683 { | 694 { |
684 typename ImplType::AddResult result = m_impl.template add<NodeHashFunctions>
(value, m_anchor.m_next); | 695 typename ImplType::AddResult result = m_impl.template add<NodeHashFunctions>
(std::forward<IncomingValueType>(value), m_anchor.m_next); |
685 Node* node = result.storedValue; | 696 Node* node = result.storedValue; |
686 if (!result.isNewEntry) { | 697 if (!result.isNewEntry) { |
687 node->unlink(); | 698 node->unlink(); |
688 m_anchor.insertAfter(*node); | 699 m_anchor.insertAfter(*node); |
689 } | 700 } |
690 return result; | 701 return result; |
691 } | 702 } |
692 | 703 |
693 template<typename T, typename U, typename V, typename W> | 704 template<typename T, typename U, typename V, typename W> |
694 typename LinkedHashSet<T, U, V, W>::AddResult LinkedHashSet<T, U, V, W>::insertB
efore(ValuePeekInType beforeValue, ValuePeekInType newValue) | 705 template<typename IncomingValueType> |
| 706 typename LinkedHashSet<T, U, V, W>::AddResult LinkedHashSet<T, U, V, W>::insertB
efore(ValuePeekInType beforeValue, IncomingValueType&& newValue) |
695 { | 707 { |
696 return insertBefore(find(beforeValue), newValue); | 708 return insertBefore(find(beforeValue), std::forward<IncomingValueType>(newVa
lue)); |
697 } | 709 } |
698 | 710 |
699 template<typename T, typename U, typename V, typename W> | 711 template<typename T, typename U, typename V, typename W> |
700 inline void LinkedHashSet<T, U, V, W>::remove(iterator it) | 712 inline void LinkedHashSet<T, U, V, W>::remove(iterator it) |
701 { | 713 { |
702 if (it == end()) | 714 if (it == end()) |
703 return; | 715 return; |
704 m_impl.remove(it.node()); | 716 m_impl.remove(it.node()); |
705 } | 717 } |
706 | 718 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 STATIC_ONLY(NeedsTracing); | 781 STATIC_ONLY(NeedsTracing); |
770 static const bool value = false; | 782 static const bool value = false; |
771 }; | 783 }; |
772 #endif | 784 #endif |
773 | 785 |
774 } // namespace WTF | 786 } // namespace WTF |
775 | 787 |
776 using WTF::LinkedHashSet; | 788 using WTF::LinkedHashSet; |
777 | 789 |
778 #endif /* WTF_LinkedHashSet_h */ | 790 #endif /* WTF_LinkedHashSet_h */ |
OLD | NEW |