Something went wrong. Try again.
Git format in pure OCaml
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657(* Copyright (c) 2026 Thomas Gazagnaire <thomas@gazagnaire.org>
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. *)
(** Mutable maps from strings, iterated in the order of git's own [strmap].
Where git breaks a tie by the first entry its hash map yields (a directory rename's most frequent target, the order deferred directories are walked in), the same tie must break the same way here. This map keeps git's hashmap.c layout alongside the bindings: buckets indexed by the FNV-1 hash of the key, a new entry at the head of its bucket, sixty-four buckets at first, four times as many once more than eighty per cent are used and a quarter once fewer than a fifth of that are, a resize reversing each bucket's order. {!iter} walks the buckets in order. *)
type 'a t(** The type for maps from strings to ['a]. *)
val v : unit -> 'a t(** [v ()] is an empty map, as [strmap_init] makes one. *)
val strhash : string -> int(** [strhash s] is git's [strhash]: the 32-bit FNV-1 hash of the bytes of [s].*)
val find : 'a t -> string -> 'a option(** [find m k] is the binding of [k] in [m], if any. *)
val mem : 'a t -> string -> bool(** [mem m k] is [true] iff [k] is bound in [m]. *)
val replace : 'a t -> string -> 'a -> unit(** [replace m k v] binds [k] to [v]: in place when [k] is bound, as [strmap_put] does, and at the head of its bucket otherwise. *)
val remove : 'a t -> string -> unit(** [remove m k] unbinds [k], if it is bound. *)
val is_empty : 'a t -> bool(** [is_empty m] is [true] iff [m] binds nothing. *)
val iter : (string -> 'a -> unit) -> 'a t -> unit(** [iter f m] applies [f] to each binding of [m] in git's iteration order. *)
val to_list : 'a t -> (string * 'a) list(** [to_list m] is the bindings of [m] in git's iteration order. *)