Page 2 of 2
Re: BitModule
Posted: Sat Mar 22, 2014 12:09 am
by said
Thanks idle for sharing ... very nice and useful
Re: BitModule
Posted: Wed May 21, 2014 3:27 am
by idle
fixed a bug in the bittrie reallocation
Re: BitModule
Posted: Sun Jun 15, 2014 7:10 am
by said
Hi Idle
looks like something is wrong with BitArray (probably other structures as well haven't tested), try the below you will see that position 14 (or 15 if we start at 1) is being set not 9!
Code: Select all
Define ar.BitModule::IBitArray
ar = BitModule::New_BitArray(20)
ar\Set(9)
Define *q.ascii, *p = ar\GetBuffer()
Define i,txt.s
For i=0 To MemorySize(*p)
*q = *p + i
txt + RSet( Bin(*q\a), 8, "0") + ">"
Next
Debug txt
output
Re: BitModule
Posted: Sun Jun 15, 2014 2:05 pm
by Demivec
said wrote:looks like something is wrong with BitArray (probably other structures as well haven't tested), try the below you will see that position 14 (or 15 if we start at 1) is being set not 9!
You're examining the buffer directly and not in the manner that the BitArray does.
If you use the BitArray's interface instead:
Code: Select all
Define ar.BitModule::IBitArray
ar = BitModule::New_BitArray(20)
ar\Set(9)
Define i,txt.s
For i=0 To ar\BitSize()
txt + Str(Bool(ar\get(i) = 1))
If i % 8 = 0 And i > 0
txt + ">"
EndIf
Next
Debug txt
The output produced looks like:
Everything looks as it should.
Re: BitModule
Posted: Sun Jun 15, 2014 3:23 pm
by said
Thanks Demivec for clarifying, now i looked in detail on what's going on and i see that each byte is being processed separately. You are right, yes it is working fine but honestly I was not expecting this ... (should never use blindly anything

)
I was planning to use this to store blocks in files that could be read by other applications, this somehow put restrictions on the usage of this great module

Re: BitModule
Posted: Sun Jun 15, 2014 10:17 pm
by idle
Hi Said, it's easy enough fix I think
if you change the set and get parts after the "<<" to (7-(index & $07)
I've updated the module with the changes, seems to be ok
Re: BitModule
Posted: Mon Jun 16, 2014 3:11 am
by said
Thanks Idle for updating the module (actually i had already changed it here to suit my needs, exactly as you are suggesting). It is your module and you know all the details, modifications coming from you are the most welcome ones
Thanks again for sharing this very useful work

Re: BitModule
Posted: Thu Feb 26, 2015 12:53 am
by Justin
What is Toggle suposed to do? I thought would invert the bit value, but does nothing.
Code: Select all
EnableExplicit
Define ba.BitModule::IBitArray
ba = BitModule::New_BitArray(4)
ba\Set(2)
Debug ba\Get(2)
ba\Toggle(2)
Debug ba\Get(2)
Re: BitModule
Posted: Thu Feb 26, 2015 8:45 pm
by idle
it's a bug left over from reversing the order, replace it with
Code: Select all
Procedure BitArray_Toggle(*this.bitbuffer,index)
Protected *ta.Ascii
If ((index) >> 3) >= *this\inf\size
*this\inf\size = index + 64
*this\inf\BytesUsed = *this\inf\size
*this\buf = ReAllocateMemory(*this\buf,*this\inf\size)
EndIf
If *this\buf
*ta = *this\buf + ((index)>>3)
*ta\a ! (1 << (7-(index & $07)))
EndIf
EndProcedure
Re: BitModule
Posted: Fri Apr 01, 2016 6:58 am
by idle
v 1.3.8
Updated to pb 5.42 lts
exported hash functions
removed crc32
added asm popcount x86/x64 and SSE 4.2 for bitcount
added shift left / right (nicked from wilbert)
Re: BitModule
Posted: Fri Apr 01, 2016 8:04 am
by davido
@
idle,
Very useful, thank you.
