Other workarounds for the vec > 2**31 offsets bug?
My crude approach to extending the addressable bit range to 2**32-1 would be to divide the offset by 2 and operate in units of 2 bits. Something like this:
sub setbit {
# args: var, offset, value (0/1)
if ($_[1] % 2) { # odd offset
if ($_[2]) {
vec($_[0], $_[1]/2, 2) |= 0b10; # set
} else {
vec($_[0], $_[1]/2, 2) &= 1; # clear
}
} else { # even offset
if ($_[2]) {
vec($_[0], $_[1]/2, 2) |= 1; # set
} else {
vec($_[0], $_[1]/2, 2) &= 0b10; # clear
}
}
}
my $v = "";
setbit($v, 2**32-1, 1); # set bit
setbit($v, 2**32-1, 0); # clear bit
(and likewise for reading a bit)
The idea could in principle be extended to other unit sizes (4, 8, ...), though the bit fiddling would then be somewhat more involved.