Bug 13177 – There may be a problem with std.bitmanip.BitArray and the "in" operator of associative arrays?

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-07-21T12:16:23Z
Last change time
2020-03-21T03:56:32Z
Assigned to
No Owner
Creator
cvbcvb

Comments

Comment #0 by bfguser — 2014-07-21T12:16:23Z
//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 by b2.temp — 2015-11-21T15:16:53Z
this is the case now. you get true in your output (tba in ha)