diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-10-31 03:15:28 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-10-31 03:15:28 -0300 |
| commit | 55174a28581c33c4b6d91066086a2ee7b5c663ea (patch) | |
| tree | fedb78bf66dd114eedc358ca385cf5f01a65ae0e /lib/kernel/SubstantialRelation.ml | |
| parent | a8cd08bfe473f01f245a4808e63809ed1cddc0e7 (diff) | |
| download | RNT-55174a28581c33c4b6d91066086a2ee7b5c663ea.tar.gz RNT-55174a28581c33c4b6d91066086a2ee7b5c663ea.zip | |
bencode helpers between dicts and string maps
Diffstat (limited to '')
| -rw-r--r-- | lib/kernel/SubstantialRelation.ml | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/lib/kernel/SubstantialRelation.ml b/lib/kernel/SubstantialRelation.ml index e89b008..f269686 100644 --- a/lib/kernel/SubstantialRelation.ml +++ b/lib/kernel/SubstantialRelation.ml @@ -81,22 +81,15 @@ module Make (S : Abstract.Storage.STORAGE) = struct let open Concepts.Encoding in [ "schema", Value.bencode_of_hash schematics; "tuples", Value.bencode_of_hash tuples; - ( "indexes", - Bencode.Dict - (BatMap.String.bindings indexes |> List.map (fun (a, h) -> a, Value.bencode_of_hash h)) - ) ] + "indexes", Bencode.of_map Value.bencode_of_hash indexes ] let of_fields fields = let open Utilities.Result in let open Concepts.Encoding in let* schematics = Bencode.field "schema" fields |>> Value.hash_of_bencode in let* tuples = Bencode.field "tuples" fields |>> Value.hash_of_bencode in - let* indexes = Bencode.field "indexes" fields |>> Bencode.as_dict in - let* indexes = - List.map (fun (a, h) -> Value.hash_of_bencode h |> Result.map (fun h -> a, h)) indexes - |> Utilities.List.sequence - in - Ok {schematics; tuples; indexes= BatMap.String.of_list indexes} + let* indexes = Bencode.field "indexes" fields |>> Bencode.to_map Value.hash_of_bencode in + Ok {schematics; tuples; indexes} end let encode = Representation.to_blob @@ -109,23 +102,17 @@ module Make (S : Abstract.Storage.STORAGE) = struct let store_schema tx description = Concepts.Encoding.Bencode.( - Dict - ( BatMap.String.bindings description - |> List.map (fun (name, {Protocols.Schematics.domain; _}) -> name, String domain) ) - |> to_blob ) + of_map (fun {Protocols.Schematics.domain; _} -> String domain) description |> to_blob ) |> SI.store_blob tx let schema_of tx schematics = let open Utilities.Result in + let open Concepts.Encoding in let* data = SI.get_req tx (S.Hash schematics) in - let* fields = Concepts.Encoding.Bencode.of_blob data in - let* kvs = Concepts.Encoding.Bencode.as_dict fields in - kvs - |> List.map (fun (name, domain) -> - Concepts.Encoding.Bencode.as_string domain - |> Result.map (fun domain -> name, {Protocols.Schematics.domain; provenance= []}) ) - |> Utilities.List.sequence - |> Result.map BatMap.String.of_list + Bencode.of_blob data + |>> Bencode.to_map (fun domain -> + Bencode.as_string domain + |> Result.map (fun domain -> {Protocols.Schematics.domain; provenance= []}) ) let prefix value = Concepts.Encoding.Bencode.to_bytes (Concepts.Tuple.bencode_of_value value) |
