summaryrefslogtreecommitdiffstats
path: root/kpat/freecell-solver/fcs_isa.c
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitc90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch)
tree6d8391395bce9eaea4ad78958617edb20c6a7573 /kpat/freecell-solver/fcs_isa.c
downloadtdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz
tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kpat/freecell-solver/fcs_isa.c')
-rw-r--r--kpat/freecell-solver/fcs_isa.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/kpat/freecell-solver/fcs_isa.c b/kpat/freecell-solver/fcs_isa.c
new file mode 100644
index 00000000..0a6ffe51
--- /dev/null
+++ b/kpat/freecell-solver/fcs_isa.c
@@ -0,0 +1,88 @@
+/* fcs_isa.c - Freecell Solver Indirect State Allocation Routines
+
+ Written by Shlomi Fish, 2000
+ This file is distributed under the public domain.
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "fcs_config.h"
+
+
+#include "state.h"
+#include "fcs.h"
+
+#include "fcs_isa.h"
+
+#ifdef DMALLOC
+#include "dmalloc.h"
+#endif
+
+void freecell_solver_state_ia_init(freecell_solver_hard_thread_t * hard_thread)
+{
+ hard_thread->max_num_state_packs = IA_STATE_PACKS_GROW_BY;
+ hard_thread->state_packs = (fcs_state_with_locations_t * *)malloc(sizeof(fcs_state_with_locations_t *) * hard_thread->max_num_state_packs);
+ hard_thread->num_state_packs = 1;
+ /*
+ * All the states should fit in one 64KB segment. Now, we allocate as
+ * many states as possible, minus one, so we would be certain that there
+ * would be place for the overhead required by the malloc algorithm.
+ * */
+ hard_thread->state_pack_len = (0x010000 / sizeof(fcs_state_with_locations_t)) - 1;
+ hard_thread->state_packs[0] = malloc(hard_thread->state_pack_len*sizeof(fcs_state_with_locations_t));
+
+ hard_thread->num_states_in_last_pack = 0;
+}
+
+#if 0
+fcs_state_with_locations_t * fcs_state_ia_alloc(freecell_solver_hard_thread_t * hard_thread)
+{
+ if (hard_thread->num_states_in_last_pack == hard_thread->state_pack_len)
+ {
+ if (hard_thread->num_state_packs == hard_thread->max_num_state_packs)
+ {
+ hard_thread->max_num_state_packs += IA_STATE_PACKS_GROW_BY;
+ hard_thread->state_packs = (fcs_state_with_locations_t * *)realloc(hard_thread->state_packs, sizeof(fcs_state_with_locations_t *) * hard_thread->max_num_state_packs);
+ }
+ hard_thread->state_packs[hard_thread->num_state_packs] = malloc(hard_thread->state_pack_len * sizeof(fcs_state_with_locations_t));
+ hard_thread->num_state_packs++;
+ hard_thread->num_states_in_last_pack = 0;
+ }
+ return &(hard_thread->state_packs[hard_thread->num_state_packs-1][hard_thread->num_states_in_last_pack++]);
+}
+#endif
+
+#if 0
+void fcs_state_ia_release(freecell_solver_hard_thread_t * hard_thread)
+{
+ hard_thread->num_states_in_last_pack--;
+}
+#endif
+
+void freecell_solver_state_ia_finish(freecell_solver_hard_thread_t * hard_thread)
+{
+ int a;
+ for(a=0;a<hard_thread->num_state_packs;a++)
+ {
+ free(hard_thread->state_packs[a]);
+ }
+ free(hard_thread->state_packs);
+ hard_thread->state_packs = NULL;
+}
+
+void freecell_solver_state_ia_foreach(freecell_solver_hard_thread_t * hard_thread, void (*ptr_function)(fcs_state_with_locations_t *, void *), void * context)
+{
+ int p,s;
+ for(p=0;p<hard_thread->num_state_packs-1;p++)
+ {
+ for(s=0 ; s < hard_thread->state_pack_len ; s++)
+ {
+ ptr_function(&(hard_thread->state_packs[p][s]), context);
+ }
+ }
+ for(s=0; s < hard_thread->num_states_in_last_pack ; s++)
+ {
+ ptr_function(&(hard_thread->state_packs[p][s]), context);
+ }
+}