Commits

shl...@b384bcd7-cfd4-0310-aca0-d78b80f7b91b  committed 1bad83b

Adapted the build system for Tokyo Cabinet.

The TC backend still doesn't work (but the internal_hash is OK.)

  • Participants
  • Parent commits 59cc65e

Comments (0)

Files changed (7)

File black-hole-solitaire/c-solver/CMakeLists.txt

 
 INCLUDE(CPack)
 INCLUDE(CheckCCompilerFlag)
+INCLUDE(FindPkgConfig)
 
 LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
 
 
 ENDIF (${BHS_STATE_STORAGE} STREQUAL "BHS_STATE_STORAGE_INTERNAL_HASH")
 
+SET (LIBTOKYO_CAB_LIBS)
 
 IF (${BHS_STATE_STORAGE} STREQUAL "BHS_STATE_STORAGE_TOKYO_CAB_HASH")
 
     LIST(APPEND BLACK_HOLE_SOLVER_MODULES tokyo_cab_hash.c)
 
+    PKG_CHECK_MODULES(TOKYO_CAB REQUIRED "tokyocabinet")
+
+    IF (NOT TOKYO_CAB_FOUND)
+        MESSAGE (FATAL "Tokyo cabinet could not be found.")
+    ENDIF (NOT TOKYO_CAB_FOUND)
+
+    SET (LIBTOKYO_CAB_LIBS ${TOKYO_CAB_LIBRARIES})
 ENDIF (${BHS_STATE_STORAGE} STREQUAL "BHS_STATE_STORAGE_TOKYO_CAB_HASH")
 
 SET(COMPILER_FLAGS_TO_CHECK 
     ${BLACK_HOLE_SOLVER_MODULES}
     )
 
+TARGET_LINK_LIBRARIES("${LIB_BASE}" ${LIBTOKYO_CAB_LIBS})
+
 LIST (APPEND BLACK_HOLE_SOLVER_LIBS "${LIB_BASE}")
 
 IF (BUILD_STATIC_LIBRARY)
         ${FREECELL_SOLVER_LIB_MODULES}
     )
 
-    LIST (APPEND BLACK_HOLE_SOLVER_LIBS "${$STATIC_LIB}")
+    LIST (APPEND BLACK_HOLE_SOLVER_LIBS "${STATIC_LIB}")
 
     SET_TARGET_PROPERTIES(
         "${STATIC_LIB}"

File black-hole-solitaire/c-solver/Tatzer

+#!/usr/bin/env perl
+
+# This is a script to configure the distribution. Its primary audience
+# are the core developers and halo developers, and not end-users. Please
+# see the INSTALL file for proper building instructions using cmake.
+#
+# "Tatzer" (Taf-Tzadik-Reish) is the Hebrew word for "configure!".
+
+use strict;
+use warnings;
+
+use Getopt::Long;
+
+my $build_type = "debug";
+my $state_storage;
+my $prefix = "/usr";
+my $build_static_lib = 0;
+my $test_suite = 1;
+my $cpu_arch;
+my $omit_frame;
+my $state_storage_libavl2_tree;
+my $stack_storage_libavl2_tree;
+my $with_context_var = 1;
+my $max_bench_threads_num = 4;
+my $pack_size;
+my $link_to_static = 0;
+
+sub set_both
+{
+    my $val = shift;
+    $state_storage = $val;
+
+    return;
+}
+
+sub set_hash
+{
+    return set_both("INTERNAL_HASH");
+}
+
+set_hash();
+
+my %themes =
+(
+    tt => [qw(-r --notest-suite --static)],
+    bench => [qw(-l tt --omit-frame)],
+    fc_bench => [qw(-l bench --fc-only)],
+    p4b => [qw(-l fc_bench --arch=pentium4)],
+    x64b => [qw(-l fc_bench --arch=barcelona)],
+    p4bb => [qw(-l bench --arch=pentium4)],
+    x64bb => [qw(-l bench --arch=barcelona)],    
+);
+
+my @new_argv = @ARGV;
+
+CALC_NEW_ARGV:
+for (my $idx = 0; $idx < @new_argv ; $idx++)
+{
+    if ($new_argv[$idx] =~ m{\A-l(.*)\z}ms)
+    {
+        my $start_idx = $idx;
+
+        my $param = $1 || $new_argv[++$idx];
+
+        if (! (my $cmd = $themes{$param}) )
+        {
+            die "Unknown -l argument $param!";
+        }
+        else
+        {
+            splice (@new_argv, $start_idx, $idx-$start_idx+1, @$cmd);
+        }
+        
+        $idx = $start_idx;
+        redo CALC_NEW_ARGV;
+    }
+}
+
+@ARGV = @new_argv;
+
+GetOptions(
+    'd|debug' => sub {
+        my ($opt, $val) = @_;
+        if ($val)
+        {
+            $build_type = "debug";
+        }
+        return;
+    },
+    'r|release' => sub {
+        my ($opt, $val) = @_;
+        if ($val) 
+        {
+            $build_type = "release";
+        } 
+        elsif ($build_type eq "release")
+        {
+            $build_type = "debug";
+        }
+        return;
+    },
+    'p|pos=s' => \$state_storage,
+    'libavl2-p=s' => \$state_storage_libavl2_tree,
+    'libavl2-c=s' => \$stack_storage_libavl2_tree,
+    'prefix=s' => \$prefix,
+    'test-suite!' => \$test_suite,
+    'tokyo' => sub { return set_both("TOKYO_CAB_HASH"); },
+    'hash' => \&set_hash,
+    'static' => \$build_static_lib,
+    'profile' => sub {
+        my ($opt, $val) = @_;
+        if ($val) 
+        {
+            $build_type = "profile";
+        } 
+        elsif ($build_type eq "profile")
+        {
+            $build_type = "debug";
+        }
+        return;
+    },
+    'minsize' => sub {
+        $build_type = "MinSizeRel";
+        return;
+    },
+    'arch=s' => \$cpu_arch,
+    'omit-frame!' => \$omit_frame,
+    'with-ctx-var!' => \$with_context_var,
+    'max-bench-threads-num=i' => \$max_bench_threads_num,
+    'pack-size=i' => \$pack_size,
+    'static!' => \$link_to_static,
+) or
+    die "Wrong options";
+
+my $dir = shift(@ARGV) || '.';
+
+if ($state_storage_libavl2_tree)
+{
+    $state_storage = "LIBAVL2_TREE";
+}
+
+# This cache is sometimes causing problems.
+unlink("CMakeCache.txt");
+
+my @cmd= ("cmake",
+    "-DCMAKE_BUILD_TYPE=$build_type",
+    "-DBHS_STATE_STORAGE=BHS_STATE_STORAGE_$state_storage",
+    "-DMAX_NUM_BENCHMARK_THREADS=$max_bench_threads_num",
+    "-DCMAKE_INSTALL_PREFIX=$prefix",
+    "-DDATADIR=$prefix/share",
+    ((!$build_static_lib) ? ("-DBUILD_STATIC_LIBRARY=") : ()),
+    (defined($pack_size) ? ("-DFCS_IA_PACK_SIZE=$pack_size") : ()),
+    ($test_suite ? ("-DFCS_WITH_TEST_SUITE=1") : ()),
+    (defined($cpu_arch) ? ("-DCPU_ARCH=$cpu_arch") : ()),
+    ($omit_frame ? "-DOPTIMIZATION_OMIT_FRAME_POINTER=1" : ()),
+    ($state_storage_libavl2_tree
+        ? "-DFCS_STATE_STORAGE_LIBAVL2_TREE_TYPE=$state_storage_libavl2_tree"
+        : ()
+    ),
+    ($stack_storage_libavl2_tree
+        ? "-DFCS_STACK_STORAGE_LIBAVL2_TREE_TYPE=$stack_storage_libavl2_tree"
+        : ()
+    ),
+    (exists($ENV{"LIBAVL2_SOURCE_DIR"})
+        ? ("-DLIBAVL2_SOURCE_DIR=$ENV{LIBAVL2_SOURCE_DIR}")
+        : ()
+    ),
+    ($with_context_var
+        ? "-DFCS_WITH_CONTEXT_VARIABLE=1"
+        : "-DFCS_WITH_CONTEXT_VARIABLE="
+    ),
+    ($link_to_static
+        ? ("-DFCS_LINK_TO_STATIC=1")
+        : ("-DFCS_LINK_TO_STATIC=")
+    ),
+    $dir
+);
+
+print(join(" ", @cmd), "\n");
+exec(@cmd);
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (c) 2009 Shlomi Fish
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+=cut
+

File black-hole-solitaire/c-solver/black_hole_solver.c

 #else
 #include "fcs_hash.h"
 #endif
+
+#include "alloc.h"
+
 typedef struct 
 {
     /*
         ret->iterations_num = 0;
         ret->num_states_in_collection = 0;
         bh_solve_compact_allocator_init(&(ret->allocator));
-        bh_solve_hash_init(&(ret->positions), 256);
+        bh_solve_hash_init(&(ret->positions));
         *ret_instance = (black_hole_solver_instance_t *)ret;
         return BLACK_HOLE_SOLVER__SUCCESS;
     }
 {
     bhs_solver_t * solver;
     bhs_state_key_value_pair_t * init_state;
+#if (! (BHS_STATE_STORAGE == BHS_STATE_STORAGE_TOKYO_CAB_HASH))
     void * init_state_existing;
+#endif
     bhs_state_key_value_pair_t * state, * next_state;
     int four_cols_idx, four_cols_offset;
     bhs_state_key_value_pair_t * * queue;
                         , &init_state_existing
                         , perl_hash_function(((ub1 *)&(next_state->key)), 
                             sizeof(next_state->key))
+#endif
                         )
-#endif
                     )
                     {
                         num_states_in_collection++;
         bhs_state_key_value_pair_t temp_state;
 
         int i, num_states, max_num_states;
+#if (! (BHS_STATE_STORAGE == BHS_STATE_STORAGE_TOKYO_CAB_HASH))
         void * next_state;
+#endif
 
         num_states = 0;
         max_num_states = 53;

File black-hole-solitaire/c-solver/fcs_hash.c

 
 
 void bh_solve_hash_init(
-    bh_solve_hash_t * hash,
-    bh_solve_hash_value_t wanted_size
+    bh_solve_hash_t * hash
     )
 {
-    int size;
-    /* Find a size that's a power of 2 that's just greater than 
-     * the wanted_size. */
-    size = 256;
-    while (size < wanted_size)
-    {
-        size <<= 1;
-    }
+    int size = 256;
 
     hash->size = size;
     hash->size_bitmask = size-1;

File black-hole-solitaire/c-solver/fcs_hash.h

 
 extern void
 bh_solve_hash_init(
-    bh_solve_hash_t * hash,
-    bh_solve_hash_value_t wanted_size
+    bh_solve_hash_t * hash
     );
 
 /*

File black-hole-solitaire/c-solver/tokyo_cab_hash.c

 #include "state.h"
 
 void bh_solve_hash_init(
-    bh_solve_hash_t * hash,
-    bh_solve_hash_value_t wanted_size
+    bh_solve_hash_t * hash
     )
 {
     hash->hash = tchdbnew();
     tchdbsetcache(hash->hash, 128*1024);
-    tchdbopen(hash->hash, "bh_solve.hdb", HDBOWRITER|GDBOTRUNC|HDBOREADER);
+    tchdbopen(hash->hash, "bh_solve.hdb", HDBOWRITER|HDBOTRUNC|HDBOREADER);
     return;
 }
 

File black-hole-solitaire/c-solver/tokyo_cab_hash.h

 #include "inline.h"
 #include "bool.h"
 
+#include "state.h"
+
 typedef struct
 {
     TCHDB * hash;
 
 extern void
 bh_solve_hash_init(
-    bh_solve_hash_t * hash,
-    bh_solve_hash_value_t wanted_size
+    bh_solve_hash_t * hash
     );
 
 /*
     bhs_state_key_value_pair_t * result
     )
 {
-    result->key = key_ptr;
+    result->key = (*key_ptr);
     tchdbget3(hash->hash, key_ptr, sizeof(*key_ptr), &(result->value), sizeof(result->value));
 
     return;