Skip to content

Commit

Permalink
Merge branch 'release/v1.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethshackleton committed Sep 24, 2017
2 parents 8fd084b + 4ff56fb commit 21012b0
Show file tree
Hide file tree
Showing 8 changed files with 6,718 additions and 33 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
### Change Log

#### 1.8

* Index cards by bytes.
* Observed performance gains of about 23%.

#### 1.7.1

* Reduce rank hash table by 9%.
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Expand Up @@ -5,8 +5,8 @@ project(${PROJECT_NAME})

# Versioning.
set(SK_POKER_EVAL_VERSION_MAJOR 1)
set(SK_POKER_EVAL_VERSION_MINOR 7)
set(SK_POKER_EVAL_VERSION_PATCH 1)
set(SK_POKER_EVAL_VERSION_MINOR 8)
set(SK_POKER_EVAL_VERSION_PATCH 0)

# Get the current commit.
execute_process(
Expand Down
5 changes: 3 additions & 2 deletions README.md
@@ -1,6 +1,6 @@
# SKPokerEval

A lightweight 32-bit Texas Hold'em 7-card hand evaluator written in C++.
A fast and lightweight 32-bit Texas Hold'em 7-card hand evaluator written in C++.

## Travis status

Expand Down Expand Up @@ -41,7 +41,8 @@ Taking v1.1 as the base line, the sampled relative throughput of random [SevenEv
| [1.4.2](https://github.com/kennethshackleton/SKPokerEval/releases/tag/v1.4.2) |               1.18 | Hashing.                          |
| [1.6](https://github.com/kennethshackleton/SKPokerEval/releases/tag/v1.6)     |               1.50 | Remove branching from flush case. |
| [1.7](https://github.com/kennethshackleton/SKPokerEval/releases/tag/v1.7)     |               1.53 | Reduce the hash table.            |
| [1.7.1](https://github.com/kennethshackleton/SKPokerEval/releases/tag/v1.7.1) |               1.56 | Reduce the rank hash table.      |
| [1.7.1](https://github.com/kennethshackleton/SKPokerEval/releases/tag/v1.7.1) |               1.57 | Reduce the rank hash table.      |
| [1.8](https://github.com/kennethshackleton/SKPokerEval/releases/tag/v1.8) |               1.93 | Index cards by bytes.      |

## I want to contribute, how might I profile my change?

Expand Down
21 changes: 21 additions & 0 deletions scripts/__init__.py
@@ -0,0 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# SKPokerEval
#
# Copyright 2010 Kenneth J. Shackleton
#
# This program gives you software freedom; you can copy, convey, propagate,
# redistribute and/or modify this program under the terms of the GNU General
# Public License (GPL) as published by the Free Software Foundation (FSF),
# either version 3 of the License, or (at your option) any later version of
# the GPL published by the FSF.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program in a file in the top-level directory called "GPLv3". If
# not, see http://www.gnu.org/licenses/.
47 changes: 25 additions & 22 deletions scripts/perfect_hash.py
Expand Up @@ -24,6 +24,8 @@
# See "Fundamental Study Perfect Hashing" by Czech, Havas, Majewski,
# Theoretical Computer Science 182 (1997) 1-143.

from rank import rank

val = [0, 1, 5, 22, 98, 453, 2031, 8698, 22854, 83661, 262349, 636345, 1479181]
keys = set([])
max_key = 0
Expand All @@ -33,14 +35,11 @@
for k in xrange(1, j+1):
for l in xrange(0, k+1):
for m in xrange(0, l+1):
if not m < i:
break
if not m < i: break
for n in xrange(0, m+1):
if not n < j:
break
if not n < j: break
for p in xrange(0, n+1):
if not p < k:
break
if not p < k: break
key = val[i] + val[j] + val[k] + val[l] + val[m] +\
val[n] + val[p]
keys.add(key)
Expand All @@ -55,34 +54,38 @@
square = [[-1]*(512*side) for i in xrange(side)]

for k in keys:
square[k % side][k / side] = k
square[k % side][k / side] = rank(k)

offset = [0]*((max_key / side) + 1)
hash_table = [-1]*max_key
hash_table_len = 0
ranks = [-1]*max_key
length = 0

for i in xrange(0, len(offset)):
for j in xrange(0, len(hash_table)-side):
for j in xrange(0, len(ranks)-side):
collision = False
for k in xrange(0, side):
if hash_table[j+k] != -1 and square[k][i] != -1:
collision = True
break
s = square[k][i]
h = ranks[j+k]
collision = (s != -1 and h != -1 and s != h)
if collision: break
if not collision:
offset[i] = j
for k in xrange(0, side):
x = square[k][i]
if x != -1:
hash_table[j+k] = x
hash_table_len = max(hash_table_len, j+side)
print "Offset of row %i is %i (length %i)." %\
(i, j, hash_table_len)
s = square[k][i]
if s != -1:
n = j+k
ranks[n] = s
length = max(length, n)
print "Offset of row %i is %i (length %i)." % (i, j, length)
break

with open('./hash_table_%s' % (side,), 'w') as f:
f.write("%s\n" % (hash_table[0:hash_table_len],))
for i in xrange(0, length):
if ranks[i] == -1: ranks[i] = 0

with open('./ranks_%s' % (side,), 'w') as f:
f.write("%s\n" % (ranks[0:length],))

with open('./offset_%s' % (side,), 'w') as f:
f.write("%s\n" % (offset,))

print "Hash table has length %i." % (hash_table_len,)
print "Hash table has length %i." % (length,)

0 comments on commit 21012b0

Please sign in to comment.