hash function providing unique uint from an integer coordinate pair

前端 未结 11 1956
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 10:09

The problem in general: I have a big 2d point space, sparsely populated with dots. Think of it as a big white canvas sprinkled with black dots. I have to it

11条回答
  •  别那么骄傲
    2020-12-13 10:33

    a hash function that is GUARANTEED collision-free is not a hash function :)

    Instead of using a hash function, you could consider using binary space partition trees (BSPs) or XY-trees (closely related).

    If you want to hash two uint32's into one uint32, do not use things like Y & 0xFFFF because that discards half of the bits. Do something like

    (x * 0x1f1f1f1f) ^ y
    

    (you need to transform one of the variables first to make sure the hash function is not commutative)

提交回复
热议问题