OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // Clears the whole set. | 80 // Clears the whole set. |
81 void clear() { m_impl.clear(); } | 81 void clear() { m_impl.clear(); } |
82 | 82 |
83 void trace(typename Allocator::Visitor* visitor) { m_impl.trace(visitor)
; } | 83 void trace(typename Allocator::Visitor* visitor) { m_impl.trace(visitor)
; } |
84 | 84 |
85 private: | 85 private: |
86 ImplType m_impl; | 86 ImplType m_impl; |
87 }; | 87 }; |
88 | 88 |
89 template<typename T, typename U, typename V, typename W> | 89 template<typename T, typename U, typename V, typename W> |
90 inline typename HashCountedSet<T, U, V, W>::AddResult HashCountedSet<T, U, V
, W>::add(const ValueType& value) | 90 typename HashCountedSet<T, U, V, W>::AddResult HashCountedSet<T, U, V, W>::a
dd(const ValueType& value) |
91 { | 91 { |
92 AddResult result = m_impl.add(value, 0); | 92 AddResult result = m_impl.add(value, 0); |
93 ++result.storedValue->value; | 93 ++result.storedValue->value; |
94 return result; | 94 return result; |
95 } | 95 } |
96 | 96 |
97 template<typename T, typename U, typename V, typename W> | 97 template<typename T, typename U, typename V, typename W> |
98 inline bool HashCountedSet<T, U, V, W>::remove(iterator it) | 98 bool HashCountedSet<T, U, V, W>::remove(iterator it) |
99 { | 99 { |
100 if (it == end()) | 100 if (it == end()) |
101 return false; | 101 return false; |
102 | 102 |
103 unsigned oldVal = it->value; | 103 unsigned oldVal = it->value; |
104 ASSERT(oldVal); | 104 ASSERT(oldVal); |
105 unsigned newVal = oldVal - 1; | 105 unsigned newVal = oldVal - 1; |
106 if (newVal) { | 106 if (newVal) { |
107 it->value = newVal; | 107 it->value = newVal; |
108 return false; | 108 return false; |
109 } | 109 } |
110 | 110 |
111 m_impl.remove(it); | 111 m_impl.remove(it); |
112 return true; | 112 return true; |
113 } | 113 } |
114 | 114 |
115 template<typename T, typename U, typename V, typename W> | 115 template<typename T, typename U, typename V, typename W> |
116 inline void HashCountedSet<T, U, V, W>::removeAll(iterator it) | 116 void HashCountedSet<T, U, V, W>::removeAll(iterator it) |
117 { | 117 { |
118 if (it == end()) | 118 if (it == end()) |
119 return; | 119 return; |
120 | 120 |
121 m_impl.remove(it); | 121 m_impl.remove(it); |
122 } | 122 } |
123 | 123 |
124 template<typename T, typename U, typename V, typename W, typename VectorType
> | 124 template<typename T, typename U, typename V, typename W, typename VectorType
> |
125 inline void copyToVector(const HashCountedSet<T, U, V, W>& collection, Vecto
rType& vector) | 125 void copyToVector(const HashCountedSet<T, U, V, W>& collection, VectorType&
vector) |
126 { | 126 { |
127 typedef typename HashCountedSet<T, U, V, W>::const_iterator iterator; | 127 typedef typename HashCountedSet<T, U, V, W>::const_iterator iterator; |
128 | 128 |
129 vector.resize(collection.size()); | 129 vector.resize(collection.size()); |
130 | 130 |
131 iterator it = collection.begin(); | 131 iterator it = collection.begin(); |
132 iterator end = collection.end(); | 132 iterator end = collection.end(); |
133 for (unsigned i = 0; it != end; ++it, ++i) | 133 for (unsigned i = 0; it != end; ++it, ++i) |
134 vector[i] = *it; | 134 vector[i] = *it; |
135 } | 135 } |
136 | 136 |
137 template<typename Value, typename HashFunctions, typename Traits, typename A
llocator, size_t inlineCapacity, typename VectorAllocator> | 137 template<typename Value, typename HashFunctions, typename Traits, typename A
llocator, size_t inlineCapacity, typename VectorAllocator> |
138 inline void copyToVector(const HashCountedSet<Value, HashFunctions, Traits,
Allocator>& collection, Vector<Value, inlineCapacity, VectorAllocator>& vector) | 138 void copyToVector(const HashCountedSet<Value, HashFunctions, Traits, Allocat
or>& collection, Vector<Value, inlineCapacity, VectorAllocator>& vector) |
139 { | 139 { |
140 typedef typename HashCountedSet<Value, HashFunctions, Traits, Allocator>
::const_iterator iterator; | 140 typedef typename HashCountedSet<Value, HashFunctions, Traits, Allocator>
::const_iterator iterator; |
141 | 141 |
142 vector.resize(collection.size()); | 142 vector.resize(collection.size()); |
143 | 143 |
144 iterator it = collection.begin(); | 144 iterator it = collection.begin(); |
145 iterator end = collection.end(); | 145 iterator end = collection.end(); |
146 for (unsigned i = 0; it != end; ++it, ++i) | 146 for (unsigned i = 0; it != end; ++it, ++i) |
147 vector[i] = (*it).key; | 147 vector[i] = (*it).key; |
148 } | 148 } |
149 | 149 |
150 #if !ENABLE(OILPAN) | 150 #if !ENABLE(OILPAN) |
151 template<typename T, typename U, typename V> | 151 template<typename T, typename U, typename V> |
152 struct NeedsTracing<HashCountedSet<T, U, V> > { | 152 struct NeedsTracing<HashCountedSet<T, U, V> > { |
153 static const bool value = false; | 153 static const bool value = false; |
154 }; | 154 }; |
155 #endif | 155 #endif |
156 | 156 |
157 } // namespace WTF | 157 } // namespace WTF |
158 | 158 |
159 using WTF::HashCountedSet; | 159 using WTF::HashCountedSet; |
160 | 160 |
161 #endif /* WTF_HashCountedSet_h */ | 161 #endif /* WTF_HashCountedSet_h */ |
OLD | NEW |