D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13177 - There may be a problem with std.bitmanip.BitArray and the "in" operator of associative arrays?
Summary: There may be a problem with std.bitmanip.BitArray and the "in" operator of as...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-21 12:16 UTC by cvbcvb
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description cvbcvb 2014-07-21 12:16:23 UTC
//checking out the following code snippet:

BitArray ba, ba2, ba3;
bool[] b = [1, 1, 0, 0, 0];
ba.init(b);
bool[] b2 = [1, 0, 0, 0, 0];
ba2.init(b2);
bool[] b3 = [1, 0, 0, 0, 0];
ba3.init(b3);

int[BitArray] ha;
ha[ba] = 9;
ha[ba2] = 10;

writeln("HASH BA2: ", ba2.toHash(), " HASH BA3: ", ba3.toHash());
writeln(ba2.opEquals(ba3));
if (ba2 in ha) writeln("in hash");
writeln("ba.toHash(): ", ba.toHash());
auto tba = ba.dup();
writeln("tba.toHash(): ", ba.toHash());
writeln("editing tba:");
tba[1] = false;
writeln("tba.toHash(): ", tba.toHash());
foreach (bit; ba) bit ? write(1) : write(0);
writeln();
foreach (bit; tba) bit ? write(1) : write(0);
writeln();
writeln(tba.opEquals(ba2));
ha.rehash;
if (tba in ha) writeln("found");

//I assume the last output line would be "found" but the output i get is the following:
/*
BitArray ba, ba2, ba3;
bool[] b = [1, 1, 0, 0, 0];
ba.init(b);
bool[] b2 = [1, 0, 0, 0, 0];
ba2.init(b2);
bool[] b3 = [1, 0, 0, 0, 0];
ba3.init(b3);

int[BitArray] ha;
ha[ba] = 9;
ha[ba2] = 10;

writeln("HASH BA2: ", ba2.toHash(), " HASH BA3: ", ba3.toHash());
writeln(ba2.opEquals(ba3));
if (ba2 in ha) writeln("in hash");
writeln("ba.toHash(): ", ba.toHash());
auto tba = ba.dup();
writeln("tba.toHash(): ", ba.toHash());
writeln("editing tba:");
tba[1] = false;
writeln("tba.toHash(): ", tba.toHash());
foreach (bit; ba) bit ? write(1) : write(0);
writeln();
foreach (bit; tba) bit ? write(1) : write(0);
writeln();
writeln(tba.opEquals(ba2));
ha.rehash;
if (tba in ha) writeln("found");
*/
/*The BitArray ba2 and tba is have the same hash values and they are equal accordin go opEquals and according to phobos:
"Using Structs or Unions as the KeyType

If the KeyType is a struct or union type, a default mechanism is used to compute the hash and comparisons of it based on the binary data within the struct val"
So i assume if (tba in ha) should have a logic value of "true" and i should see the word "found" on my standard output.
*/
Comment 1 basile-z 2015-11-21 15:16:53 UTC
this is the case now. you get true in your output (tba in ha)