| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_HYDROGEN_UNIQUE_H_ | 5 #ifndef V8_HYDROGEN_UNIQUE_H_ |
| 6 #define V8_HYDROGEN_UNIQUE_H_ | 6 #define V8_HYDROGEN_UNIQUE_H_ |
| 7 | 7 |
| 8 #include "handles.h" | 8 #include "handles.h" |
| 9 #include "objects.h" | 9 #include "objects.h" |
| 10 #include "utils.h" | 10 #include "utils.h" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 while (i < this->size_) out->array_[k++] = this->array_[i++]; | 271 while (i < this->size_) out->array_[k++] = this->array_[i++]; |
| 272 while (j < that->size_) out->array_[k++] = that->array_[j++]; | 272 while (j < that->size_) out->array_[k++] = that->array_[j++]; |
| 273 | 273 |
| 274 out->size_ = k; | 274 out->size_ = k; |
| 275 return out; | 275 return out; |
| 276 } | 276 } |
| 277 | 277 |
| 278 // Returns a new set representing all elements from this set which are not in | |
| 279 // that set. O(|this| * |that|). | |
| 280 UniqueSet<T>* Subtract(const UniqueSet<T>* that, Zone* zone) const { | |
| 281 if (that->size_ == 0) return this->Copy(zone); | |
| 282 | |
| 283 UniqueSet<T>* out = new(zone) UniqueSet<T>(this->size_, zone); | |
| 284 | |
| 285 int i = 0, j = 0; | |
| 286 while (i < this->size_) { | |
| 287 Unique<T> cand = this->array_[i]; | |
| 288 if (!that->Contains(cand)) { | |
| 289 out->array_[j++] = cand; | |
| 290 } | |
| 291 } | |
| 292 | |
| 293 out->size_ = j; | |
| 294 return out; | |
| 295 } | |
| 296 | |
| 297 // Makes an exact copy of this set. O(|this|). | 278 // Makes an exact copy of this set. O(|this|). |
| 298 UniqueSet<T>* Copy(Zone* zone) const { | 279 UniqueSet<T>* Copy(Zone* zone) const { |
| 299 UniqueSet<T>* copy = new(zone) UniqueSet<T>(this->size_, zone); | 280 UniqueSet<T>* copy = new(zone) UniqueSet<T>(this->size_, zone); |
| 300 copy->size_ = this->size_; | 281 copy->size_ = this->size_; |
| 301 memcpy(copy->array_, this->array_, this->size_ * sizeof(Unique<T>)); | 282 memcpy(copy->array_, this->array_, this->size_ * sizeof(Unique<T>)); |
| 302 return copy; | 283 return copy; |
| 303 } | 284 } |
| 304 | 285 |
| 305 void Clear() { | 286 void Clear() { |
| 306 size_ = 0; | 287 size_ = 0; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 337 capacity_ = new_capacity; | 318 capacity_ = new_capacity; |
| 338 array_ = new_array; | 319 array_ = new_array; |
| 339 } | 320 } |
| 340 } | 321 } |
| 341 }; | 322 }; |
| 342 | 323 |
| 343 | 324 |
| 344 } } // namespace v8::internal | 325 } } // namespace v8::internal |
| 345 | 326 |
| 346 #endif // V8_HYDROGEN_UNIQUE_H_ | 327 #endif // V8_HYDROGEN_UNIQUE_H_ |
| OLD | NEW |