Commits

Anonymous committed a0eadc3

Add bh_solve_get to fcs_hash.c.

Comments (0)

Files changed (4)

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

     bhs_state_key_value_pair_t * init_state;
     bhs_state_key_value_pair_t state;
     bhs_state_key_value_pair_t next_state;
+#if (! (BHS_STATE_STORAGE == BHS_STATE_STORAGE_TOKYO_CAB_HASH))
     bhs_state_key_value_pair_t * init_state_existing;
+#endif
 
     int four_cols_idx, four_cols_offset;
     bhs_state_key_value_pair_t * queue;
         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))
-        bhs_state_key_value_pair_t * next_state;
-#endif
 
         num_states = 0;
         max_num_states = 53;
          
             key_ptr = (bhs_state_key_value_pair_t *)&(states[num_states].value.parent_state);
             /* Look up the next state in the positions associative array. */
-#if (BHS_STATE_STORAGE == BHS_STATE_STORAGE_TOKYO_CAB_HASH)
             bh_solve_hash_get(
                 &(solver->positions),
                 key_ptr,
                 states+(++num_states)
+#if (! (BHS_STATE_STORAGE == BHS_STATE_STORAGE_TOKYO_CAB_HASH))
+                ,perl_hash_function((ub1 *)&(key_ptr->key), sizeof(key_ptr->key))
+#endif
             );
-#else
-            bh_solve_hash_insert(
-                &(solver->positions),
-                key_ptr,
-                &next_state,
-                perl_hash_function((ub1 *)key_ptr, sizeof(key_ptr->key))
-            );
-
-            memcpy(
-                states+(++num_states),
-                next_state, 
-                sizeof(states[0])
-            );            
-#endif
-
         }
 
         num_states++;

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

 
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 #include "fcs_hash.h"
 
     return;
 }
 
+void bh_solve_hash_get(
+    bh_solve_hash_t * hash,
+    bhs_state_key_value_pair_t * key_ptr,
+    bhs_state_key_value_pair_t * result,
+    bh_solve_hash_value_t hash_value
+    )
+{
+    bh_solve_hash_symlink_t * list;
+    bh_solve_hash_symlink_item_t * item;
+#define PLACE() (hash_value & (hash->size_bitmask))
+    list = (hash->entries + PLACE());
+
+    assert(item = list->first_item);
+
+    result->key = key_ptr->key;
+
+    while (item != NULL)
+    {
+        if (
+            (!memcmp(&(item->key.key), &(key_ptr->key), sizeof(bhs_state_key_t)))
+        )
+        {
+            result->value = item->key.value;
+            return;
+        }
+
+        item = item->next;
+    }
+
+    assert(0);
+
+    return;
+}
+
 fcs_bool_t bh_solve_hash_insert(
     bh_solve_hash_t * hash,
     bhs_state_key_value_pair_t * key,
 
         while (item != NULL)
         {
-            /*
-                We first compare the hash values, because it is faster than
-                comparing the entire data structure.
-            */
             if (
                 (!memcmp(&(item->key.key), &(key->key), sizeof(bhs_state_key_t)))
                )

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

     free(hash->entries);
 }
 
+extern void bh_solve_hash_get(
+    bh_solve_hash_t * hash,
+    bhs_state_key_value_pair_t * key_ptr,
+    bhs_state_key_value_pair_t * result,
+    bh_solve_hash_value_t hash_value
+    );
+
+
 #ifdef __cplusplus
 }
 #endif

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

 
 static GCC_INLINE void bh_solve_hash_get(
     bh_solve_hash_t * hash,
-    bhs_state_key_t * key_ptr,
+    bhs_state_key_value_pair_t * key_ptr,
     bhs_state_key_value_pair_t * result
     )
 {
-    result->key = (*key_ptr);
-    tchdbget3(hash->hash, key_ptr, sizeof(*key_ptr), &(result->value), sizeof(result->value));
+    result->key = key_ptr->key;
+    tchdbget3(hash->hash, &(key_ptr->key), sizeof(key_ptr->key), &(result->value), sizeof(result->value));
 
     return;
 }
-    
+
 #ifdef __cplusplus
 }
 #endif