Select Git revision
imperativeBL.ml 20.19 KiB
open! DataStruct
module type S =
sig
type elt
val pqtree : elt PqTree.t
val index : elt -> int
end
module Make =
functor (T : S) ->
struct
open PqTree
type elt = T.elt
let max_nb_nodes = 3 * length T.pqtree
let pool = ref (Pool.make_int_pool max_nb_nodes)
let get_new_index () =
let (index, p) = Pool.get !pool in
pool := p;
index
let free_index index =
pool := Pool.free index !pool
type kind = L of T.elt | PNode | QNode
type status = Full | Partial | Empty
type node = int
let root = ref 0
let parent = Array.make max_nb_nodes None
let next = Array.make max_nb_nodes None
let previous = Array.make max_nb_nodes None
let leftmost_child = Array.make max_nb_nodes None
let rightmost_child = Array.make max_nb_nodes None
let kind = Array.make max_nb_nodes PNode
let nb_children = Array.make max_nb_nodes 0
let is_visited = Array.make max_nb_nodes false
let active_children = Array.make max_nb_nodes []
let status = Array.make max_nb_nodes Empty
let visited = ref []
let leaf = Array.make (length T.pqtree) (-1)
let clean_node node =
if is_visited.(node) then
begin
is_visited.(node) <- false;
active_children.(node) <- [];
status.(node) <- Empty
end
let clean () =
List.iter clean_node !visited;
visited := []
let free = free_index
let add_child ?(left_of=None) p child =
next.(child) <- left_of;
parent.(child) <- Some p;
nb_children.(p) <- nb_children.(p) + 1;