aboutsummaryrefslogtreecommitdiffstats
path: root/lib/merkle.ml
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-04-03 16:17:38 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-04-03 16:17:38 -0300
commit63ae3c930de89af6f85229a467caa3f53cb844a2 (patch)
treecda4d513672f9fefa09c3a1dff69d8443890e224 /lib/merkle.ml
parentc5bc3a4992b4968780c286a084ad7c02b2b58f1e (diff)
downloadSakura-63ae3c930de89af6f85229a467caa3f53cb844a2.tar.gz
Sakura-63ae3c930de89af6f85229a467caa3f53cb844a2.zip
format
Diffstat (limited to 'lib/merkle.ml')
-rw-r--r--lib/merkle.ml41
1 files changed, 17 insertions, 24 deletions
diff --git a/lib/merkle.ml b/lib/merkle.ml
index ffa7171..6c4be52 100644
--- a/lib/merkle.ml
+++ b/lib/merkle.ml
@@ -2,57 +2,52 @@
This is an opaque interface that can be backed by different implementations:
- A simple hash set (current placeholder)
- - A proper radix/patricia merkle tree (e.g., plebeia when OCaml 5 support arrives)
+ - A proper radix/patricia merkle tree (e.g., plebeia when OCaml 5 support
+ arrives)
- The tree stores hashes as keys (like a set) and computes a root hash
- from all contained elements. *)
+ The tree stores hashes as keys (like a set) and computes a root hash from
+ all contained elements. *)
module type S = sig
type t
- (** The empty tree *)
val empty : t
+ (** The empty tree *)
- (** Check if tree is empty *)
val is_empty : t -> bool
+ (** Check if tree is empty *)
- (** Insert a hash into the tree. Returns a new tree. *)
val insert : Conventions.Hash.t -> t -> t
+ (** Insert a hash into the tree. Returns a new tree. *)
- (** Delete a hash from the tree. Returns a new tree. *)
val delete : Conventions.Hash.t -> t -> t
+ (** Delete a hash from the tree. Returns a new tree. *)
- (** Check if a hash is in the tree *)
val member : Conventions.Hash.t -> t -> bool
+ (** Check if a hash is in the tree *)
- (** Get all hashes in the tree *)
val keys : t -> Conventions.Hash.t list
+ (** Get all hashes in the tree *)
- (** Compute the root hash of the tree. None if empty. *)
val root_hash : t -> Conventions.Hash.t option
+ (** Compute the root hash of the tree. None if empty. *)
- (** Number of elements in the tree *)
val size : t -> int
+ (** Number of elements in the tree *)
end
-(** Simple hash set implementation.
- This is a placeholder until a proper radix-merkle library
- with OCaml 5 support becomes available. *)
+(** Simple hash set implementation. This is a placeholder until a proper
+ radix-merkle library with OCaml 5 support becomes available. *)
module HashSet : S = struct
- module StringSet = Set.Make(String)
+ module StringSet = Set.Make (String)
type t = StringSet.t
let empty = StringSet.empty
-
let is_empty = StringSet.is_empty
-
let insert hash tree = StringSet.add hash tree
-
let delete hash tree = StringSet.remove hash tree
-
let member hash tree = StringSet.mem hash tree
-
let keys tree = StringSet.elements tree
(* TODO: Streaming/pagination for large tuple sets. Currently materializes
entire keyset into memory, which fails for relations with billions of tuples.
@@ -60,10 +55,8 @@ module HashSet : S = struct
to avoid loading all hashes upfront. Consider replacing HashSet with proper
radix-merkle tree (plebeia) for native lazy traversal. *)
-
let root_hash tree =
- if StringSet.is_empty tree then
- None
+ if StringSet.is_empty tree then None
else
(* Compute root hash by hashing sorted concatenation of all hashes *)
let sorted_hashes = StringSet.elements tree in
@@ -73,5 +66,5 @@ module HashSet : S = struct
let size = StringSet.cardinal
end
-(** Default implementation using HashSet *)
include HashSet
+(** Default implementation using HashSet *)