Class KnownRangeHasher
NON-GENERALIZED hashing algorithm for Point instances that calculates a hash, assuming a known minimum and maximum extent of the Points being hashed.
Namespace: SadRogue.Primitives.PointHashers
Assembly: TheSadRogue.Primitives.dll
Syntax
public class KnownRangeHasher : EqualityComparer<Point>
Remarks
This is NOT an efficient generalized hashing algorithm; it generates a hash code using the assumption of a "maximum range" of x/y values in which all the points given to it to hash fall. It simply normalizes the points to a range of (0, 0), to (x_1, y_1), then hashes them via a simple call to ToIndex(Int32). The algorithm WILL still function on points outside of the min/max extents; however it will start to generate more collisions.
This algorithm is nonetheless useful in some cases; the assumption that points will fall from (minX, minY) to some known max width/height is fairly common (as it could apply to any fixed-size grid). Since this algorithm can be significantly faster to compute than fully generalized algorithms, it can be useful for these cases.
Constructors
KnownRangeHasher(Point, Point)
Creates a new instance of the comparison/hashing algorithm implementation.
Declaration
public KnownRangeHasher(Point minExtent, Point maxExtent)
Parameters
Type | Name | Description |
---|---|---|
Point | minExtent | Point whose x and y values constitute the minimum x/y values that will generally be encountered in Point instances that are hashed by this algorithm. |
Point | maxExtent | Point whose x and y values constitute the maximum x/y values that will generally be encountered in Point instances that are hashed by this algorithm. |
KnownRangeHasher(Point, Int32)
Creates a new instance of the comparison/hashing algorithm implementation.
Declaration
public KnownRangeHasher(Point minExtent, int boundsWidth)
Parameters
Type | Name | Description |
---|---|---|
Point | minExtent | Point whose x and y values constitute the minimum x/y values that will generally be encountered in Point instances that are hashed by this algorithm. |
Int32 | boundsWidth | Width of the bounds that will generally encompass Points hashed by this hashing algorithm. |
KnownRangeHasher(Rectangle)
Creates a new instance of the comparison/hashing algorithm implementation.
Declaration
public KnownRangeHasher(Rectangle bounds)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | bounds | Bounds encompassing the area which points generally hashed by this algorithm will reside within. |
Fields
BoundsWidth
Width of the area which encompasses points which will generally be hashed by this algorithm, starting at MinExtent.
Declaration
public readonly int BoundsWidth
Field Value
Type | Description |
---|---|
Int32 |
MinExtent
Minimum x/y values that will generally occur in points hashed by this instance.
Declaration
public readonly Point MinExtent
Field Value
Type | Description |
---|---|
Point |
Methods
Equals(Point, Point)
Declaration
public override bool Equals(Point x, Point y)
Parameters
Type | Name | Description |
---|---|---|
Point | x | |
Point | y |
Returns
Type | Description |
---|---|
Boolean |
GetHashCode(Point)
Declaration
public override int GetHashCode(Point p)
Parameters
Type | Name | Description |
---|---|---|
Point | p |
Returns
Type | Description |
---|---|
Int32 |