Efficiently insert a range of values. When N is small, this is * essentially an O(1) algorithm, although technically it is O(N) */
| 197 | * essentially an O(1) algorithm, although technically it is O(N) |
| 198 | */ |
| 199 | void insert_range(const KeyT start, int length) { |
| 200 | unsigned start_word = int(start) / bits_per_uint64_t; |
| 201 | // This is not an off-by-one error. Conventionally this would have length |
| 202 | // - 1, but the logic below is simpler with it as follows. |
| 203 | unsigned end_word = (int(start) + length) / bits_per_uint64_t; |
| 204 | ceph_assert(end_word < word_count + 1); |
| 205 | |
| 206 | if (start_word == end_word) { |
| 207 | words[start_word] |= |
| 208 | ((1ULL << length) - 1) << (int(start) % bits_per_uint64_t); |
| 209 | } else { |
| 210 | words[start_word] |= -1ULL << (int(start) % bits_per_uint64_t); |
| 211 | while (++start_word < end_word) { |
| 212 | words[start_word] = -1ULL; |
| 213 | } |
| 214 | if (end_word < word_count) { |
| 215 | words[end_word] |= |
| 216 | (1ULL << ((int(start) + length) % bits_per_uint64_t)) - 1; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /** Efficiently erase a range of values. When N is small, this is |
| 222 | * essentially an O(1) algorithm, although technically it is O(N) |
no outgoing calls