Created
April 28, 2012 04:53
-
-
Save TinkerWorX/2516110 to your computer and use it in GitHub Desktop.
A simple Point struct that generates collision free hash codes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace TinkerWorX.Legeria | |
{ | |
/// <summary> | |
/// A simple Point struct that generates collision free hash codes. | |
/// </summary> | |
public struct HashPoint | |
{ | |
public Int16 X; | |
public Int16 Y; | |
public HashPoint(Int16 x, Int16 y) | |
{ | |
this.X = x; | |
this.Y = y; | |
} | |
public override Int32 GetHashCode() | |
{ | |
return (this.X << 16 | (UInt16)this.Y); | |
} | |
public Boolean Equals(HashPoint other) | |
{ | |
return (this.X == other.X && this.Y == other.Y); | |
} | |
public override Boolean Equals(Object other) | |
{ | |
return (other is HashPoint) && this.Equals((HashPoint)other); | |
} | |
public override string ToString() | |
{ | |
return String.Format("{{{0}; {1}}}", this.X, this.Y); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment