Discussion:
tbits.NotBits
(too old to reply)
Andrea Mauri
2017-03-31 12:07:09 UTC
Permalink
Raw Message
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-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-dev
Andrea Mauri
2017-03-31 12:10:51 UTC
Permalink
Raw Message
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
Post by Andrea Mauri
I didn't understand how TBits.NotBits works.
b:= TBits.Create(NRECORDS);
b.NotBits(b);
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-***@lists.freepascal.org
http://lists.free
Andrea Mauri
2017-03-31 13:58:22 UTC
Permalink
Raw Message
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
Post by Andrea Mauri
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
Post by Andrea Mauri
I didn't understand how TBits.NotBits works.
b:= TBits.Create(NRECORDS);
b.NotBits(b);
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-***@lists.freepascal.org
http://lists.freepascal.org/cg
Andrea Mauri
2017-04-13 08:30:33 UTC
Permalink
Raw Message
any answer?
I asked in the wrong place?
where should I ask?
Post by Andrea Mauri
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
Post by Andrea Mauri
I didn't understand how TBits.NotBits works.
b:= TBits.Create(NRECORDS);
b.NotBits(b);
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-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinf
Michael Van Canneyt
2017-04-13 08:52:44 UTC
Permalink
Raw Message
Post by Andrea Mauri
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.
Post by Andrea Mauri
Post by Andrea Mauri
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
Post by Andrea Mauri
I didn't understand how TBits.NotBits works.
b:= TBits.Create(NRECORDS);
b.NotBits(b);
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
_______________________________________________
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.fre
Mattias Gaertner
2017-04-13 09:06:35 UTC
Permalink
Raw Message
On Thu, 13 Apr 2017 10:52:44 +0200 (CEST)
Post by Michael Van Canneyt
[...]
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-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo
Mattias Gaertner
2017-04-13 08:51:03 UTC
Permalink
Raw Message
On Fri, 31 Mar 2017 14:07:09 +0200
Post by Andrea Mauri
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-***@lists.freepascal.org
http://lists.freepascal
Andrea Mauri
2017-04-13 09:28:20 UTC
Permalink
Raw Message
Post by Mattias Gaertner
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-***@lists.freepascal.org
http://lists.freepascal.org/cgi-b
Mattias Gaertner
2017-04-13 09:47:00 UTC
Permalink
Raw Message
On Thu, 13 Apr 2017 11:28:20 +0200
Post by Andrea Mauri
[...]
procedure TBits.Setall;
var
loop : longint;
begin
for loop := 0 to FSize - 1 do
FBits^[loop] := 1;
Should be
FBits^[loop] := not cardinal(0);
Post by Andrea Mauri
end;
Btw, it seems TBits misses an AssignBits(b: TBits).

And maybe an AssignNotBits(b: TBits)
Post by Andrea Mauri
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.
Post by Andrea Mauri
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-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Loading...