Commit 51576612c5700ed70d73e6493ccc14f37edab86b

Thomas de Grivel 2023-07-22T20:50:38

remove hashes

diff --git a/libc3/facts.c b/libc3/facts.c
index 529e9d9..726fe1f 100644
--- a/libc3/facts.c
+++ b/libc3/facts.c
@@ -23,7 +23,6 @@
 #include "facts.h"
 #include "facts_cursor.h"
 #include "facts_with.h"
-#include "hash.h"
 #include "log.h"
 #include "set__fact.h"
 #include "set__tag.h"
@@ -105,7 +104,6 @@ sw facts_dump (s_facts *facts, s_buf *buf)
 {
   s_facts_cursor cursor;
   s_fact *fact;
-  t_hash hash;
   s_tag predicate;
   s_tag object;
   sw r;
@@ -131,10 +129,8 @@ sw facts_dump (s_facts *facts, s_buf *buf)
   if ((r = buf_write_1(buf, "}\n")) < 0)
     goto ko;
   result += r;
-  hash_init(&hash);
   facts_with_0(facts, &cursor, &subject, &predicate, &object);
   while ((fact = facts_cursor_next(&cursor))) {
-    hash_update_fact(&hash, fact);
     if ((r = buf_inspect_fact(buf, fact)) < 0)
       goto ko;
     result += r;
@@ -142,18 +138,7 @@ sw facts_dump (s_facts *facts, s_buf *buf)
       goto ko;
     result += r;
   }
-  facts_lock_unlock_r(facts);
-  if ((r = buf_write_1(buf, "%{hash: 0x")) < 0)
-    return r;
-  result += r;
-  u = hash_to_u64(&hash);
-  if ((r = buf_inspect_u64_hexadecimal(buf, &u)) < 0)
-    return r;
-  result += r;
-  if ((r = buf_write_1(buf, "}\n")) < 0)
-    return r;
-  result += r;
-  return result;
+  r = result;
  ko:
   facts_lock_unlock_r(facts);
   return r;
@@ -235,9 +220,6 @@ sw facts_load (s_facts *facts, s_buf *buf, const s_str *path)
   u64 count;
   s_fact_w fact;
   s_fact *factp;
-  t_hash hash;
-  u64 hash_u64;
-  u64 hash_u64_buf;
   u64 i;
   sw r;
   sw result = 0;
@@ -255,14 +237,12 @@ sw facts_load (s_facts *facts, s_buf *buf, const s_str *path)
   if ((r = buf_read_1(buf, "}\n")) <= 0)
     goto ko_header;
   result += r;
-  hash_init(&hash);
   facts_lock_w(facts);
   for (i = 0; i < count; i++) {
     if ((r = buf_parse_fact(buf, &fact)) <= 0)
       goto ko_fact;
     result += r;
     factp = fact_r(&fact);
-    hash_update_fact(&hash, factp);
     facts_add_fact(facts, factp);
     fact_w_clean(&fact);
     if ((r = buf_read_1(buf, "\n")) <= 0) {
@@ -272,29 +252,7 @@ sw facts_load (s_facts *facts, s_buf *buf, const s_str *path)
     result += r;
   }
   facts_lock_unlock_w(facts);
-  hash_u64 = hash_to_u64(&hash);
-  if ((r = buf_read_1(buf, "%{hash: 0x")) <= 0)
-    goto ko_hash;
-  result += r;
-  if ((r = buf_parse_u64_hex(buf, &hash_u64_buf)) <= 0)
-    goto ko_hash;
-  result += r;
-  if ((r = buf_read_1(buf, "}\n")) <= 0)
-    goto ko_hash;
-  result += r;
   i++;
-  if (hash_u64_buf != hash_u64) {
-    s_buf tmp;
-    buf_init_alloc(&tmp, 16);
-    buf_inspect_u64_hexadecimal(&tmp, &hash_u64);
-    buf_write_s8(&tmp, 0);
-    warnx("facts_load: %s: invalid hash line %lu: 0x%s",
-          path->ptr.ps8,
-          (unsigned long) i + 5,
-          tmp.ptr.ps8);
-    buf_clean(&tmp);
-    return -1;
-  }
   return result;
  ko_header:
   warnx("facts_load: %s: invalid or missing header",
@@ -307,12 +265,6 @@ sw facts_load (s_facts *facts, s_buf *buf, const s_str *path)
         r ? "invalid" : "missing",
         (unsigned long) i + 5);
   return -1;
- ko_hash:
-  warnx("facts_load: %s: %s hash line %lu",
-        path->ptr.ps8,
-        r ? "invalid" : "missing",
-        (unsigned long) i + 5);
-  return -1;
 }
 
 sw facts_load_file (s_facts *facts, const s_str *path)
@@ -407,11 +359,9 @@ sw facts_log_add (s_log *log, const s_fact *fact)
   if ((r = buf_write_1(&log->buf, "add ")) < 0)
     return r;
   result += r;
-  hash_update_1(&log->hash, "add");
   if ((r = buf_inspect_fact(&log->buf, fact)) < 0)
     return r;
   result += r;
-  hash_update_fact(&log->hash, fact);
   if ((r = buf_write_1(&log->buf, "\n")) < 0)
     return r;
   result += r;
@@ -425,11 +375,9 @@ sw facts_log_remove (s_log *log, const s_fact *fact)
   if ((r = buf_write_1(&log->buf, "remove ")) < 0)
     return r;
   result += r;
-  hash_update_1(&log->hash, "remove");
   if ((r = buf_inspect_fact(&log->buf, fact)) < 0)
     return r;
   result += r;
-  hash_update_fact(&log->hash, fact);
   if ((r = buf_write_1(&log->buf, "\n")) < 0)
     return r;
   result += r;
diff --git a/test/facts_test.c b/test/facts_test.c
index 9cc32e6..3af999b 100644
--- a/test/facts_test.c
+++ b/test/facts_test.c
@@ -258,7 +258,7 @@ TEST_CASE(facts_load)
   s_str path;
   facts_init(&facts);
   str_init_1(&path, NULL, "facts_test_load_file.facts");
-  TEST_EQ(facts_load_file(&facts, &path), 708);
+  TEST_EQ(facts_load_file(&facts, &path), 681);
   TEST_EQ(facts_count(&facts), 23);
   while (p[i]) {
     fact_test_init_1(&fact, p[i]);
@@ -467,7 +467,7 @@ TEST_CASE(facts_open_file)
     errx(1, "%s:%i: cp", __FILE__, __LINE__);
   facts_init(&facts);
   str_init_1(&path, NULL, "facts_test_open_file.1.facts");
-  TEST_EQ(facts_open_file(&facts, &path), 747);
+  TEST_EQ(facts_open_file(&facts, &path), 720);
   TEST_EQ(facts_count(&facts), 23);
   i = 0;
   while (p[i]) {
@@ -497,7 +497,7 @@ TEST_CASE(facts_open_file)
   if (r > 0)
     errx(1, "%s:%i: cp", __FILE__, __LINE__);
   str_init_1(&path, NULL, "facts_test_open_file.2.facts");
-  TEST_EQ(facts_open_file(&facts, &path), 1480);
+  TEST_EQ(facts_open_file(&facts, &path), 1453);
   TEST_EQ(facts_count(&facts), 46);
   i = 0;
   while (p[i]) {
@@ -525,7 +525,7 @@ TEST_CASE(facts_open_file)
   if (r > 0)
     errx(1, "%s:%i: cp", __FILE__, __LINE__);
   str_init_1(&path, NULL, "facts_test_open_file.3.facts");
-  TEST_EQ(facts_open_file(&facts, &path), 1537);
+  TEST_EQ(facts_open_file(&facts, &path), 1510);
   TEST_EQ(facts_count(&facts), 0);
   i = 0;
   while (p[i]) {
diff --git a/test/facts_test_dump_file.expected.facts b/test/facts_test_dump_file.expected.facts
index ecdb52e..c9313c8 100644
--- a/test/facts_test_dump_file.expected.facts
+++ b/test/facts_test_dump_file.expected.facts
@@ -24,4 +24,3 @@
 {{:a, :b}, {:a, :b}, {:a, :b}}
 {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
 {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x8dd94636f1eb189}
diff --git a/test/facts_test_load_file.facts b/test/facts_test_load_file.facts
index ecdb52e..c9313c8 100644
--- a/test/facts_test_load_file.facts
+++ b/test/facts_test_load_file.facts
@@ -24,4 +24,3 @@
 {{:a, :b}, {:a, :b}, {:a, :b}}
 {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
 {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x8dd94636f1eb189}
diff --git a/test/facts_test_open_file.1.expected.facts b/test/facts_test_open_file.1.expected.facts
index cb71f14..26b031d 100644
--- a/test/facts_test_open_file.1.expected.facts
+++ b/test/facts_test_open_file.1.expected.facts
@@ -26,7 +26,6 @@
 {{:a, :b}, {:a, :b}, {:a, :b}}
 {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
 {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x8dd94636f1eb189}
 remove {"a", "a", "a"}
 remove {:a, :a, :a}
 remove {A, A, A}
diff --git a/test/facts_test_open_file.1.in.facts b/test/facts_test_open_file.1.in.facts
index b258c9a..fd5bd92 100644
--- a/test/facts_test_open_file.1.in.facts
+++ b/test/facts_test_open_file.1.in.facts
@@ -26,4 +26,3 @@
 {{:a, :b}, {:a, :b}, {:a, :b}}
 {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
 {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x8dd94636f1eb189}
diff --git a/test/facts_test_open_file.2.expected.facts b/test/facts_test_open_file.2.expected.facts
index 64e3432..bd9dd81 100644
--- a/test/facts_test_open_file.2.expected.facts
+++ b/test/facts_test_open_file.2.expected.facts
@@ -26,7 +26,6 @@
 {{:a, :b}, {:a, :b}, {:a, :b}}
 {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
 {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x8dd94636f1eb189}
 add {b, b, b}
 add {-18446744073709551617, -18446744073709551617, -18446744073709551617}
 add {18446744073709551617, 18446744073709551617, 18446744073709551617}
diff --git a/test/facts_test_open_file.2.in.facts b/test/facts_test_open_file.2.in.facts
index 64e3432..bd9dd81 100644
--- a/test/facts_test_open_file.2.in.facts
+++ b/test/facts_test_open_file.2.in.facts
@@ -26,7 +26,6 @@
 {{:a, :b}, {:a, :b}, {:a, :b}}
 {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
 {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x8dd94636f1eb189}
 add {b, b, b}
 add {-18446744073709551617, -18446744073709551617, -18446744073709551617}
 add {18446744073709551617, 18446744073709551617, 18446744073709551617}
diff --git a/test/facts_test_open_file.3.expected.facts b/test/facts_test_open_file.3.expected.facts
index 288e66b..609d6eb 100644
--- a/test/facts_test_open_file.3.expected.facts
+++ b/test/facts_test_open_file.3.expected.facts
@@ -26,7 +26,6 @@
 {{:a, :b}, {:a, :b}, {:a, :b}}
 {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
 {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x8dd94636f1eb189}
 remove {a, a, a}
 remove {-18446744073709551616, -18446744073709551616, -18446744073709551616}
 remove {18446744073709551616, 18446744073709551616, 18446744073709551616}
diff --git a/test/facts_test_open_file.3.in.facts b/test/facts_test_open_file.3.in.facts
index cbe7f0c..2b80171 100644
--- a/test/facts_test_open_file.3.in.facts
+++ b/test/facts_test_open_file.3.in.facts
@@ -26,7 +26,6 @@
 {{:a, :b}, {:a, :b}, {:a, :b}}
 {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
 {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x8dd94636f1eb189}
 remove {a, a, a}
 remove {-18446744073709551616, -18446744073709551616, -18446744073709551616}
 remove {18446744073709551616, 18446744073709551616, 18446744073709551616}
diff --git a/test/facts_test_save.expected.facts b/test/facts_test_save.expected.facts
index b258c9a..fd5bd92 100644
--- a/test/facts_test_save.expected.facts
+++ b/test/facts_test_save.expected.facts
@@ -26,4 +26,3 @@
 {{:a, :b}, {:a, :b}, {:a, :b}}
 {{{a, b}, {c, d}}, {{a, b}, {c, d}}, {{a, b}, {c, d}}}
 {{{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}, {{:a, :b}, {:c, :d}}}
-%{hash: 0x8dd94636f1eb189}