hash function providing unique uint from an integer coordinate pair

前端 未结 11 1965
隐瞒了意图╮
隐瞒了意图╮ 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:27

    If you're already using languages or platforms that all objects (even primitive ones like integers) has built-in hash functions implemented (Java platform Languages like Java, .NET platform languages like C#. And others like Python, Ruby, etc ). You may use built-in hashing values as a building block and add your "hashing flavor" in to the mix. Like:

    // C# code snippet 
    public class SomeVerySimplePoint { 
    
    public int X;
    public int Y;
    
    public override int GetHashCode() {
       return ( Y.GetHashCode() << 16 ) ^ X.GetHashCode();
    }
    
    }
    

    And also having test cases like "predefined million point set" running against each possible hash generating algorithm comparison for different aspects like, computation time, memory required, key collision count, and edge cases (too big or too small values) may be handy.

提交回复
热议问题