| OLD | NEW |
| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 iterator end() const; | 61 iterator end() const; |
| 62 | 62 |
| 63 iterator find(const ValueType&) const; | 63 iterator find(const ValueType&) const; |
| 64 bool contains(const ValueType&) const; | 64 bool contains(const ValueType&) const; |
| 65 | 65 |
| 66 // An alternate version of find() that finds the object by hashing and c
omparing | 66 // An alternate version of find() that finds the object by hashing and c
omparing |
| 67 // with some other type, to avoid the cost of type conversion. HashTrans
lator | 67 // with some other type, to avoid the cost of type conversion. HashTrans
lator |
| 68 // must have the following function members: | 68 // must have the following function members: |
| 69 // static unsigned hash(const T&); | 69 // static unsigned hash(const T&); |
| 70 // static bool equal(const ValueType&, const T&); | 70 // static bool equal(const ValueType&, const T&); |
| 71 // FIXME: We should reverse the order of the template arguments so that
callers | 71 template<typename HashTranslator, typename T> iterator find(const T&) co
nst; |
| 72 // can just pass the translator and let the compiler deduce T. | 72 template<typename HashTranslator, typename T> bool contains(const T&) co
nst; |
| 73 template<typename T, typename HashTranslator> iterator find(const T&) co
nst; | |
| 74 template<typename T, typename HashTranslator> bool contains(const T&) co
nst; | |
| 75 | 73 |
| 76 // The return value is a pair of an interator to the new value's locatio
n, | 74 // The return value is a pair of an interator to the new value's locatio
n, |
| 77 // and a bool that is true if an new entry was added. | 75 // and a bool that is true if an new entry was added. |
| 78 AddResult add(const ValueType&); | 76 AddResult add(const ValueType&); |
| 79 | 77 |
| 80 // An alternate version of add() that finds the object by hashing and co
mparing | 78 // An alternate version of add() that finds the object by hashing and co
mparing |
| 81 // with some other type, to avoid the cost of type conversion if the obj
ect is already | 79 // with some other type, to avoid the cost of type conversion if the obj
ect is already |
| 82 // in the table. HashTranslator must have the following function members
: | 80 // in the table. HashTranslator must have the following function members
: |
| 83 // static unsigned hash(const T&); | 81 // static unsigned hash(const T&); |
| 84 // static bool equal(const ValueType&, const T&); | 82 // static bool equal(const ValueType&, const T&); |
| 85 // static translate(ValueType&, const T&, unsigned hashCode); | 83 // static translate(ValueType&, const T&, unsigned hashCode); |
| 86 // FIXME: We should reverse the order of the template arguments so that
callers | 84 template<typename HashTranslator, typename T> AddResult add(const T&); |
| 87 // can just pass the translator and let the compiler deduce T. | |
| 88 template<typename T, typename HashTranslator> AddResult add(const T&); | |
| 89 | 85 |
| 90 void remove(const ValueType&); | 86 void remove(const ValueType&); |
| 91 void remove(iterator); | 87 void remove(iterator); |
| 92 void clear(); | 88 void clear(); |
| 93 | 89 |
| 94 static bool isValidValue(const ValueType&); | 90 static bool isValidValue(const ValueType&); |
| 95 | 91 |
| 96 private: | 92 private: |
| 97 friend void deleteAllValues<>(const HashSet&); | 93 friend void deleteAllValues<>(const HashSet&); |
| 98 | 94 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 return m_impl.find(value); | 151 return m_impl.find(value); |
| 156 } | 152 } |
| 157 | 153 |
| 158 template<typename T, typename U, typename V> | 154 template<typename T, typename U, typename V> |
| 159 inline bool HashSet<T, U, V>::contains(const ValueType& value) const | 155 inline bool HashSet<T, U, V>::contains(const ValueType& value) const |
| 160 { | 156 { |
| 161 return m_impl.contains(value); | 157 return m_impl.contains(value); |
| 162 } | 158 } |
| 163 | 159 |
| 164 template<typename Value, typename HashFunctions, typename Traits> | 160 template<typename Value, typename HashFunctions, typename Traits> |
| 165 template<typename T, typename HashTranslator> | 161 template<typename HashTranslator, typename T> |
| 166 typename HashSet<Value, HashFunctions, Traits>::iterator | 162 typename HashSet<Value, HashFunctions, Traits>::iterator |
| 167 inline HashSet<Value, HashFunctions, Traits>::find(const T& value) const | 163 inline HashSet<Value, HashFunctions, Traits>::find(const T& value) const |
| 168 { | 164 { |
| 169 return m_impl.template find<HashSetTranslatorAdapter<HashTranslator> >(v
alue); | 165 return m_impl.template find<HashSetTranslatorAdapter<HashTranslator> >(v
alue); |
| 170 } | 166 } |
| 171 | 167 |
| 172 template<typename Value, typename HashFunctions, typename Traits> | 168 template<typename Value, typename HashFunctions, typename Traits> |
| 173 template<typename T, typename HashTranslator> | 169 template<typename HashTranslator, typename T> |
| 174 inline bool HashSet<Value, HashFunctions, Traits>::contains(const T& value)
const | 170 inline bool HashSet<Value, HashFunctions, Traits>::contains(const T& value)
const |
| 175 { | 171 { |
| 176 return m_impl.template contains<HashSetTranslatorAdapter<HashTranslator>
>(value); | 172 return m_impl.template contains<HashSetTranslatorAdapter<HashTranslator>
>(value); |
| 177 } | 173 } |
| 178 | 174 |
| 179 template<typename T, typename U, typename V> | 175 template<typename T, typename U, typename V> |
| 180 inline typename HashSet<T, U, V>::AddResult HashSet<T, U, V>::add(const Valu
eType& value) | 176 inline typename HashSet<T, U, V>::AddResult HashSet<T, U, V>::add(const Valu
eType& value) |
| 181 { | 177 { |
| 182 return m_impl.add(value); | 178 return m_impl.add(value); |
| 183 } | 179 } |
| 184 | 180 |
| 185 template<typename Value, typename HashFunctions, typename Traits> | 181 template<typename Value, typename HashFunctions, typename Traits> |
| 186 template<typename T, typename HashTranslator> | 182 template<typename HashTranslator, typename T> |
| 187 inline typename HashSet<Value, HashFunctions, Traits>::AddResult | 183 inline typename HashSet<Value, HashFunctions, Traits>::AddResult |
| 188 HashSet<Value, HashFunctions, Traits>::add(const T& value) | 184 HashSet<Value, HashFunctions, Traits>::add(const T& value) |
| 189 { | 185 { |
| 190 return m_impl.template addPassingHashCode<HashSetTranslatorAdapter<HashT
ranslator> >(value, value); | 186 return m_impl.template addPassingHashCode<HashSetTranslatorAdapter<HashT
ranslator> >(value, value); |
| 191 } | 187 } |
| 192 | 188 |
| 193 template<typename T, typename U, typename V> | 189 template<typename T, typename U, typename V> |
| 194 inline void HashSet<T, U, V>::remove(iterator it) | 190 inline void HashSet<T, U, V>::remove(iterator it) |
| 195 { | 191 { |
| 196 if (it.m_impl == m_impl.end()) | 192 if (it.m_impl == m_impl.end()) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 iterator end = collection.end(); | 250 iterator end = collection.end(); |
| 255 for (unsigned i = 0; it != end; ++it, ++i) | 251 for (unsigned i = 0; it != end; ++it, ++i) |
| 256 vector[i] = *it; | 252 vector[i] = *it; |
| 257 } | 253 } |
| 258 | 254 |
| 259 } // namespace WTF | 255 } // namespace WTF |
| 260 | 256 |
| 261 using WTF::HashSet; | 257 using WTF::HashSet; |
| 262 | 258 |
| 263 #endif /* WTF_HashSet_h */ | 259 #endif /* WTF_HashSet_h */ |
| OLD | NEW |