add a pushFront operation for the bitranges
This commit is contained in:
parent
1391b9595a
commit
ba631f7f5d
|
@ -174,6 +174,12 @@ proc setAbsoluteBit(x: BitRange, absIdx: int, val: bool) {.inline.} =
|
|||
if val:
|
||||
raiseBitBE x.data[byteToWrite], bitToWrite
|
||||
|
||||
proc pushFront*(x: var BitRange, val: bool) =
|
||||
assert x.start > 0
|
||||
dec x.start
|
||||
x[0] = val
|
||||
inc x.mLen
|
||||
|
||||
template neededBytes(nBits: int): int =
|
||||
(nBits shr 3) + ord((nBits and 0b111) != 0)
|
||||
|
||||
|
|
|
@ -68,3 +68,16 @@ suite "bir ranges":
|
|||
for idx, bit in x:
|
||||
y[idx] = bit
|
||||
check x == y
|
||||
|
||||
test "constructor with start":
|
||||
var a = @[byte 0b10101010, 0b11110000, 0b00001111, 0b01010101]
|
||||
var b = a.bits(1, 8)
|
||||
check b.len == 8
|
||||
check b[0] == false
|
||||
check $b == "01010101"
|
||||
b[0] = true
|
||||
check $b == "11010101"
|
||||
check b[0] == true
|
||||
b.pushFront(false)
|
||||
check b[0] == false
|
||||
check $b == "011010101"
|
||||
|
|
Loading…
Reference in New Issue