| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 120 |
| 121 // An alternate version of find() that finds the object by hashing and c
omparing | 121 // An alternate version of find() that finds the object by hashing and c
omparing |
| 122 // with some other type, to avoid the cost of type conversion. | 122 // with some other type, to avoid the cost of type conversion. |
| 123 // The HashTranslator interface is defined in HashSet. | 123 // The HashTranslator interface is defined in HashSet. |
| 124 // FIXME: We should reverse the order of the template arguments so that
callers | 124 // FIXME: We should reverse the order of the template arguments so that
callers |
| 125 // can just pass the translator let the compiler deduce T. | 125 // can just pass the translator let the compiler deduce T. |
| 126 template<typename T, typename HashTranslator> iterator find(const T&); | 126 template<typename T, typename HashTranslator> iterator find(const T&); |
| 127 template<typename T, typename HashTranslator> const_iterator find(const
T&) const; | 127 template<typename T, typename HashTranslator> const_iterator find(const
T&) const; |
| 128 template<typename T, typename HashTranslator> bool contains(const T&) co
nst; | 128 template<typename T, typename HashTranslator> bool contains(const T&) co
nst; |
| 129 | 129 |
| 130 // The return value of add is a pair of an iterator to the new value's l
ocation, | 130 // The return value of add is a pair of an iterator to the new value's l
ocation, |
| 131 // and a bool that is true if an new entry was added. | 131 // and a bool that is true if an new entry was added. |
| 132 AddResult add(const ValueType&); | 132 AddResult add(const ValueType&); |
| 133 | 133 |
| 134 // Add the value to the end of the collection. If the value was already
in | 134 // Add the value to the end of the collection. If the value was already
in |
| 135 // the list, it is moved to the end. | 135 // the list, it is moved to the end. |
| 136 AddResult appendOrMoveToLast(const ValueType&); | 136 AddResult appendOrMoveToLast(const ValueType&); |
| 137 | 137 |
| 138 // Add the value to the beginning of the collection. If the value was al
ready in | 138 // Add the value to the beginning of the collection. If the value was al
ready in |
| 139 // the list, it is moved to the beginning. | 139 // the list, it is moved to the beginning. |
| 140 AddResult prependOrMoveToFirst(const ValueType&); | 140 AddResult prependOrMoveToFirst(const ValueType&); |
| 141 | 141 |
| 142 AddResult insertBefore(const ValueType& beforeValue, const ValueType& ne
wValue); | 142 AddResult insertBefore(const ValueType& beforeValue, const ValueType& ne
wValue); |
| 143 AddResult insertBefore(iterator, const ValueType&); | 143 AddResult insertBefore(iterator, const ValueType&); |
| 144 | 144 |
| 145 void remove(const ValueType&); | 145 void remove(const ValueType&); |
| 146 void remove(iterator); | 146 void remove(iterator); |
| 147 void clear(); | 147 void clear(); |
| 148 | 148 |
| 149 private: | 149 private: |
| 150 void unlink(Node*); | 150 void unlink(Node*); |
| 151 void unlinkAndDelete(Node*); | 151 void unlinkAndDelete(Node*); |
| 152 void appendNode(Node*); | 152 void appendNode(Node*); |
| 153 void prependNode(Node*); | 153 void prependNode(Node*); |
| 154 void insertNodeBefore(Node* beforeNode, Node* newNode); | 154 void insertNodeBefore(Node* beforeNode, Node* newNode); |
| 155 void deleteAllNodes(); | 155 void deleteAllNodes(); |
| 156 | 156 |
| 157 iterator makeIterator(Node*); | 157 iterator makeIterator(Node*); |
| 158 const_iterator makeConstIterator(Node*) const; | 158 const_iterator makeConstIterator(Node*) const; |
| 159 reverse_iterator makeReverseIterator(Node*); | 159 reverse_iterator makeReverseIterator(Node*); |
| 160 const_reverse_iterator makeConstReverseIterator(Node*) const; | 160 const_reverse_iterator makeConstReverseIterator(Node*) const; |
| 161 | 161 |
| 162 friend void deleteAllValues<>(const ListHashSet&); | 162 friend void deleteAllValues<>(const ListHashSet&); |
| 163 | 163 |
| 164 ImplType m_impl; | 164 ImplType m_impl; |
| 165 Node* m_head; | 165 Node* m_head; |
| 166 Node* m_tail; | 166 Node* m_tail; |
| 167 OwnPtr<NodeAllocator> m_allocator; | 167 OwnPtr<NodeAllocator> m_allocator; |
| 168 }; | 168 }; |
| 169 | 169 |
| 170 template<typename ValueArg, size_t inlineCapacity> struct ListHashSetNodeAll
ocator { | 170 template<typename ValueArg, size_t inlineCapacity> struct ListHashSetNodeAll
ocator { |
| 171 typedef ListHashSetNode<ValueArg, inlineCapacity> Node; | 171 typedef ListHashSetNode<ValueArg, inlineCapacity> Node; |
| 172 typedef ListHashSetNodeAllocator<ValueArg, inlineCapacity> NodeAllocator
; | 172 typedef ListHashSetNodeAllocator<ValueArg, inlineCapacity> NodeAllocator
; |
| 173 | 173 |
| 174 ListHashSetNodeAllocator() | 174 ListHashSetNodeAllocator() |
| 175 : m_freeList(pool()) | 175 : m_freeList(pool()) |
| 176 , m_isDoneWithInitialFreeList(false) | 176 , m_isDoneWithInitialFreeList(false) |
| 177 { | 177 { |
| 178 memset(m_pool.pool, 0, sizeof(m_pool.pool)); | 178 memset(m_pool.pool, 0, sizeof(m_pool.pool)); |
| 179 } | 179 } |
| 180 | 180 |
| 181 Node* allocate() | 181 Node* allocate() |
| 182 { | 182 { |
| 183 Node* result = m_freeList; | 183 Node* result = m_freeList; |
| 184 | 184 |
| 185 if (!result) | 185 if (!result) |
| 186 return static_cast<Node*>(fastMalloc(sizeof(Node))); | 186 return static_cast<Node*>(fastMalloc(sizeof(Node))); |
| 187 | 187 |
| 188 ASSERT(!result->m_isAllocated); | 188 ASSERT(!result->m_isAllocated); |
| 189 | 189 |
| 190 Node* next = result->m_next; | 190 Node* next = result->m_next; |
| 191 ASSERT(!next || !next->m_isAllocated); | 191 ASSERT(!next || !next->m_isAllocated); |
| 192 if (!next && !m_isDoneWithInitialFreeList) { | 192 if (!next && !m_isDoneWithInitialFreeList) { |
| 193 next = result + 1; | 193 next = result + 1; |
| 194 if (next == pastPool()) { | 194 if (next == pastPool()) { |
| 195 m_isDoneWithInitialFreeList = true; | 195 m_isDoneWithInitialFreeList = true; |
| 196 next = 0; | 196 next = 0; |
| 197 } else { | 197 } else { |
| 198 ASSERT(inPool(next)); | 198 ASSERT(inPool(next)); |
| 199 ASSERT(!next->m_isAllocated); | 199 ASSERT(!next->m_isAllocated); |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 m_freeList = next; | 202 m_freeList = next; |
| 203 | 203 |
| 204 return result; | 204 return result; |
| 205 } | 205 } |
| 206 | 206 |
| 207 void deallocate(Node* node) | 207 void deallocate(Node* node) |
| 208 { | 208 { |
| 209 if (inPool(node)) { | 209 if (inPool(node)) { |
| 210 #ifndef NDEBUG | 210 #ifndef NDEBUG |
| 211 node->m_isAllocated = false; | 211 node->m_isAllocated = false; |
| 212 #endif | 212 #endif |
| 213 node->m_next = m_freeList; | 213 node->m_next = m_freeList; |
| 214 m_freeList = node; | 214 m_freeList = node; |
| 215 return; | 215 return; |
| 216 } | 216 } |
| 217 | 217 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 | 546 |
| 547 template<typename T, size_t inlineCapacity, typename U> | 547 template<typename T, size_t inlineCapacity, typename U> |
| 548 inline ListHashSet<T, inlineCapacity, U>::~ListHashSet() | 548 inline ListHashSet<T, inlineCapacity, U>::~ListHashSet() |
| 549 { | 549 { |
| 550 deleteAllNodes(); | 550 deleteAllNodes(); |
| 551 } | 551 } |
| 552 | 552 |
| 553 template<typename T, size_t inlineCapacity, typename U> | 553 template<typename T, size_t inlineCapacity, typename U> |
| 554 inline int ListHashSet<T, inlineCapacity, U>::size() const | 554 inline int ListHashSet<T, inlineCapacity, U>::size() const |
| 555 { | 555 { |
| 556 return m_impl.size(); | 556 return m_impl.size(); |
| 557 } | 557 } |
| 558 | 558 |
| 559 template<typename T, size_t inlineCapacity, typename U> | 559 template<typename T, size_t inlineCapacity, typename U> |
| 560 inline int ListHashSet<T, inlineCapacity, U>::capacity() const | 560 inline int ListHashSet<T, inlineCapacity, U>::capacity() const |
| 561 { | 561 { |
| 562 return m_impl.capacity(); | 562 return m_impl.capacity(); |
| 563 } | 563 } |
| 564 | 564 |
| 565 template<typename T, size_t inlineCapacity, typename U> | 565 template<typename T, size_t inlineCapacity, typename U> |
| 566 inline bool ListHashSet<T, inlineCapacity, U>::isEmpty() const | 566 inline bool ListHashSet<T, inlineCapacity, U>::isEmpty() const |
| 567 { | 567 { |
| 568 return m_impl.isEmpty(); | 568 return m_impl.isEmpty(); |
| 569 } | 569 } |
| 570 | 570 |
| 571 template<typename T, size_t inlineCapacity, typename U> | 571 template<typename T, size_t inlineCapacity, typename U> |
| 572 size_t ListHashSet<T, inlineCapacity, U>::sizeInBytes() const | 572 size_t ListHashSet<T, inlineCapacity, U>::sizeInBytes() const |
| 573 { | 573 { |
| 574 size_t result = sizeof(*this) + sizeof(*m_allocator); | 574 size_t result = sizeof(*this) + sizeof(*m_allocator); |
| 575 result += sizeof(typename ImplType::ValueType) * m_impl.capacity(); | 575 result += sizeof(typename ImplType::ValueType) * m_impl.capacity(); |
| 576 for (Node* node = m_head; node; node = node->m_next) { | 576 for (Node* node = m_head; node; node = node->m_next) { |
| 577 if (!m_allocator->inPool(node)) | 577 if (!m_allocator->inPool(node)) |
| 578 result += sizeof(Node); | 578 result += sizeof(Node); |
| 579 } | 579 } |
| 580 return result; | 580 return result; |
| 581 } | 581 } |
| 582 | 582 |
| 583 template<typename T, size_t inlineCapacity, typename U> | 583 template<typename T, size_t inlineCapacity, typename U> |
| 584 inline typename ListHashSet<T, inlineCapacity, U>::iterator ListHashSet<T, i
nlineCapacity, U>::begin() | 584 inline typename ListHashSet<T, inlineCapacity, U>::iterator ListHashSet<T, i
nlineCapacity, U>::begin() |
| 585 { | 585 { |
| 586 return makeIterator(m_head); | 586 return makeIterator(m_head); |
| 587 } | 587 } |
| 588 | 588 |
| 589 template<typename T, size_t inlineCapacity, typename U> | 589 template<typename T, size_t inlineCapacity, typename U> |
| 590 inline typename ListHashSet<T, inlineCapacity, U>::iterator ListHashSet<T, i
nlineCapacity, U>::end() | 590 inline typename ListHashSet<T, inlineCapacity, U>::iterator ListHashSet<T, i
nlineCapacity, U>::end() |
| 591 { | 591 { |
| 592 return makeIterator(0); | 592 return makeIterator(0); |
| 593 } | 593 } |
| 594 | 594 |
| 595 template<typename T, size_t inlineCapacity, typename U> | 595 template<typename T, size_t inlineCapacity, typename U> |
| 596 inline typename ListHashSet<T, inlineCapacity, U>::const_iterator ListHashSe
t<T, inlineCapacity, U>::begin() const | 596 inline typename ListHashSet<T, inlineCapacity, U>::const_iterator ListHashSe
t<T, inlineCapacity, U>::begin() const |
| 597 { | 597 { |
| 598 return makeConstIterator(m_head); | 598 return makeConstIterator(m_head); |
| 599 } | 599 } |
| 600 | 600 |
| 601 template<typename T, size_t inlineCapacity, typename U> | 601 template<typename T, size_t inlineCapacity, typename U> |
| 602 inline typename ListHashSet<T, inlineCapacity, U>::const_iterator ListHashSe
t<T, inlineCapacity, U>::end() const | 602 inline typename ListHashSet<T, inlineCapacity, U>::const_iterator ListHashSe
t<T, inlineCapacity, U>::end() const |
| 603 { | 603 { |
| 604 return makeConstIterator(0); | 604 return makeConstIterator(0); |
| 605 } | 605 } |
| 606 | 606 |
| 607 template<typename T, size_t inlineCapacity, typename U> | 607 template<typename T, size_t inlineCapacity, typename U> |
| 608 inline typename ListHashSet<T, inlineCapacity, U>::reverse_iterator ListHash
Set<T, inlineCapacity, U>::rbegin() | 608 inline typename ListHashSet<T, inlineCapacity, U>::reverse_iterator ListHash
Set<T, inlineCapacity, U>::rbegin() |
| 609 { | 609 { |
| 610 return makeReverseIterator(m_tail); | 610 return makeReverseIterator(m_tail); |
| 611 } | 611 } |
| 612 | 612 |
| 613 template<typename T, size_t inlineCapacity, typename U> | 613 template<typename T, size_t inlineCapacity, typename U> |
| 614 inline typename ListHashSet<T, inlineCapacity, U>::reverse_iterator ListHash
Set<T, inlineCapacity, U>::rend() | 614 inline typename ListHashSet<T, inlineCapacity, U>::reverse_iterator ListHash
Set<T, inlineCapacity, U>::rend() |
| 615 { | 615 { |
| 616 return makeReverseIterator(0); | 616 return makeReverseIterator(0); |
| 617 } | 617 } |
| 618 | 618 |
| 619 template<typename T, size_t inlineCapacity, typename U> | 619 template<typename T, size_t inlineCapacity, typename U> |
| 620 inline typename ListHashSet<T, inlineCapacity, U>::const_reverse_iterator Li
stHashSet<T, inlineCapacity, U>::rbegin() const | 620 inline typename ListHashSet<T, inlineCapacity, U>::const_reverse_iterator Li
stHashSet<T, inlineCapacity, U>::rbegin() const |
| 621 { | 621 { |
| 622 return makeConstReverseIterator(m_tail); | 622 return makeConstReverseIterator(m_tail); |
| 623 } | 623 } |
| 624 | 624 |
| 625 template<typename T, size_t inlineCapacity, typename U> | 625 template<typename T, size_t inlineCapacity, typename U> |
| 626 inline typename ListHashSet<T, inlineCapacity, U>::const_reverse_iterator Li
stHashSet<T, inlineCapacity, U>::rend() const | 626 inline typename ListHashSet<T, inlineCapacity, U>::const_reverse_iterator Li
stHashSet<T, inlineCapacity, U>::rend() const |
| 627 { | 627 { |
| 628 return makeConstReverseIterator(0); | 628 return makeConstReverseIterator(0); |
| 629 } | 629 } |
| 630 | 630 |
| 631 template<typename T, size_t inlineCapacity, typename U> | 631 template<typename T, size_t inlineCapacity, typename U> |
| 632 inline T& ListHashSet<T, inlineCapacity, U>::first() | 632 inline T& ListHashSet<T, inlineCapacity, U>::first() |
| 633 { | 633 { |
| 634 ASSERT(!isEmpty()); | 634 ASSERT(!isEmpty()); |
| 635 return m_head->m_value; | 635 return m_head->m_value; |
| 636 } | 636 } |
| 637 | 637 |
| 638 template<typename T, size_t inlineCapacity, typename U> | 638 template<typename T, size_t inlineCapacity, typename U> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 m_impl.remove(m_tail); | 671 m_impl.remove(m_tail); |
| 672 unlinkAndDelete(m_tail); | 672 unlinkAndDelete(m_tail); |
| 673 } | 673 } |
| 674 | 674 |
| 675 template<typename T, size_t inlineCapacity, typename U> | 675 template<typename T, size_t inlineCapacity, typename U> |
| 676 inline typename ListHashSet<T, inlineCapacity, U>::iterator ListHashSet<T, i
nlineCapacity, U>::find(const ValueType& value) | 676 inline typename ListHashSet<T, inlineCapacity, U>::iterator ListHashSet<T, i
nlineCapacity, U>::find(const ValueType& value) |
| 677 { | 677 { |
| 678 ImplTypeIterator it = m_impl.template find<BaseTranslator>(value); | 678 ImplTypeIterator it = m_impl.template find<BaseTranslator>(value); |
| 679 if (it == m_impl.end()) | 679 if (it == m_impl.end()) |
| 680 return end(); | 680 return end(); |
| 681 return makeIterator(*it); | 681 return makeIterator(*it); |
| 682 } | 682 } |
| 683 | 683 |
| 684 template<typename T, size_t inlineCapacity, typename U> | 684 template<typename T, size_t inlineCapacity, typename U> |
| 685 inline typename ListHashSet<T, inlineCapacity, U>::const_iterator ListHashSe
t<T, inlineCapacity, U>::find(const ValueType& value) const | 685 inline typename ListHashSet<T, inlineCapacity, U>::const_iterator ListHashSe
t<T, inlineCapacity, U>::find(const ValueType& value) const |
| 686 { | 686 { |
| 687 ImplTypeConstIterator it = m_impl.template find<BaseTranslator>(value); | 687 ImplTypeConstIterator it = m_impl.template find<BaseTranslator>(value); |
| 688 if (it == m_impl.end()) | 688 if (it == m_impl.end()) |
| 689 return end(); | 689 return end(); |
| 690 return makeConstIterator(*it); | 690 return makeConstIterator(*it); |
| 691 } | 691 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 { | 765 { |
| 766 typename ImplType::AddResult result = m_impl.template add<BaseTranslator
>(newValue, m_allocator.get()); | 766 typename ImplType::AddResult result = m_impl.template add<BaseTranslator
>(newValue, m_allocator.get()); |
| 767 if (result.isNewEntry) | 767 if (result.isNewEntry) |
| 768 insertNodeBefore(it.node(), *result.iterator); | 768 insertNodeBefore(it.node(), *result.iterator); |
| 769 return AddResult(makeIterator(*result.iterator), result.isNewEntry); | 769 return AddResult(makeIterator(*result.iterator), result.isNewEntry); |
| 770 } | 770 } |
| 771 | 771 |
| 772 template<typename T, size_t inlineCapacity, typename U> | 772 template<typename T, size_t inlineCapacity, typename U> |
| 773 typename ListHashSet<T, inlineCapacity, U>::AddResult ListHashSet<T, inlineC
apacity, U>::insertBefore(const ValueType& beforeValue, const ValueType& newValu
e) | 773 typename ListHashSet<T, inlineCapacity, U>::AddResult ListHashSet<T, inlineC
apacity, U>::insertBefore(const ValueType& beforeValue, const ValueType& newValu
e) |
| 774 { | 774 { |
| 775 return insertBefore(find(beforeValue), newValue); | 775 return insertBefore(find(beforeValue), newValue); |
| 776 } | 776 } |
| 777 | 777 |
| 778 template<typename T, size_t inlineCapacity, typename U> | 778 template<typename T, size_t inlineCapacity, typename U> |
| 779 inline void ListHashSet<T, inlineCapacity, U>::remove(iterator it) | 779 inline void ListHashSet<T, inlineCapacity, U>::remove(iterator it) |
| 780 { | 780 { |
| 781 if (it == end()) | 781 if (it == end()) |
| 782 return; | 782 return; |
| 783 m_impl.remove(it.node()); | 783 m_impl.remove(it.node()); |
| 784 unlinkAndDelete(it.node()); | 784 unlinkAndDelete(it.node()); |
| 785 } | 785 } |
| 786 | 786 |
| 787 template<typename T, size_t inlineCapacity, typename U> | 787 template<typename T, size_t inlineCapacity, typename U> |
| 788 inline void ListHashSet<T, inlineCapacity, U>::remove(const ValueType& value
) | 788 inline void ListHashSet<T, inlineCapacity, U>::remove(const ValueType& value
) |
| 789 { | 789 { |
| 790 remove(find(value)); | 790 remove(find(value)); |
| 791 } | 791 } |
| 792 | 792 |
| 793 template<typename T, size_t inlineCapacity, typename U> | 793 template<typename T, size_t inlineCapacity, typename U> |
| 794 inline void ListHashSet<T, inlineCapacity, U>::clear() | 794 inline void ListHashSet<T, inlineCapacity, U>::clear() |
| 795 { | 795 { |
| 796 deleteAllNodes(); | 796 deleteAllNodes(); |
| 797 m_impl.clear(); | 797 m_impl.clear(); |
| 798 m_head = 0; | 798 m_head = 0; |
| 799 m_tail = 0; | 799 m_tail = 0; |
| 800 } | 800 } |
| 801 | 801 |
| 802 template<typename T, size_t inlineCapacity, typename U> | 802 template<typename T, size_t inlineCapacity, typename U> |
| 803 void ListHashSet<T, inlineCapacity, U>::unlink(Node* node) | 803 void ListHashSet<T, inlineCapacity, U>::unlink(Node* node) |
| 804 { | 804 { |
| 805 if (!node->m_prev) { | 805 if (!node->m_prev) { |
| 806 ASSERT(node == m_head); | 806 ASSERT(node == m_head); |
| 807 m_head = node->m_next; | 807 m_head = node->m_next; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 m_tail = node; | 855 m_tail = node; |
| 856 | 856 |
| 857 m_head = node; | 857 m_head = node; |
| 858 } | 858 } |
| 859 | 859 |
| 860 template<typename T, size_t inlineCapacity, typename U> | 860 template<typename T, size_t inlineCapacity, typename U> |
| 861 void ListHashSet<T, inlineCapacity, U>::insertNodeBefore(Node* beforeNode, N
ode* newNode) | 861 void ListHashSet<T, inlineCapacity, U>::insertNodeBefore(Node* beforeNode, N
ode* newNode) |
| 862 { | 862 { |
| 863 if (!beforeNode) | 863 if (!beforeNode) |
| 864 return appendNode(newNode); | 864 return appendNode(newNode); |
| 865 | 865 |
| 866 newNode->m_next = beforeNode; | 866 newNode->m_next = beforeNode; |
| 867 newNode->m_prev = beforeNode->m_prev; | 867 newNode->m_prev = beforeNode->m_prev; |
| 868 if (beforeNode->m_prev) | 868 if (beforeNode->m_prev) |
| 869 beforeNode->m_prev->m_next = newNode; | 869 beforeNode->m_prev->m_next = newNode; |
| 870 beforeNode->m_prev = newNode; | 870 beforeNode->m_prev = newNode; |
| 871 | 871 |
| 872 if (!newNode->m_prev) | 872 if (!newNode->m_prev) |
| 873 m_head = newNode; | 873 m_head = newNode; |
| 874 } | 874 } |
| 875 | 875 |
| 876 template<typename T, size_t inlineCapacity, typename U> | 876 template<typename T, size_t inlineCapacity, typename U> |
| 877 void ListHashSet<T, inlineCapacity, U>::deleteAllNodes() | 877 void ListHashSet<T, inlineCapacity, U>::deleteAllNodes() |
| 878 { | 878 { |
| 879 if (!m_head) | 879 if (!m_head) |
| 880 return; | 880 return; |
| 881 | 881 |
| 882 for (Node* node = m_head, *next = m_head->m_next; node; node = next, nex
t = node ? node->m_next : 0) | 882 for (Node* node = m_head, *next = m_head->m_next; node; node = next, nex
t = node ? node->m_next : 0) |
| 883 node->destroy(m_allocator.get()); | 883 node->destroy(m_allocator.get()); |
| 884 } | 884 } |
| 885 | 885 |
| 886 template<typename T, size_t inlineCapacity, typename U> | 886 template<typename T, size_t inlineCapacity, typename U> |
| 887 inline ListHashSetReverseIterator<T, inlineCapacity, U> ListHashSet<T, inlin
eCapacity, U>::makeReverseIterator(Node* position) | 887 inline ListHashSetReverseIterator<T, inlineCapacity, U> ListHashSet<T, inlin
eCapacity, U>::makeReverseIterator(Node* position) |
| 888 { | 888 { |
| 889 return ListHashSetReverseIterator<T, inlineCapacity, U>(this, position);
| 889 return ListHashSetReverseIterator<T, inlineCapacity, U>(this, position); |
| 890 } | 890 } |
| 891 | 891 |
| 892 template<typename T, size_t inlineCapacity, typename U> | 892 template<typename T, size_t inlineCapacity, typename U> |
| 893 inline ListHashSetConstReverseIterator<T, inlineCapacity, U> ListHashSet<T,
inlineCapacity, U>::makeConstReverseIterator(Node* position) const | 893 inline ListHashSetConstReverseIterator<T, inlineCapacity, U> ListHashSet<T,
inlineCapacity, U>::makeConstReverseIterator(Node* position) const |
| 894 { | 894 { |
| 895 return ListHashSetConstReverseIterator<T, inlineCapacity, U>(this, posit
ion); | 895 return ListHashSetConstReverseIterator<T, inlineCapacity, U>(this, posit
ion); |
| 896 } | 896 } |
| 897 | 897 |
| 898 template<typename T, size_t inlineCapacity, typename U> | 898 template<typename T, size_t inlineCapacity, typename U> |
| 899 inline ListHashSetIterator<T, inlineCapacity, U> ListHashSet<T, inlineCapaci
ty, U>::makeIterator(Node* position) | 899 inline ListHashSetIterator<T, inlineCapacity, U> ListHashSet<T, inlineCapaci
ty, U>::makeIterator(Node* position) |
| 900 { | 900 { |
| 901 return ListHashSetIterator<T, inlineCapacity, U>(this, position); | 901 return ListHashSetIterator<T, inlineCapacity, U>(this, position); |
| 902 } | 902 } |
| 903 | 903 |
| 904 template<typename T, size_t inlineCapacity, typename U> | 904 template<typename T, size_t inlineCapacity, typename U> |
| 905 inline ListHashSetConstIterator<T, inlineCapacity, U> ListHashSet<T, inlineC
apacity, U>::makeConstIterator(Node* position) const | 905 inline ListHashSetConstIterator<T, inlineCapacity, U> ListHashSet<T, inlineC
apacity, U>::makeConstIterator(Node* position) const |
| 906 { | 906 { |
| 907 return ListHashSetConstIterator<T, inlineCapacity, U>(this, position); | 907 return ListHashSetConstIterator<T, inlineCapacity, U>(this, position); |
| 908 } | 908 } |
| 909 template<bool, typename ValueType, typename HashTableType> | 909 template<bool, typename ValueType, typename HashTableType> |
| 910 void deleteAllValues(HashTableType& collection) | 910 void deleteAllValues(HashTableType& collection) |
| 911 { | 911 { |
| 912 typedef typename HashTableType::const_iterator iterator; | 912 typedef typename HashTableType::const_iterator iterator; |
| 913 iterator end = collection.end(); | 913 iterator end = collection.end(); |
| 914 for (iterator it = collection.begin(); it != end; ++it) | 914 for (iterator it = collection.begin(); it != end; ++it) |
| 915 delete (*it)->m_value; | 915 delete (*it)->m_value; |
| 916 } | 916 } |
| 917 | 917 |
| 918 template<typename T, size_t inlineCapacity, typename U> | 918 template<typename T, size_t inlineCapacity, typename U> |
| 919 inline void deleteAllValues(const ListHashSet<T, inlineCapacity, U>& collect
ion) | 919 inline void deleteAllValues(const ListHashSet<T, inlineCapacity, U>& collect
ion) |
| 920 { | 920 { |
| 921 deleteAllValues<true, typename ListHashSet<T, inlineCapacity, U>::ValueT
ype>(collection.m_impl); | 921 deleteAllValues<true, typename ListHashSet<T, inlineCapacity, U>::ValueT
ype>(collection.m_impl); |
| 922 } | 922 } |
| 923 | 923 |
| 924 } // namespace WTF | 924 } // namespace WTF |
| 925 | 925 |
| 926 using WTF::ListHashSet; | 926 using WTF::ListHashSet; |
| 927 | 927 |
| 928 #endif /* WTF_ListHashSet_h */ | 928 #endif /* WTF_ListHashSet_h */ |
| OLD | NEW |