mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Fix iteration of biased Bit_Array
This commit is contained in:
@@ -53,7 +53,7 @@ Returns:
|
|||||||
*/
|
*/
|
||||||
iterate_by_all :: proc (it: ^Bit_Array_Iterator) -> (set: bool, index: int, ok: bool) {
|
iterate_by_all :: proc (it: ^Bit_Array_Iterator) -> (set: bool, index: int, ok: bool) {
|
||||||
index = it.word_idx * NUM_BITS + int(it.bit_idx) + it.array.bias
|
index = it.word_idx * NUM_BITS + int(it.bit_idx) + it.array.bias
|
||||||
if index > it.array.max_index { return false, 0, false }
|
if index > it.array.max_index + it.array.bias { return false, 0, false }
|
||||||
|
|
||||||
word := it.array.bits[it.word_idx] if len(it.array.bits) > it.word_idx else 0
|
word := it.array.bits[it.word_idx] if len(it.array.bits) > it.word_idx else 0
|
||||||
set = (word >> it.bit_idx & 1) == 1
|
set = (word >> it.bit_idx & 1) == 1
|
||||||
@@ -136,7 +136,7 @@ iterate_internal_ :: proc (it: ^Bit_Array_Iterator, $ITERATE_SET_BITS: bool) ->
|
|||||||
it.bit_idx = 0
|
it.bit_idx = 0
|
||||||
it.word_idx += 1
|
it.word_idx += 1
|
||||||
}
|
}
|
||||||
return index, index <= it.array.max_index
|
return index, index <= it.array.max_index + it.array.bias
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
Gets the state of a bit in the bit-array
|
Gets the state of a bit in the bit-array
|
||||||
@@ -285,7 +285,7 @@ create :: proc(max_index: int, min_index: int = 0, allocator := context.allocato
|
|||||||
res = new(Bit_Array)
|
res = new(Bit_Array)
|
||||||
res.bits = bits
|
res.bits = bits
|
||||||
res.bias = min_index
|
res.bias = min_index
|
||||||
res.max_index = max_index
|
res.max_index = max_index - min_index
|
||||||
res.free_pointer = true
|
res.free_pointer = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user