package irmin-pack
Irmin backend which stores values in a pack file
Install
Dune Dependency
Authors
Maintainers
Sources
irmin-3.3.1.tbz
sha256=535254ca443858bfc9e540535977fed63e9206d4b78c5cac0239d1e6657b5c78
sha512=fa18557fcf808121a0495de707c6f7bff4a69197b310480816648adafd4a659b5673a1f5bbf4574f517b7d93253735ef7798b0c365d87afac60675007ef19b54
doc/src/irmin-pack/pack_key.ml.html
Source file pack_key.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
(* * Copyright (c) 2018-2021 Tarides <contact@tarides.com> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) open! Import include Pack_key_intf type 'hash state = | Direct of { hash : 'hash; offset : int63; length : int } | Indexed of 'hash type 'hash t = { mutable state : 'hash state } let inspect t = t.state let to_hash t = match t.state with Direct t -> t.hash | Indexed h -> h let promote_exn t ~offset ~length = let () = match t.state with | Direct _ -> Fmt.failwith "Attempted to promote a key that is already Direct" | Indexed _ -> () in t.state <- Direct { hash = to_hash t; offset; length } let t : type h. h Irmin.Type.t -> h t Irmin.Type.t = fun hash_t -> let open Irmin.Type in variant "t" (fun direct indexed t -> match t.state with | Direct { hash; offset; length } -> direct (hash, offset, length) | Indexed x1 -> indexed x1) |~ case1 "Direct" [%typ: hash * int63 * int] (fun (hash, offset, length) -> { state = Direct { hash; offset; length } }) |~ case1 "Indexed" [%typ: hash] (fun x1 -> { state = Indexed x1 }) |> sealv let t (type hash) (hash_t : hash Irmin.Type.t) = let module Hash = struct type t = hash [@@deriving irmin ~equal ~compare ~pre_hash ~encode_bin ~decode_bin] let unboxed_encode_bin = Irmin.Type.(unstage (Unboxed.encode_bin t)) let unboxed_decode_bin = Irmin.Type.(unstage (Unboxed.decode_bin t)) let encoded_size = match Irmin.Type.Size.of_value t with | Static n -> n | Dynamic _ | Unknown -> Fmt.failwith "Hash must have a fixed-width binary encoding" end in (* Equality and ordering on keys respects {i structural} equality semantics, meaning two objects (containing keys) are considered equal even if their children are stored at different offsets (either as duplicates in the same pack file, or inside different pack files), or with different lengths (in the event that the encoding environments were different). *) let equal a b = Hash.equal (to_hash a) (to_hash b) in let compare a b = Hash.compare (to_hash a) (to_hash b) in (* The pre-hash image of a key is just the hash of the corresponding value. NOTE: it's particularly important that we discard the file offset when computing hashes of structured values (e.g. inodes), so that this hashing process is reproducible in different stores (w/ different offsets for the values). *) let pre_hash t f = Hash.pre_hash (to_hash t) f in let encode_bin t f = Hash.encode_bin (to_hash t) f in let unboxed_encode_bin t f = Hash.unboxed_encode_bin (to_hash t) f in let decode_bin buf pos_ref = { state = Indexed (Hash.decode_bin buf pos_ref) } in let unboxed_decode_bin buf pos_ref = { state = Indexed (Hash.unboxed_decode_bin buf pos_ref) } in let size_of = Irmin.Type.Size.custom_static Hash.encoded_size in Irmin.Type.like (t hash_t) ~pre_hash ~equal ~compare ~bin:(encode_bin, decode_bin, size_of) ~unboxed_bin:(unboxed_encode_bin, unboxed_decode_bin, size_of) let v_direct ~hash ~offset ~length = { state = Direct { hash; offset; length } } let v_indexed hash = { state = Indexed hash } module type S = sig type hash include S with type t = hash t and type hash := hash end module Make (Hash : Irmin.Hash.S) = struct type nonrec t = Hash.t t [@@deriving irmin] type hash = Hash.t [@@deriving irmin ~of_bin_string] let to_hash = to_hash let null_offset = Int63.minus_one let null_length = -1 let null = let buf = String.make Hash.hash_size '\000' in let hash = match hash_of_bin_string buf with Ok x -> x | Error _ -> assert false in v_direct ~hash ~offset:null_offset ~length:null_length let unfindable_of_hash hash = v_direct ~hash ~offset:null_offset ~length:null_length end module type Store_spec = sig type ('h, _) contents_key = 'h t type 'h node_key = 'h t type 'h commit_key = 'h t end module rec Store_spec : Store_spec = Store_spec
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>