| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium 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 #include "net/disk_cache/bitmap.h" | 5 #include "net/disk_cache/bitmap.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // Returns the index of the first bit set to |value| from |word|. This code | 29 // Returns the index of the first bit set to |value| from |word|. This code |
| 30 // assumes that we'll be able to find that bit. | 30 // assumes that we'll be able to find that bit. |
| 31 int FindLSBNonEmpty(uint32 word, bool value) { | 31 int FindLSBNonEmpty(uint32 word, bool value) { |
| 32 // If we are looking for 0, negate |word| and look for 1. | 32 // If we are looking for 0, negate |word| and look for 1. |
| 33 if (!value) | 33 if (!value) |
| 34 word = ~word; | 34 word = ~word; |
| 35 | 35 |
| 36 return FindLSBSetNonZero(word); | 36 return FindLSBSetNonZero(word); |
| 37 } | 37 } |
| 38 | 38 |
| 39 } | 39 } // namespace |
| 40 | 40 |
| 41 namespace disk_cache { | 41 namespace disk_cache { |
| 42 | 42 |
| 43 Bitmap::Bitmap(int num_bits, bool clear_bits) | 43 Bitmap::Bitmap(int num_bits, bool clear_bits) |
| 44 : num_bits_(num_bits), | 44 : num_bits_(num_bits), |
| 45 array_size_(RequiredArraySize(num_bits)), | 45 array_size_(RequiredArraySize(num_bits)), |
| 46 alloc_(true) { | 46 alloc_(true) { |
| 47 map_ = new uint32[array_size_]; | 47 map_ = new uint32[array_size_]; |
| 48 | 48 |
| 49 // Initialize all of the bits. | 49 // Initialize all of the bits. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 map_[j] |= (1 << i); | 98 map_[j] |= (1 << i); |
| 99 else | 99 else |
| 100 map_[j] &= ~(1 << i); | 100 map_[j] &= ~(1 << i); |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool Bitmap::Get(int index) const { | 103 bool Bitmap::Get(int index) const { |
| 104 DCHECK_LT(index, num_bits_); | 104 DCHECK_LT(index, num_bits_); |
| 105 DCHECK_GE(index, 0); | 105 DCHECK_GE(index, 0); |
| 106 const int i = index & (kIntBits-1); | 106 const int i = index & (kIntBits-1); |
| 107 const int j = index / kIntBits; | 107 const int j = index / kIntBits; |
| 108 return map_[j] & (1 << i) ? true : false; | 108 return ((map_[j] & (1 << i)) != 0); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void Bitmap::Toggle(int index) { | 111 void Bitmap::Toggle(int index) { |
| 112 DCHECK_LT(index, num_bits_); | 112 DCHECK_LT(index, num_bits_); |
| 113 DCHECK_GE(index, 0); | 113 DCHECK_GE(index, 0); |
| 114 const int i = index & (kIntBits - 1); | 114 const int i = index & (kIntBits - 1); |
| 115 const int j = index / kIntBits; | 115 const int j = index / kIntBits; |
| 116 map_[j] ^= (1 << i); | 116 map_[j] ^= (1 << i); |
| 117 } | 117 } |
| 118 | 118 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 uint32 to_add = 0xffffffff << len; | 302 uint32 to_add = 0xffffffff << len; |
| 303 to_add = (~to_add) << offset; | 303 to_add = (~to_add) << offset; |
| 304 if (value) { | 304 if (value) { |
| 305 map_[word] |= to_add; | 305 map_[word] |= to_add; |
| 306 } else { | 306 } else { |
| 307 map_[word] &= ~to_add; | 307 map_[word] &= ~to_add; |
| 308 } | 308 } |
| 309 } | 309 } |
| 310 | 310 |
| 311 } // namespace disk_cache | 311 } // namespace disk_cache |
| OLD | NEW |