[Issue 13177] New: There may be a problem with std.bitmanip.BitArray and the "in" operator of associative arrays?
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Jul 21 05:16:23 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13177
Issue ID: 13177
Summary: There may be a problem with std.bitmanip.BitArray and
the "in" operator of associative arrays?
Product: D
Version: D2
Hardware: x86_64
OS: Windows
Status: NEW
Severity: enhancement
Priority: P1
Component: Phobos
Assignee: nobody at puremagic.com
Reporter: bfguser at gmail.com
//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.
*/
--
More information about the Digitalmars-d-bugs
mailing list