Re: flags in a bitmap

"Ruud H.G. van Tol" <[email protected]>
Newsgroups gmane.comp.mathematics.pari.user
Message-ID <[email protected]>
On 2025-07-04 10:06, Bill Allombert wrote:
 > On Thu, Jul 03, 2025 at 06:06:14PM +0200, Ruud H.G. van Tol wrote:

 >> Bill, many thanks for the pointers, I'll explore.
 >>
 >> As an alternative, maybe add a Vecbits() or Vecflags() or such.
 >> No idea if the first bit should have offset 0 or 1.
 >> Only with bittest(), maybe 0?
 >>
 >> my(B=Vecbits([0], 987654321));
 >> Vecbits_put(~B, 7654, v=1);  \\set the bit at offset 7654, by 
default to 1
 >> Vecbits_put(~B, 7654, [1,0,0,1,1]); \\set bits 7654..7658 to [1,0,0,1,1]
 >> my(b=Vecbits_get(B,7654)); \\get bit-7654
 >> my(b=bittest(B,7653)); \\...

 > What I can do is to allow to set/clean a bit in place inside an integer.
 > However this would only work if the integer is large enough.
 >
 > I can do a git branch if you want to test:
 >
 > ? install(bitset,vWL)
 > ? x=2^(2^20);
 > ? forprime(p=2,2^20,bitset(~x,p))
 >   ***   last result computed in 8 ms.
 > ? my(S=0);for(i=0,2^20-1,S+=bittest(x,i));S
 > %16 = 82025
 >   ***   last result computed in 159 ms.

That indeed looks good, and I can test it.

The word "set" is overloaded! :)
(that is why I used "put" in my suggestions)

-- Ruud
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.