aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/BranchIndex.ml
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-08-01 14:22:05 -0300
committerGitHub <noreply@github.com>2026-08-01 14:22:05 -0300
commitd512411992a6a2b50fcdf03689129f70f530116f (patch)
tree03c0cec59ae2bfd20ef5af00e6a01bb2fe5dab2d /lib/kernel/BranchIndex.ml
parent117fe888ef9325dbc6965e36c38e40c92d7bc1ee (diff)
downloadRNT-d512411992a6a2b50fcdf03689129f70f530116f.tar.gz
RNT-d512411992a6a2b50fcdf03689129f70f530116f.zip
Initialization with Branch State and Index
Diffstat (limited to '')
-rw-r--r--lib/kernel/BranchIndex.ml29
-rw-r--r--lib/kernel/BranchIndex.mli28
2 files changed, 57 insertions, 0 deletions
diff --git a/lib/kernel/BranchIndex.ml b/lib/kernel/BranchIndex.ml
new file mode 100644
index 0000000..d1efa9a
--- /dev/null
+++ b/lib/kernel/BranchIndex.ml
@@ -0,0 +1,29 @@
+type address = Concepts.Hash.hash
+type root = address
+type branch_name = string
+type branch_state_root = address
+
+let default_branch_name = "master"
+
+module Branch_name = struct
+ type t = branch_name
+
+ let encode name = Concepts.Codec.Bencode.(String name |> to_blob)
+ let compare left right = Concepts.Ordering.of_int (String.compare left right)
+
+ let decode blob =
+ Concepts.Codec.Bencode.of_blob blob |> Utilities.Result.fmap Concepts.Codec.Bencode.as_string
+end
+
+module Make (Store : Abstract.Storage.STORAGE) = struct
+ module Tree = Merkle.Make (Store) (Branch_name)
+
+ type tree = Tree.node
+
+ let empty = Tree.empty
+ let hash_of = Tree.hash_of
+ let persist = Tree.persist
+ let find = Tree.find
+ let find_branch = Tree.lookup
+ let put_branch = Tree.insert
+end
diff --git a/lib/kernel/BranchIndex.mli b/lib/kernel/BranchIndex.mli
new file mode 100644
index 0000000..5a867bf
--- /dev/null
+++ b/lib/kernel/BranchIndex.mli
@@ -0,0 +1,28 @@
+type address = Concepts.Hash.hash
+type root = address
+type branch_name = string
+type branch_state_root = address
+
+val default_branch_name : branch_name
+
+module Make (Store : Abstract.Storage.STORAGE) : sig
+ type tree
+
+ val empty : tree
+ val hash_of : tree -> root
+ val persist : Store.transaction -> tree -> (root, Concepts.Condition.condition) result
+ val find : Store.transaction -> root -> (tree option, Concepts.Condition.condition) result
+
+ val find_branch :
+ Store.transaction ->
+ branch_name ->
+ tree ->
+ (branch_state_root option, Concepts.Condition.condition) result
+
+ val put_branch :
+ Store.transaction ->
+ branch_name ->
+ branch_state_root ->
+ tree ->
+ (tree, Concepts.Condition.condition) result
+end