Skip to content

Instantly share code, notes, and snippets.

@TinkerWorX
Created April 28, 2012 04:53
Show Gist options
  • Save TinkerWorX/2516110 to your computer and use it in GitHub Desktop.
Save TinkerWorX/2516110 to your computer and use it in GitHub Desktop.
A simple Point struct that generates collision free hash codes.
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