Commits

Anonymous committed 81a2487

Now storing the struct in a hash item instead of a pointer.

Formerly, it just wasted space.

  • Participants
  • Parent commits 0962122

Comments (0)

Files changed (3)

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

     bhs_state_key_value_pair_t next_state_raw;
 #define next_state (&(next_state_raw))
 #else
-    void * init_state_existing;
+    bhs_state_key_value_pair_t * init_state_existing;
     bhs_state_key_value_pair_t * next_state;
 #endif
 #define state (&(state_raw))
     if (! solver->states_in_solution)
     {
         bhs_state_key_value_pair_t * states;
-        bhs_state_key_t * key_ptr;
+        bhs_state_key_value_pair_t * key_ptr;
         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;
+        bhs_state_key_value_pair_t * next_state;
 #endif
 
         num_states = 0;
                     );
             }
          
-            key_ptr = &(states[num_states].value.parent_state);
+            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,
                 &next_state,
-                perl_hash_function((ub1 *)key_ptr, sizeof(*key_ptr))
+                perl_hash_function((ub1 *)key_ptr, sizeof(key_ptr->key))
             );
 
             memcpy(

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

 
 fcs_bool_t bh_solve_hash_insert(
     bh_solve_hash_t * hash,
-    void * key,
-    void * * existing_key,
+    bhs_state_key_value_pair_t * key,
+    bhs_state_key_value_pair_t * * existing_key,
     bh_solve_hash_value_t hash_value
 #ifdef FCS_ENABLE_SECONDARY_HASH_VALUE
     , bh_solve_hash_value_t secondary_hash_value
                 comparing the entire data structure.
             */
             if (
-                (!memcmp(item->key, key, sizeof(bhs_state_key_t)))
+                (!memcmp(&(item->key.key), &(key->key), sizeof(bhs_state_key_t)))
                )
             {
-                *existing_key = item->key;
+                *existing_key = &(item->key);
 
                 return TRUE;
             }
 
     /* Put the new element at the end of the list */
     /* Do an in-order insertion. */
-    item->key = key;
+    item->key = (*key);
     item->hash_value = hash_value;
 #ifdef FCS_ENABLE_SECONDARY_HASH_VALUE
     item->secondary_hash_value = secondary_hash_value;

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

 
 #include "inline.h"
 #include "bool.h"
+#include "state.h"
 
 #ifdef FCS_INLINED_HASH_COMPARISON
 enum FCS_INLINED_HASH_DATA_TYPE
 struct bh_solve_hash_symlink_item_struct
 {
     /* A pointer to the data structure that is to be collected */
-    void * key;
+    bhs_state_key_value_pair_t key;
     /* We also store the hash value corresponding to this key for faster
        comparisons */
     bh_solve_hash_value_t hash_value;
  */
 extern fcs_bool_t bh_solve_hash_insert(
     bh_solve_hash_t * hash,
-    void * key,
-    void * * existing_key,
+    bhs_state_key_value_pair_t * key,
+    bhs_state_key_value_pair_t * * existing_key,
     bh_solve_hash_value_t hash_value
 #ifdef FCS_ENABLE_SECONDARY_HASH_VALUE
     , bh_solve_hash_value_t secondary_hash_value