Problems using HashMap with covers / custom types? #874

Closed
geckojsc opened this Issue Apr 23, 2015 · 2 comments

Projects

None yet

3 participants

@geckojsc

From what I've tested, the following program sometimes segfaults as map get(b) returns null:

import structs/HashMap

Vec2: cover {
    x, y:Int
}

main: func {
    map := HashMap<Vec2, String> new()

    a := (10, 20) as Vec2
    b := (10, 20) as Vec2

    map put(a, "foo")
    map get(b) println()
}

I've tried the following assertions (assuming that these are the functions that were chosen by the HashMap).

assert(genericEquals(a, b))
assert(murmurHash(a) == murmurHash(b)) // fails?

Strangely the 2nd one always fails, which is weird because I thought they should have identical bits, and also weird that the main program sometimes succeeds.

I was able to get a working solution by defining custom hash functions, though originally I was tripped up because I didn't realise they had to be implemented generically.

@zhaihj
Contributor
zhaihj commented Apr 24, 2015

murmurHash may be incorrect.

  • Firstly SizeT should be UInt32;
  • The following code:
    data += 4
    if(len < 4) break
    len -= 4

will process extra 4 bytes. But in most time the bytes following value data are 0, so it sometimes works.

code should be

data += 4
len -= 4
if(len < 4) break
@zhaihj zhaihj referenced this issue in zhaihj/rock Apr 24, 2015
@zhaihj zhaihj Update murmurHash 69eb762
@fasterthanlime
Collaborator

Ugh, another remnant from the big SizeT fight of.. 2011 ? I should've stood my ground back then.

@fasterthanlime fasterthanlime modified the milestone: 0.9.10 Jul 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment