New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems using HashMap with covers / custom types? #874

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

Comments

Projects
None yet
3 participants
@geckojsc

geckojsc commented Apr 23, 2015

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

This comment has been minimized.

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 referenced this issue in zhaihj/rock Apr 24, 2015

@fasterthanlime

This comment has been minimized.

Collaborator

fasterthanlime commented Jul 8, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment