Commit 93bc4e79 authored by Colomban Wendling's avatar Colomban Wendling
Browse files

Move position hash to Position.hash()

parent 3235ed67
......@@ -32,11 +32,26 @@ namespace OVCC
{
return this.x == pos.x && this.y == pos.y;
}
public uint hash ()
{
/* from g_str_hash, do a direct in-memory hash */
char *p = (char *) (&this);
uint32 h = p[0];
size_t i = 0;
for (i = 1; i < sizeof (Position); i++) {
h = (h << 5) - h + p[i];
}
return (uint) h;
}
}
public class Board : Object
{
private HashTable<Position?,Tile> _board = new HashTable<Position?,Tile> (position_hash, position_equals);
private HashTable<Position?,Tile> _board = new HashTable<Position?,Tile> ((k) => { return k.hash (); },
(a, b) => { return a.equals (b); });
/* private HashTable<Pawns> _pawns = new HashTable<Pawns> (); */
private int leftedge = 0;
......@@ -45,7 +60,7 @@ namespace OVCC
private int bottomedge = 0;
public signal void tile_added (Tile t, Position pos);
public Board ()
{
}
......@@ -175,25 +190,6 @@ namespace OVCC
height = (topedge - bottomedge).abs() + 1;
}
private static uint position_hash (Position? key)
{
/* from g_str_hash, do a direct in-memory hash */
char *p = (char *) key;
uint32 h = p[0];
size_t i = 0;
for (i = 1; i < sizeof (Position); i++)
h = (h << 5) - h + p[i];
return (uint) h;
}
private static bool position_equals (Position? a,
Position? b)
{
return a.equals (b);
}
public delegate bool BoardForeachFunc (Board board,
Position pos,
Tile tile);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment