Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_BIT_VECTOR_H_ | 5 #ifndef VM_BIT_VECTOR_H_ |
| 6 #define VM_BIT_VECTOR_H_ | 6 #define VM_BIT_VECTOR_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 10 #include "vm/zone.h" | 10 #include "vm/zone.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 | 56 |
| 57 static intptr_t SizeFor(intptr_t length) { | 57 static intptr_t SizeFor(intptr_t length) { |
| 58 return 1 + ((length - 1) / kBitsPerWord); | 58 return 1 + ((length - 1) / kBitsPerWord); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void Add(intptr_t i) { | 61 void Add(intptr_t i) { |
| 62 ASSERT(i >= 0 && i < length()); | 62 ASSERT(i >= 0 && i < length()); |
| 63 data_[i / kBitsPerWord] |= (static_cast<uword>(1) << (i % kBitsPerWord)); | 63 data_[i / kBitsPerWord] |= (static_cast<uword>(1) << (i % kBitsPerWord)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool Contains(int i) const { | |
| 67 ASSERT(i >= 0 && i < length()); | |
| 68 uword block = data_[i / sizeof(uword)]; | |
| 69 return (block & (1U << (i % sizeof(uword)))) != 0; | |
|
srdjan
2012/06/12 17:34:37
Please add a test
Florian Schneider
2012/06/13 10:53:40
Done. Good point. I fixed a bug here as well.
| |
| 70 } | |
| 71 | |
| 66 void Clear() { | 72 void Clear() { |
| 67 for (intptr_t i = 0; i < data_length_; i++) { | 73 for (intptr_t i = 0; i < data_length_; i++) { |
| 68 data_[i] = 0; | 74 data_[i] = 0; |
| 69 } | 75 } |
| 70 } | 76 } |
| 71 | 77 |
| 72 intptr_t length() const { return length_; } | 78 intptr_t length() const { return length_; } |
| 73 | 79 |
| 74 private: | 80 private: |
| 75 intptr_t length_; | 81 intptr_t length_; |
| 76 intptr_t data_length_; | 82 intptr_t data_length_; |
| 77 uword* data_; | 83 uword* data_; |
| 78 | 84 |
| 79 DISALLOW_COPY_AND_ASSIGN(BitVector); | 85 DISALLOW_COPY_AND_ASSIGN(BitVector); |
| 80 }; | 86 }; |
| 81 | 87 |
| 82 } // namespace dart | 88 } // namespace dart |
| 83 | 89 |
| 84 #endif // VM_BIT_VECTOR_H_ | 90 #endif // VM_BIT_VECTOR_H_ |
| OLD | NEW |