module H = Huffman;; type 'a t = Node of 'a * 'a list;; Node (3, []);; Node (3, [Node (1, [])]);; Node (3, [(Node (1, []))]);; let t = Node (1, []);; Node (1, [t]);; type 'a t = Node of 'a * 'a t list;; Node (3, []);; Node (3, [(Node (1, []))]);; Node (3, [(Node (1, [])); Node (2, [])]);; type 'a t = Empty | Node of 'a t * 'a * 'a t;; Empty;; t1;; t;; t = Empty;; Empty;; let t3 = Node (Empty, 3, Empty);; let t1 = Node (Empty, 1, Empty);; let t143 = Node (t1, 4, t3);; Node (t143, 0, t143);; let t = Node (t143, 0, t143);; let Node (l, _, r) = t;; let n = Node (t1, 4 t3);; let n = Node (t1, 4, t3);; n = l;; n == l;; r = l;; r == l;; let rec of_list = function [] -> Empty | h :: t -> Node (Empty, h, of_list t);; of_list [3;76;5;7;8;7;5;4];; let rec split_list = function h1 :: h2 :: t -> let (l1, l2) = split_list t in (h1 :: l1, h2 :: l2) | l -> ([], l);; split_list [2;5;4;6;5;6;7];; let rec of_list = function [] -> Empty | [e] -> Node (Empty, e, Empty) | l -> let (l1, h :: l2) = split_list l in Node (of_list l1, h, of_list l2);; of_list [3;3;4;5;6;7;8;6;45;3;4;5];; let t = of_list [3;3;4;5;6;7;8;6;45;3;4;5];; let rec size = function Empty -> 0 | Node (l, _, r) -> size l + size r + 1;; size t;; let rec height = function Empty -> 0 | Node (l, _, r) -> max (height l) (height r) + 1;; height t;; let rec insert e = function Empty -> Node (Empty, e, Empty) | Node (l, v, r) -> if compare e v < 0 then Node (insert e l, v, r) else Node (l, v, insert e r);; List.fold_left insert;; let insert l e = insert e l;; List.fold_left insert;; List.fold_left insert Empty;; let bst = List.fold_left insert Empty;; let rec flatten = function Empty -> [] | Node (l, v, r) -> (flatten l) @ (v :: (flatten r));; let sort l = flatten (bst l);; sort [3;6;5;7;5;43];; sort (IntLst.range 0 10000);; sort (List.rev (IntLst.range 0 10000));; Huffman.collate;; Huffman.collate "text";; Huffman.collate (Strng.of_string "text");; Huffman.collate (Strng.of_string "aasserertyyu");; Huffman.tree;; Huffman.tree (Strng.of_string "freaferfsrf";; Huffman.tree (Strng.of_string "freaferfsrf");; #install_printer Huffman.toplevel_printer;; Huffman.tree (Strng.of_string "freaferfsrf");; let tree = Huffman.tree (Strng.of_string "freaferfsrf");; Huffman.lookup;; Huffman.table tree;; List.map (Huffman.lookup (Huffman.table tree)) (Strng.of_string "freaferfsrf");; List.concat (List.map (Huffman.lookup (Huffman.table tree)) (Strng.of_string "freaferfsrf"));; List.length (List.concat (List.map (Huffman.lookup (Huffman.table tree)) (Strng.of_string "freaferfsrf")));;