Commit 28a879b3 authored by Stefan Behnel's avatar Stefan Behnel

speed up cythonized hexiom2 benchmark a little by using C int arrays instead...

speed up cythonized hexiom2 benchmark a little by using C int arrays instead of fixed size Python lists
parent 198906bd
......@@ -20,7 +20,7 @@ cdef class Done:
cdef inline bint remove_unfixed(self, v) except -123
cdef int next_cell(self, Pos pos, int strategy=*) except -123
cdef int filter_tiles(self, list tiles) except -123
cdef int filter_tiles(self, int* tiles) except -123
cdef int next_cell_min_choice(self) except -123
cdef int next_cell_max_choice(self) except -123
cdef int next_cell_highest_value(self) except -123
......@@ -53,7 +53,7 @@ cdef class Hex:
cdef class Pos:
cdef public Hex hex
cdef public Done done
cdef public list tiles
cdef public int[8] tiles
cdef Pos clone(self)
......
......@@ -229,7 +229,7 @@ class Pos(object):
@cython.locals(pos=Pos, i=cython.long, v=cython.int,
nid=cython.int, num=cython.int,
empties=cython.int, filled=cython.int,
vmax=cython.int, vmin=cython.int, cell=list)
vmax=cython.int, vmin=cython.int, cell=list, left=cython.int[8])
def constraint_pass(pos, last_move=None):
changed = False
left = pos.tiles[:]
......@@ -365,7 +365,8 @@ OPEN = 0
SOLVED = 1
IMPOSSIBLE = -1
@cython.locals(i=cython.int, num=cython.int, nid=cython.int, vmin=cython.int, vmax=cython.int)
@cython.locals(i=cython.int, num=cython.int, nid=cython.int,
vmin=cython.int, vmax=cython.int, tiles=cython.int[8])
def solved(pos, output, verbose=False):
hex = pos.hex
tiles = pos.tiles[:]
......@@ -436,7 +437,7 @@ def solve_step(prev, strategy, order, output, first=False):
return IMPOSSIBLE
@cython.locals(tot=cython.int)
@cython.locals(tot=cython.int, tiles=cython.int[8])
def check_valid(pos):
hex = pos.hex
tiles = pos.tiles
......@@ -460,7 +461,7 @@ def solve(pos, strategy, order, output):
# TODO Write an 'iterator' to go over all x,y positions
@cython.locals(x=cython.int, y=cython.int, p=cython.int,
@cython.locals(x=cython.int, y=cython.int, p=cython.int, tiles=cython.int[8],
size=cython.int, inctile=cython.int, linei=cython.int)
def read_file(file):
lines = [line.strip("\r\n") for line in file.splitlines()]
......
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