| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 for (int i = 0; i < size_; i++) { | 182 for (int i = 0; i < size_; i++) { |
| 183 if (array_[i] == uniq) { | 183 if (array_[i] == uniq) { |
| 184 while (++i < size_) array_[i - 1] = array_[i]; | 184 while (++i < size_) array_[i - 1] = array_[i]; |
| 185 size_--; | 185 size_--; |
| 186 return; | 186 return; |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 // Compare this set against another set. O(|this|). | 191 // Compare this set against another set. O(|this|). |
| 192 bool Equals(UniqueSet<T>* that) const { | 192 bool Equals(const UniqueSet<T>* that) const { |
| 193 if (that->size_ != this->size_) return false; | 193 if (that->size_ != this->size_) return false; |
| 194 for (int i = 0; i < this->size_; i++) { | 194 for (int i = 0; i < this->size_; i++) { |
| 195 if (this->array_[i] != that->array_[i]) return false; | 195 if (this->array_[i] != that->array_[i]) return false; |
| 196 } | 196 } |
| 197 return true; | 197 return true; |
| 198 } | 198 } |
| 199 | 199 |
| 200 // Check whether this set contains the given element. O(|this|) | 200 // Check whether this set contains the given element. O(|this|) |
| 201 // TODO(titzer): use binary search for large sets to make this O(log|this|) | 201 // TODO(titzer): use binary search for large sets to make this O(log|this|) |
| 202 template <typename U> | 202 template <typename U> |
| 203 bool Contains(Unique<U> elem) const { | 203 bool Contains(const Unique<U> elem) const { |
| 204 for (int i = 0; i < size_; i++) { | 204 for (int i = 0; i < size_; i++) { |
| 205 if (this->array_[i] == elem) return true; | 205 if (this->array_[i] == elem) return true; |
| 206 } | 206 } |
| 207 return false; | 207 return false; |
| 208 } | 208 } |
| 209 | 209 |
| 210 // Check if this set is a subset of the given set. O(|this| + |that|). | 210 // Check if this set is a subset of the given set. O(|this| + |that|). |
| 211 bool IsSubset(UniqueSet<T>* that) const { | 211 bool IsSubset(const UniqueSet<T>* that) const { |
| 212 if (that->size_ < this->size_) return false; | 212 if (that->size_ < this->size_) return false; |
| 213 int j = 0; | 213 int j = 0; |
| 214 for (int i = 0; i < this->size_; i++) { | 214 for (int i = 0; i < this->size_; i++) { |
| 215 Unique<T> sought = this->array_[i]; | 215 Unique<T> sought = this->array_[i]; |
| 216 while (true) { | 216 while (true) { |
| 217 if (sought == that->array_[j++]) break; | 217 if (sought == that->array_[j++]) break; |
| 218 // Fail whenever there are more elements in {this} than {that}. | 218 // Fail whenever there are more elements in {this} than {that}. |
| 219 if ((this->size_ - i) > (that->size_ - j)) return false; | 219 if ((this->size_ - i) > (that->size_ - j)) return false; |
| 220 } | 220 } |
| 221 } | 221 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 capacity_ = new_capacity; | 327 capacity_ = new_capacity; |
| 328 array_ = new_array; | 328 array_ = new_array; |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 }; | 331 }; |
| 332 | 332 |
| 333 | 333 |
| 334 } } // namespace v8::internal | 334 } } // namespace v8::internal |
| 335 | 335 |
| 336 #endif // V8_HYDROGEN_UNIQUE_H_ | 336 #endif // V8_HYDROGEN_UNIQUE_H_ |
| OLD | NEW |