package xenstore
Xenstore protocol in pure OCaml
Install
Dune Dependency
github.com
Readme
Changelog
LGPL-2.1-only WITH OCaml-LGPL-linking-exception License
Edit opam file
Versions (2)
Authors
Maintainers
Sources
xenstore-2.3.0.tbz
sha256=d63c6bbcb2d3c297767d83c0a0f6dd46cecfd4e691f1cf5c5b6554445ec1b3f4
sha512=5cea990ab16ef708e53605172f708dde6ed15981cca6890939274db6efde1e5b2f9ec5c659d4d2f4115c5e0c3b69bcacc798a0d7fd5c1b75b83ddccd699de189
doc/src/xenstore.server/trie.ml.html
Source file trie.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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
(* * Copyright (C) Citrix Systems Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; version 2.1 only. with the special * exception on linking described in file LICENSE. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. *) module Node = struct type ('a,'b) t = { key: 'a; value: 'b option; children: ('a,'b) t list; } let empty key = { key = key; value = None; children = [] } let get_value node = match node.value with | None -> raise Not_found | Some value -> value let set_value node value = { node with value = Some value } let set_children node children = { node with children = children } end type ('a,'b) t = ('a,'b) Node.t list let mem_node nodes key = List.exists (fun n -> n.Node.key = key) nodes let find_node nodes key = List.find (fun n -> n.Node.key = key) nodes let replace_node nodes key node = let rec aux = function | [] -> [] | h :: tl when h.Node.key = key -> node :: tl | h :: tl -> h :: aux tl in aux nodes let remove_node nodes key = let rec aux = function | [] -> raise Not_found | h :: tl when h.Node.key = key -> tl | h :: tl -> h :: aux tl in aux nodes let create () = [] let rec iter f tree = let aux node = f node.Node.key node.Node.value; iter f node.Node.children in List.iter aux tree let rec map f tree = let aux node = let value = match node.Node.value with | None -> None | Some value -> f value in { node with Node.value = value; Node.children = map f node.Node.children } in List.filter (fun n -> n.Node.value <> None || n.Node.children <> []) (List.map aux tree) let rec fold f tree acc = let aux accu node = fold f node.Node.children (f node.Node.key node.Node.value accu) in List.fold_left aux acc tree (* return a sub-trie *) let rec sub_node tree = function | [] -> raise Not_found | h::t -> if mem_node tree h then begin let node = find_node tree h in if t = [] then node else sub_node node.Node.children t end else raise Not_found let sub tree path = try (sub_node tree path).Node.children with Not_found -> [] let find tree path = Node.get_value (sub_node tree path) (* return false if the node doesn't exists or if it is not associated to any value *) let rec mem tree = function | [] -> false | h::t -> mem_node tree h && (let node = find_node tree h in if t = [] then node.Node.value <> None else mem node.Node.children t) (* Iterate over the longest valid prefix *) let rec iter_path f tree = function | [] -> () | h::l -> if mem_node tree h then begin let node = find_node tree h in f node.Node.key node.Node.value; iter_path f node.Node.children l end let rec set_node node path value = if path = [] then Node.set_value node value else begin let children = set node.Node.children path value in Node.set_children node children end and set tree path value = match path with | [] -> raise Not_found | h::t -> if mem_node tree h then begin let node = find_node tree h in replace_node tree h (set_node node t value) end else begin let node = Node.empty h in set_node node t value :: tree end let rec unset tree = function | [] -> tree | h::t -> if mem_node tree h then begin let node = find_node tree h in let children = unset node.Node.children t in let new_node = if t = [] then Node.set_children (Node.empty h) children else Node.set_children node children in if children = [] && new_node.Node.value = None then remove_node tree h else replace_node tree h new_node end else raise Not_found
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>