Commits

shl...@b384bcd7-cfd4-0310-aca0-d78b80f7b91b  committed 312c2ea

Tokyo Cabinet backend now appears to work.

  • Participants
  • Parent commits 1bad83b

Comments (0)

Files changed (1)

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

 #define BUILDING_DLL 1
 #include "config.h"
 
+#include <assert.h>
+#include <stdlib.h>
+
 #if (BHS_STATE_STORAGE == BHS_STATE_STORAGE_TOKYO_CAB_HASH)
 
 #include "tokyo_cab_hash.h"
     bh_solve_hash_t * hash
     )
 {
+    int ecode;
+
     hash->hash = tchdbnew();
     tchdbsetcache(hash->hash, 128*1024);
-    tchdbopen(hash->hash, "bh_solve.hdb", HDBOWRITER|HDBOTRUNC|HDBOREADER);
+    if (!tchdbopen(hash->hash, "bh_solve.hdb", HDBOWRITER|HDBOTRUNC|HDBOCREAT))
+    {
+        ecode = tchdbecode(hash->hash);
+        fprintf(stderr, "Tokyo Cabinet open error: %s\n", tchdberrmsg(ecode));
+        exit(-1);
+    }
     return;
 }
 
     bhs_state_key_value_pair_t * key
 )
 {
-    return
-        !tchdbputkeep(
+    int ecode;
+
+    if (tchdbvsiz(hash->hash, &(key->key), sizeof(key->key)) < 0)
+    {
+        /* Record does not exist. */
+        if (!tchdbputkeep(
             hash->hash,
             &(key->key),
             sizeof(key->key),
             &(key->value),
             sizeof(key->value)
-            );
+            ))
+        {
+            ecode = tchdbecode(hash->hash);
+            fprintf(stderr, "Tokyo Cabinet putkeep error: %s\n", tchdberrmsg(ecode));
+            exit(-1);
+    
+        }
+        return FALSE;
+    }
+    else
+    {
+        return TRUE;
+    }
 }
 
 #else