Re: [fpc-devel] tbits.NotBits
On Thu, 13 Apr 2017 11:28:20 +0200 Andrea Mauriwrote: >[...] > procedure TBits.Setall; > var > loop : longint; > begin > for loop := 0 to FSize - 1 do >FBits^[loop] := 1; Should be FBits^[loop] := not cardinal(0); > end; Btw, it seems TBits misses an AssignBits(b: TBits). And maybe an AssignNotBits(b: TBits) > 2. a Not operator, something like a.NotBits; with no arguments that > perform the not operation on the TBIts instance (a[i]:= not a[i]) or > something that performs a not operation on the passed TBits, i.e. > a.Not(b) that fills a in this way: a[i]:= not b[i]; > > procedure TBits.Notbits; > var > n : longint; > jj : cardinal; > loop : longint; > begin > for loop := 0 to FSize - 1 do >FBits^[loop] := not FBits^[loop]; > end; > > or > > procedure TBits.Not(bitset : TBits); "Not" is a preserved word. > var > n : longint; > loop : longint; > begin > if FSize < bitset.getFSize then >n := FSize - 1 > else >n := bitset.getFSize - 1; > > for loop := 0 to n do >FBits^[loop] := not bitset.FBits^[loop]; > end; For consistency with the other SomethingBits methods you must handle all bits, not just the start. Mattias ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] tbits.NotBits
AFAIK a.NotBits(b) means (a and not b): a b result 0 0 0 0 1 0 1 0 1 1 1 0 Mattias Thank you Mattias. It works as you described. Anyway, since ClearAll, AndBits, OrBits etc works iterating on FBits : ^TBitArray; they are much faster then the simple iteration along property property Bits[Bit: longint]: Boolean read get write SetBit; default; I think should be useful to have also at least two other methods directly implemented in tbits: 1. the opposite of ClearAll, something like SetAll that sets all bits to 1, I think this s a typical operation on Bits; procedure TBits.Setall; var loop : longint; begin for loop := 0 to FSize - 1 do FBits^[loop] := 1; end; 2. a Not operator, something like a.NotBits; with no arguments that perform the not operation on the TBIts instance (a[i]:= not a[i]) or something that performs a not operation on the passed TBits, i.e. a.Not(b) that fills a in this way: a[i]:= not b[i]; procedure TBits.Notbits; var n : longint; jj : cardinal; loop : longint; begin for loop := 0 to FSize - 1 do FBits^[loop] := not FBits^[loop]; end; or procedure TBits.Not(bitset : TBits); var n : longint; loop : longint; begin if FSize < bitset.getFSize then n := FSize - 1 else n := bitset.getFSize - 1; for loop := 0 to n do FBits^[loop] := not bitset.FBits^[loop]; end; ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] tbits.NotBits
On Thu, 13 Apr 2017 10:52:44 +0200 (CEST) Michael Van Canneytwrote: >[...] > I am not sure that what you did is supported. > > b.notbits(b) > > I am not sure that you can pass the same instance to b. Just look at the code. It's only a few lines. It is supported. Mattias ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] tbits.NotBits
On Thu, 13 Apr 2017, Andrea Mauri wrote: any answer? I asked in the wrong place? where should I ask? You asked in the right place. I just didn't notice your first mail. I am not sure that what you did is supported. b.notbits(b) I am not sure that you can pass the same instance to b. Can you test with 2 separate instances ? Michael. Il 31/03/2017 14:10, Andrea Mauri ha scritto: one more thing. there is a method like clearall to set all bits to 1? clearall is much more faster then a simple iteration along all bits Il 31/03/2017 14:07, Andrea Mauri ha scritto: I didn't understand how TBits.NotBits works. Consider the following code: b:= TBits.Create(NRECORDS); b.NotBits(b); or more clear: b:= TBits.Create(NRECORDS); b.Clearall; b.NotBits(b); I supposed that all bits of b will be 1. What I obtain is that all bits are 0. fpc 3.0.0 win64 Am I missing something? Thank you. Andrea Mauri ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] tbits.NotBits
On Fri, 31 Mar 2017 14:07:09 +0200 Andrea Mauriwrote: > I didn't understand how TBits.NotBits works. AFAIK a.NotBits(b) means (a and not b): a b result 0 0 0 0 1 0 1 0 1 1 1 0 Mattias ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] tbits.NotBits
any answer? I asked in the wrong place? where should I ask? Il 31/03/2017 14:10, Andrea Mauri ha scritto: one more thing. there is a method like clearall to set all bits to 1? clearall is much more faster then a simple iteration along all bits Il 31/03/2017 14:07, Andrea Mauri ha scritto: I didn't understand how TBits.NotBits works. Consider the following code: b:= TBits.Create(NRECORDS); b.NotBits(b); or more clear: b:= TBits.Create(NRECORDS); b.Clearall; b.NotBits(b); I supposed that all bits of b will be 1. What I obtain is that all bits are 0. fpc 3.0.0 win64 Am I missing something? Thank you. Andrea Mauri ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] tbits.NotBits
one last thing, using TBits it is possible to SetIndex in order to start from a predefined index when using FindNextBit and FindPrevBit Anyway it is possible to set the State only using FindFirstBit, so I cannot use FindNextBit only using SetIndex but I have to call also FindFirstBit. Is it possible to introduce a SetState procedure? Thanks again, Andrea Mauri Il 31/03/2017 14:10, Andrea Mauri ha scritto: one more thing. there is a method like clearall to set all bits to 1? clearall is much more faster then a simple iteration along all bits Il 31/03/2017 14:07, Andrea Mauri ha scritto: I didn't understand how TBits.NotBits works. Consider the following code: b:= TBits.Create(NRECORDS); b.NotBits(b); or more clear: b:= TBits.Create(NRECORDS); b.Clearall; b.NotBits(b); I supposed that all bits of b will be 1. What I obtain is that all bits are 0. fpc 3.0.0 win64 Am I missing something? Thank you. Andrea Mauri ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] tbits.NotBits
one more thing. there is a method like clearall to set all bits to 1? clearall is much more faster then a simple iteration along all bits Il 31/03/2017 14:07, Andrea Mauri ha scritto: I didn't understand how TBits.NotBits works. Consider the following code: b:= TBits.Create(NRECORDS); b.NotBits(b); or more clear: b:= TBits.Create(NRECORDS); b.Clearall; b.NotBits(b); I supposed that all bits of b will be 1. What I obtain is that all bits are 0. fpc 3.0.0 win64 Am I missing something? Thank you. Andrea Mauri ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel