Skip to content
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
exelotl opened this issue Apr 23, 2015 · 2 comments
Closed

Problems using HashMap with covers / custom types? #874

exelotl opened this issue Apr 23, 2015 · 2 comments
Milestone

Comments

@exelotl
Copy link

@exelotl exelotl 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.

@horasal
Copy link
Contributor

@horasal horasal 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

Loading

horasal referenced this issue in horasal/rock Apr 24, 2015
@fasterthanlime
Copy link
Collaborator

@fasterthanlime fasterthanlime commented Jul 8, 2015

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

Loading

@fasterthanlime fasterthanlime added this to the 0.9.10 milestone Jul 10, 2015
@fasterthanlime fasterthanlime added this to the 0.9.10 milestone Jul 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants