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 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 struct ListHashSetTranslator { | 652 struct ListHashSetTranslator { |
653 template<typename T> static unsigned hash(const T& key) { return HashFun
ctions::hash(key); } | 653 template<typename T> static unsigned hash(const T& key) { return HashFun
ctions::hash(key); } |
654 template<typename T, typename U> static bool equal(const T& a, const U&
b) { return HashFunctions::equal(a->m_value, b); } | 654 template<typename T, typename U> static bool equal(const T& a, const U&
b) { return HashFunctions::equal(a->m_value, b); } |
655 template<typename T, typename U, typename V> static void translate(T*& l
ocation, const U& key, const V& allocator) | 655 template<typename T, typename U, typename V> static void translate(T*& l
ocation, const U& key, const V& allocator) |
656 { | 656 { |
657 location = new (const_cast<V*>(&allocator)) T(key); | 657 location = new (const_cast<V*>(&allocator)) T(key); |
658 } | 658 } |
659 }; | 659 }; |
660 | 660 |
661 template<typename T, size_t inlineCapacity, typename U, typename V> | 661 template<typename T, size_t inlineCapacity, typename U, typename V> |
662 inline ListHashSet<T, inlineCapacity, U, V>::ListHashSet() | 662 ListHashSet<T, inlineCapacity, U, V>::ListHashSet() |
663 : m_head(0) | 663 : m_head(0) |
664 , m_tail(0) | 664 , m_tail(0) |
665 { | 665 { |
666 } | 666 } |
667 | 667 |
668 template<typename T, size_t inlineCapacity, typename U, typename V> | 668 template<typename T, size_t inlineCapacity, typename U, typename V> |
669 inline ListHashSet<T, inlineCapacity, U, V>::ListHashSet(const ListHashSet&
other) | 669 ListHashSet<T, inlineCapacity, U, V>::ListHashSet(const ListHashSet& other) |
670 : m_head(0) | 670 : m_head(0) |
671 , m_tail(0) | 671 , m_tail(0) |
672 { | 672 { |
673 const_iterator end = other.end(); | 673 const_iterator end = other.end(); |
674 for (const_iterator it = other.begin(); it != end; ++it) | 674 for (const_iterator it = other.begin(); it != end; ++it) |
675 add(*it); | 675 add(*it); |
676 } | 676 } |
677 | 677 |
678 template<typename T, size_t inlineCapacity, typename U, typename V> | 678 template<typename T, size_t inlineCapacity, typename U, typename V> |
679 inline ListHashSet<T, inlineCapacity, U, V>& ListHashSet<T, inlineCapacity,
U, V>::operator=(const ListHashSet& other) | 679 ListHashSet<T, inlineCapacity, U, V>& ListHashSet<T, inlineCapacity, U, V>::
operator=(const ListHashSet& other) |
680 { | 680 { |
681 ListHashSet tmp(other); | 681 ListHashSet tmp(other); |
682 swap(tmp); | 682 swap(tmp); |
683 return *this; | 683 return *this; |
684 } | 684 } |
685 | 685 |
686 template<typename T, size_t inlineCapacity, typename U, typename V> | 686 template<typename T, size_t inlineCapacity, typename U, typename V> |
687 inline void ListHashSet<T, inlineCapacity, U, V>::swap(ListHashSet& other) | 687 void ListHashSet<T, inlineCapacity, U, V>::swap(ListHashSet& other) |
688 { | 688 { |
689 m_impl.swap(other.m_impl); | 689 m_impl.swap(other.m_impl); |
690 std::swap(m_head, other.m_head); | 690 std::swap(m_head, other.m_head); |
691 std::swap(m_tail, other.m_tail); | 691 std::swap(m_tail, other.m_tail); |
692 this->m_allocatorProvider.swap(other.m_allocatorProvider); | 692 this->m_allocatorProvider.swap(other.m_allocatorProvider); |
693 } | 693 } |
694 | 694 |
695 template<typename T, size_t inlineCapacity, typename U, typename V> | 695 template<typename T, size_t inlineCapacity, typename U, typename V> |
696 inline void ListHashSet<T, inlineCapacity, U, V>::finalize() | 696 void ListHashSet<T, inlineCapacity, U, V>::finalize() |
697 { | 697 { |
698 COMPILE_ASSERT(!Allocator::isGarbageCollected, FinalizeOnHeapAllocatedLi
stHashSetShouldNeverBeCalled); | 698 COMPILE_ASSERT(!Allocator::isGarbageCollected, FinalizeOnHeapAllocatedLi
stHashSetShouldNeverBeCalled); |
699 deleteAllNodes(); | 699 deleteAllNodes(); |
700 } | 700 } |
701 | 701 |
702 template<typename T, size_t inlineCapacity, typename U, typename V> | 702 template<typename T, size_t inlineCapacity, typename U, typename V> |
703 inline T& ListHashSet<T, inlineCapacity, U, V>::first() | 703 T& ListHashSet<T, inlineCapacity, U, V>::first() |
704 { | 704 { |
705 ASSERT(!isEmpty()); | 705 ASSERT(!isEmpty()); |
706 return m_head->m_value; | 706 return m_head->m_value; |
707 } | 707 } |
708 | 708 |
709 template<typename T, size_t inlineCapacity, typename U, typename V> | 709 template<typename T, size_t inlineCapacity, typename U, typename V> |
710 inline void ListHashSet<T, inlineCapacity, U, V>::removeFirst() | 710 void ListHashSet<T, inlineCapacity, U, V>::removeFirst() |
711 { | 711 { |
712 ASSERT(!isEmpty()); | 712 ASSERT(!isEmpty()); |
713 m_impl.remove(m_head); | 713 m_impl.remove(m_head); |
714 unlinkAndDelete(m_head); | 714 unlinkAndDelete(m_head); |
715 } | 715 } |
716 | 716 |
717 template<typename T, size_t inlineCapacity, typename U, typename V> | 717 template<typename T, size_t inlineCapacity, typename U, typename V> |
718 inline const T& ListHashSet<T, inlineCapacity, U, V>::first() const | 718 const T& ListHashSet<T, inlineCapacity, U, V>::first() const |
719 { | 719 { |
720 ASSERT(!isEmpty()); | 720 ASSERT(!isEmpty()); |
721 return m_head->m_value; | 721 return m_head->m_value; |
722 } | 722 } |
723 | 723 |
724 template<typename T, size_t inlineCapacity, typename U, typename V> | 724 template<typename T, size_t inlineCapacity, typename U, typename V> |
725 inline T& ListHashSet<T, inlineCapacity, U, V>::last() | 725 T& ListHashSet<T, inlineCapacity, U, V>::last() |
726 { | 726 { |
727 ASSERT(!isEmpty()); | 727 ASSERT(!isEmpty()); |
728 return m_tail->m_value; | 728 return m_tail->m_value; |
729 } | 729 } |
730 | 730 |
731 template<typename T, size_t inlineCapacity, typename U, typename V> | 731 template<typename T, size_t inlineCapacity, typename U, typename V> |
732 inline const T& ListHashSet<T, inlineCapacity, U, V>::last() const | 732 const T& ListHashSet<T, inlineCapacity, U, V>::last() const |
733 { | 733 { |
734 ASSERT(!isEmpty()); | 734 ASSERT(!isEmpty()); |
735 return m_tail->m_value; | 735 return m_tail->m_value; |
736 } | 736 } |
737 | 737 |
738 template<typename T, size_t inlineCapacity, typename U, typename V> | 738 template<typename T, size_t inlineCapacity, typename U, typename V> |
739 inline void ListHashSet<T, inlineCapacity, U, V>::removeLast() | 739 void ListHashSet<T, inlineCapacity, U, V>::removeLast() |
740 { | 740 { |
741 ASSERT(!isEmpty()); | 741 ASSERT(!isEmpty()); |
742 m_impl.remove(m_tail); | 742 m_impl.remove(m_tail); |
743 unlinkAndDelete(m_tail); | 743 unlinkAndDelete(m_tail); |
744 } | 744 } |
745 | 745 |
746 template<typename T, size_t inlineCapacity, typename U, typename V> | 746 template<typename T, size_t inlineCapacity, typename U, typename V> |
747 inline typename ListHashSet<T, inlineCapacity, U, V>::iterator ListHashSet<T
, inlineCapacity, U, V>::find(ValuePeekInType value) | 747 typename ListHashSet<T, inlineCapacity, U, V>::iterator ListHashSet<T, inlin
eCapacity, U, V>::find(ValuePeekInType value) |
748 { | 748 { |
749 ImplTypeIterator it = m_impl.template find<BaseTranslator>(value); | 749 ImplTypeIterator it = m_impl.template find<BaseTranslator>(value); |
750 if (it == m_impl.end()) | 750 if (it == m_impl.end()) |
751 return end(); | 751 return end(); |
752 return makeIterator(*it); | 752 return makeIterator(*it); |
753 } | 753 } |
754 | 754 |
755 template<typename T, size_t inlineCapacity, typename U, typename V> | 755 template<typename T, size_t inlineCapacity, typename U, typename V> |
756 inline typename ListHashSet<T, inlineCapacity, U, V>::const_iterator ListHas
hSet<T, inlineCapacity, U, V>::find(ValuePeekInType value) const | 756 typename ListHashSet<T, inlineCapacity, U, V>::const_iterator ListHashSet<T,
inlineCapacity, U, V>::find(ValuePeekInType value) const |
757 { | 757 { |
758 ImplTypeConstIterator it = m_impl.template find<BaseTranslator>(value); | 758 ImplTypeConstIterator it = m_impl.template find<BaseTranslator>(value); |
759 if (it == m_impl.end()) | 759 if (it == m_impl.end()) |
760 return end(); | 760 return end(); |
761 return makeConstIterator(*it); | 761 return makeConstIterator(*it); |
762 } | 762 } |
763 | 763 |
764 template<typename Translator> | 764 template<typename Translator> |
765 struct ListHashSetTranslatorAdapter { | 765 struct ListHashSetTranslatorAdapter { |
766 template<typename T> static unsigned hash(const T& key) { return Transla
tor::hash(key); } | 766 template<typename T> static unsigned hash(const T& key) { return Transla
tor::hash(key); } |
767 template<typename T, typename U> static bool equal(const T& a, const U&
b) { return Translator::equal(a->m_value, b); } | 767 template<typename T, typename U> static bool equal(const T& a, const U&
b) { return Translator::equal(a->m_value, b); } |
768 }; | 768 }; |
769 | 769 |
770 template<typename ValueType, size_t inlineCapacity, typename U, typename V> | 770 template<typename ValueType, size_t inlineCapacity, typename U, typename V> |
771 template<typename HashTranslator, typename T> | 771 template<typename HashTranslator, typename T> |
772 inline typename ListHashSet<ValueType, inlineCapacity, U, V>::iterator ListH
ashSet<ValueType, inlineCapacity, U, V>::find(const T& value) | 772 typename ListHashSet<ValueType, inlineCapacity, U, V>::iterator ListHashSet<
ValueType, inlineCapacity, U, V>::find(const T& value) |
773 { | 773 { |
774 ImplTypeConstIterator it = m_impl.template find<ListHashSetTranslatorAda
pter<HashTranslator> >(value); | 774 ImplTypeConstIterator it = m_impl.template find<ListHashSetTranslatorAda
pter<HashTranslator> >(value); |
775 if (it == m_impl.end()) | 775 if (it == m_impl.end()) |
776 return end(); | 776 return end(); |
777 return makeIterator(*it); | 777 return makeIterator(*it); |
778 } | 778 } |
779 | 779 |
780 template<typename ValueType, size_t inlineCapacity, typename U, typename V> | 780 template<typename ValueType, size_t inlineCapacity, typename U, typename V> |
781 template<typename HashTranslator, typename T> | 781 template<typename HashTranslator, typename T> |
782 inline typename ListHashSet<ValueType, inlineCapacity, U, V>::const_iterator
ListHashSet<ValueType, inlineCapacity, U, V>::find(const T& value) const | 782 typename ListHashSet<ValueType, inlineCapacity, U, V>::const_iterator ListHa
shSet<ValueType, inlineCapacity, U, V>::find(const T& value) const |
783 { | 783 { |
784 ImplTypeConstIterator it = m_impl.template find<ListHashSetTranslatorAda
pter<HashTranslator> >(value); | 784 ImplTypeConstIterator it = m_impl.template find<ListHashSetTranslatorAda
pter<HashTranslator> >(value); |
785 if (it == m_impl.end()) | 785 if (it == m_impl.end()) |
786 return end(); | 786 return end(); |
787 return makeConstIterator(*it); | 787 return makeConstIterator(*it); |
788 } | 788 } |
789 | 789 |
790 template<typename ValueType, size_t inlineCapacity, typename U, typename V> | 790 template<typename ValueType, size_t inlineCapacity, typename U, typename V> |
791 template<typename HashTranslator, typename T> | 791 template<typename HashTranslator, typename T> |
792 inline bool ListHashSet<ValueType, inlineCapacity, U, V>::contains(const T&
value) const | 792 bool ListHashSet<ValueType, inlineCapacity, U, V>::contains(const T& value)
const |
793 { | 793 { |
794 return m_impl.template contains<ListHashSetTranslatorAdapter<HashTransla
tor> >(value); | 794 return m_impl.template contains<ListHashSetTranslatorAdapter<HashTransla
tor> >(value); |
795 } | 795 } |
796 | 796 |
797 template<typename T, size_t inlineCapacity, typename U, typename V> | 797 template<typename T, size_t inlineCapacity, typename U, typename V> |
798 inline bool ListHashSet<T, inlineCapacity, U, V>::contains(ValuePeekInType v
alue) const | 798 bool ListHashSet<T, inlineCapacity, U, V>::contains(ValuePeekInType value) c
onst |
799 { | 799 { |
800 return m_impl.template contains<BaseTranslator>(value); | 800 return m_impl.template contains<BaseTranslator>(value); |
801 } | 801 } |
802 | 802 |
803 template<typename T, size_t inlineCapacity, typename U, typename V> | 803 template<typename T, size_t inlineCapacity, typename U, typename V> |
804 typename ListHashSet<T, inlineCapacity, U, V>::AddResult ListHashSet<T, inli
neCapacity, U, V>::add(ValuePassInType value) | 804 typename ListHashSet<T, inlineCapacity, U, V>::AddResult ListHashSet<T, inli
neCapacity, U, V>::add(ValuePassInType value) |
805 { | 805 { |
806 createAllocatorIfNeeded(); | 806 createAllocatorIfNeeded(); |
807 // The second argument is a const ref. This is useful for the HashTable | 807 // The second argument is a const ref. This is useful for the HashTable |
808 // because it lets it take lvalues by reference, but for our purposes | 808 // because it lets it take lvalues by reference, but for our purposes |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 } | 855 } |
856 | 856 |
857 template<typename T, size_t inlineCapacity, typename U, typename V> | 857 template<typename T, size_t inlineCapacity, typename U, typename V> |
858 typename ListHashSet<T, inlineCapacity, U, V>::AddResult ListHashSet<T, inli
neCapacity, U, V>::insertBefore(ValuePeekInType beforeValue, ValuePassInType new
Value) | 858 typename ListHashSet<T, inlineCapacity, U, V>::AddResult ListHashSet<T, inli
neCapacity, U, V>::insertBefore(ValuePeekInType beforeValue, ValuePassInType new
Value) |
859 { | 859 { |
860 createAllocatorIfNeeded(); | 860 createAllocatorIfNeeded(); |
861 return insertBefore(find(beforeValue), newValue); | 861 return insertBefore(find(beforeValue), newValue); |
862 } | 862 } |
863 | 863 |
864 template<typename T, size_t inlineCapacity, typename U, typename V> | 864 template<typename T, size_t inlineCapacity, typename U, typename V> |
865 inline void ListHashSet<T, inlineCapacity, U, V>::remove(iterator it) | 865 void ListHashSet<T, inlineCapacity, U, V>::remove(iterator it) |
866 { | 866 { |
867 if (it == end()) | 867 if (it == end()) |
868 return; | 868 return; |
869 m_impl.remove(it.node()); | 869 m_impl.remove(it.node()); |
870 unlinkAndDelete(it.node()); | 870 unlinkAndDelete(it.node()); |
871 } | 871 } |
872 | 872 |
873 template<typename T, size_t inlineCapacity, typename U, typename V> | 873 template<typename T, size_t inlineCapacity, typename U, typename V> |
874 inline void ListHashSet<T, inlineCapacity, U, V>::clear() | 874 void ListHashSet<T, inlineCapacity, U, V>::clear() |
875 { | 875 { |
876 deleteAllNodes(); | 876 deleteAllNodes(); |
877 m_impl.clear(); | 877 m_impl.clear(); |
878 m_head = 0; | 878 m_head = 0; |
879 m_tail = 0; | 879 m_tail = 0; |
880 } | 880 } |
881 | 881 |
882 template<typename T, size_t inlineCapacity, typename U, typename V> | 882 template<typename T, size_t inlineCapacity, typename U, typename V> |
883 typename ListHashSet<T, inlineCapacity, U, V>::ValuePassOutType ListHashSet<
T, inlineCapacity, U, V>::take(iterator it) | 883 typename ListHashSet<T, inlineCapacity, U, V>::ValuePassOutType ListHashSet<
T, inlineCapacity, U, V>::take(iterator it) |
884 { | 884 { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 struct NeedsTracing<ListHashSet<T, U, V> > { | 1008 struct NeedsTracing<ListHashSet<T, U, V> > { |
1009 static const bool value = false; | 1009 static const bool value = false; |
1010 }; | 1010 }; |
1011 #endif | 1011 #endif |
1012 | 1012 |
1013 } // namespace WTF | 1013 } // namespace WTF |
1014 | 1014 |
1015 using WTF::ListHashSet; | 1015 using WTF::ListHashSet; |
1016 | 1016 |
1017 #endif /* WTF_ListHashSet_h */ | 1017 #endif /* WTF_ListHashSet_h */ |
OLD | NEW |