package irmin
Irmin, a distributed database that follows the same design principles as Git
Install
Dune Dependency
Authors
Maintainers
Sources
irmin-3.4.2.tbz
sha256=964512f77697947a73dd1875c634d6804e98f14167c5aadd3c4f85b5f30ffb53
sha512=d56d3285daa2dd36f1eaff867af5c8f44c61bba4de1a5c7bb5347652dbc460c343483ab61de1a9302f664af357eacc964dc5c8b4477f6d01372dc028b162e98b
doc/src/irmin/lru.ml.html
Source file lru.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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
(* Copyright (c) 2016 David Kaloper Meršinjak Copyright (c) 2013-2022 Thomas Gazagnaire <thomas@gazagnaire.org> Permission to use, copy, modify, and/or 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. *) (* Extracted from https://github.com/pqwy/lru *) module Make (H : Hashtbl.HashedType) = struct module HT = Hashtbl.Make (H) module Q = struct type 'a node = { value : 'a; mutable next : 'a node option; mutable prev : 'a node option; } type 'a t = { mutable first : 'a node option; mutable last : 'a node option; } let detach t n = let np = n.prev and nn = n.next in (match np with | None -> t.first <- nn | Some x -> x.next <- nn; n.prev <- None); match nn with | None -> t.last <- np | Some x -> x.prev <- np; n.next <- None let append t n = let on = Some n in match t.last with | Some x as l -> x.next <- on; t.last <- on; n.prev <- l | None -> t.first <- on; t.last <- on let node x = { value = x; prev = None; next = None } let create () = { first = None; last = None } let iter t f = let rec aux f = function | Some n -> let next = n.next in f n.value; aux f next | _ -> () in aux f t.first let clear t = t.first <- None; t.last <- None end type key = HT.key type 'a t = { ht : (key * 'a) Q.node HT.t; q : (key * 'a) Q.t; mutable cap : int; mutable w : int; weight : 'a -> int; } let create ?(weight = function _ -> 1) cap = { cap; w = 0; ht = HT.create cap; q = Q.create (); weight } let drop_lru t = match t.q.first with | None -> () | Some ({ Q.value = k, v; _ } as n) -> t.w <- t.w - t.weight v; HT.remove t.ht k; Q.detach t.q n let remove t k = try let n = HT.find t.ht k in t.w <- t.w - t.weight (snd n.value); HT.remove t.ht k; Q.detach t.q n with Not_found -> () let add t k v = if t.cap = 0 then () else ( remove t k; let n = Q.node (k, v) in let w = t.weight v in if w > t.cap then (* if [v] is bigger than the LRU capacity, just skip it *) () else ( t.w <- t.w + w; while t.w > t.cap do drop_lru t done; HT.add t.ht k n; Q.append t.q n)) let promote t k = try let n = HT.find t.ht k in Q.( detach t.q n; append t.q n) with Not_found -> () let find t k = let v = HT.find t.ht k in promote t k; snd v.value let mem t k = match HT.mem t.ht k with | false -> false | true -> promote t k; true let iter t f = Q.iter t.q (fun (k, v) -> f k v) let clear t = t.w <- 0; HT.clear t.ht; Q.clear t.q end
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>