From 3b4556e23f19272e0f63d316842c887365676568 Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Sat, 22 Mar 2025 20:55:14 -0300 Subject: fix commit updates --- lib/disk.ml | 16 ++++--- lib/relation.ml | 138 +++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 101 insertions(+), 53 deletions(-) (limited to 'lib') diff --git a/lib/disk.ml b/lib/disk.ml index 7d53f77..9742216 100644 --- a/lib/disk.ml +++ b/lib/disk.ml @@ -80,8 +80,8 @@ module FileSystem (C : Configuration) : FileSystem = struct end module Executor = struct - module StringMap = Map.Make (String) - module IntMap = Map.Make (Int64) + module StringMap = Map.Make (String) [@@deriving show] + module IntMap = Map.Make (Int64) [@@deriving show] module FS = FileSystem (DevelopmentConfiguration) module Location = struct @@ -388,17 +388,16 @@ module Command = struct commit.references in Ok - ( (commit, locations, references), + ( ({ commit with references }, locations), ComputedHash computed_hash_handle ) | Some _, None -> Error "Cannot write an entity without its referential." - | None, _ -> Ok ((commit, locations, commit.references), Nothing)) + | None, _ -> Ok ((commit, locations), Nothing)) | READ -> let relation_name = List.hd @@ String.split_on_char '/' command.filename in - print_endline "READ"; - print_endline relation_name; + print_endline @@ "READ: " ^ relation_name; let entities : string list Executor.IntMap.t = print_endline command.filename; Executor.StringMap.find_opt command.filename commit.references @@ -413,6 +412,8 @@ module Command = struct let content = Executor.IntMap.fold (fun key hashes acc -> + print_string "KEY: "; + print_endline @@ Int64.to_string key; ( key, List.map (fun location -> @@ -423,6 +424,7 @@ module Command = struct in (* print_string "CONTENT: "; *) (* print_endline @@ Bytes.to_string content; *) - Ok ((commit, locations, commit.references), Read content) + print_endline "------------------"; + Ok ((commit, locations), Read content) | _ -> Error "Unimplemented method" end diff --git a/lib/relation.ml b/lib/relation.ml index 275bd10..1ce67ae 100644 --- a/lib/relation.ml +++ b/lib/relation.ml @@ -1,3 +1,15 @@ +let print_references references = + Disk.Executor.StringMap.iter + (fun k v -> + print_endline ("→ " ^ k ^ ": "); + Disk.Executor.IntMap.iter + (fun k v -> + print_endline (" ↳ " ^ Int64.to_string k); + List.iter (fun v -> print_endline (" → " ^ v)) v) + v; + print_newline ()) + references + let write_and_retrieve () = let open Disk in let schema = @@ -39,9 +51,10 @@ let write_and_retrieve () = filename = "user/first-name"; } in - let+ (commit, locations, references), Command.ComputedHash handle11 = + let+ (commit, locations), Command.ComputedHash handle11 = Command.commit_and_perform commit locations command_write1 in + print_references commit.references; let command_write2 : Command.t = { kind = Command.WRITE; @@ -52,63 +65,106 @@ let write_and_retrieve () = filename = "user/last-name"; } in - let+ (commit, locations, references), Command.ComputedHash handle12 = + let+ (commit, locations), Command.ComputedHash handle12 = Command.commit_and_perform commit locations command_write2 in - let entity_id = 1L in - let command_write3 : Command.t = - { - kind = Command.WRITE; - timestamp = 10.0; - hash = ""; - content = "Minnie"; - entity_id = Some 1L; - filename = "user/first-name"; - } - in - let+ (commit, locations, references), Command.ComputedHash handle21 = - Command.commit_and_perform commit locations command_write3 - in - let command_write4 : Command.t = + print_references commit.references; + let command_write1_address : Command.t = { kind = Command.WRITE; timestamp = 10.0; hash = ""; - content = "Mouse"; - entity_id = Some 1L; - filename = "user/last-name"; + content = "Saint James St."; + entity_id = Some 0L; + filename = "address/street"; } in - let+ (commit, locations, references), Command.ComputedHash handle22 = - Command.commit_and_perform commit locations command_write4 + let+ (commit, locations), Command.ComputedHash handle12 = + Command.commit_and_perform commit locations command_write1_address in - let entity_id = 2L in - let command_write5 : Command.t = + print_references commit.references; + let command_write2_address : Command.t = { kind = Command.WRITE; timestamp = 10.0; hash = ""; - content = "Billie"; - entity_id = Some 2L; - filename = "user/first-name"; + content = "41"; + entity_id = Some 0L; + filename = "address/number"; } in - let+ (commit, locations, references), Command.ComputedHash handle31 = - Command.commit_and_perform commit locations command_write5 + let+ (commit, locations), Command.ComputedHash handle12 = + Command.commit_and_perform commit locations command_write2_address in - let command_write6 : Command.t = + print_references commit.references; + let command_write2_5 : Command.t = { kind = Command.WRITE; timestamp = 10.0; hash = ""; - content = "Beans"; - entity_id = Some 2L; - filename = "user/last-name"; + content = "0"; + entity_id = Some 0L; + filename = "user/address"; } in - let+ (commit, locations, references), Command.ComputedHash handle32 = - Command.commit_and_perform commit locations command_write6 - in + let+ (commit, locations), Command.ComputedHash handle12 = + Command.commit_and_perform commit locations command_write2_5 + in + print_references commit.references; + (* let entity_id = 1L in *) + (* let command_write3 : Command.t = *) + (* { *) + (* kind = Command.WRITE; *) + (* timestamp = 10.0; *) + (* hash = ""; *) + (* content = "Minnie"; *) + (* entity_id = Some 1L; *) + (* filename = "user/first-name"; *) + (* } *) + (* in *) + (* let+ (commit, locations, references), Command.ComputedHash handle21 = *) + (* Command.commit_and_perform commit locations command_write3 *) + (* in *) + (* let command_write4 : Command.t = *) + (* { *) + (* kind = Command.WRITE; *) + (* timestamp = 10.0; *) + (* hash = ""; *) + (* content = "Mouse"; *) + (* entity_id = Some 1L; *) + (* filename = "user/last-name"; *) + (* } *) + (* in *) + (* let+ (commit, locations, references), Command.ComputedHash handle22 = *) + (* Command.commit_and_perform commit locations command_write4 *) + (* in *) + (* let entity_id = 2L in *) + (* let command_write5 : Command.t = *) + (* { *) + (* kind = Command.WRITE; *) + (* timestamp = 10.0; *) + (* hash = ""; *) + (* content = "Billie"; *) + (* entity_id = Some 2L; *) + (* filename = "user/first-name"; *) + (* } *) + (* in *) + (* let+ (commit, locations, references), Command.ComputedHash handle31 = *) + (* Command.commit_and_perform commit locations command_write5 *) + (* in *) + (* let command_write6 : Command.t = *) + (* { *) + (* kind = Command.WRITE; *) + (* timestamp = 10.0; *) + (* hash = ""; *) + (* content = "Beans"; *) + (* entity_id = Some 2L; *) + (* filename = "user/last-name"; *) + (* } *) + (* in *) + (* let+ (commit, locations, references), Command.ComputedHash handle32 = *) + (* Command.commit_and_perform commit locations command_write6 *) + (* in *) let command_read : Command.t = { kind = Command.READ; @@ -122,16 +178,6 @@ let write_and_retrieve () = let+ _, (Command.Read content as response) = Command.commit_and_perform commit locations command_read in - Executor.StringMap.iter - (fun k v -> - print_endline ("→ " ^ k ^ ": "); - Executor.IntMap.iter - (fun k v -> - print_endline (" ↳ " ^ Int64.to_string k); - List.iter (fun v -> print_endline (" → " ^ v)) v) - v; - print_newline ()) - references; print_endline (Command.show_return response); Ok (commit, locations) [@@warning "-8-27-26"] -- cgit v1.2.3