class ['a, 'b] graph (edge_list: ('a * 'b) list) = let adjacency_list = Hashtbl.create (List.length edge_list) in let () = List.iter (fun (u, v) -> try (* it exists *) let nodes = Hashtbl.find adjacency_list u in Hashtbl.replace adjacency_list u (v :: nodes) with Not_found -> (* init the u -> v *) Hashtbl.add adjacency_list u [v] ) edge_list in object (* Create an adjacency list of at least "edge_list" size *) val adjacency_list = adjacency_list method aj = adjacency_list end