move 2405 to use a hash table.
This commit is contained in:
@@ -1,19 +1,21 @@
|
|||||||
module IntSet = Set.Make (Int)
|
module IntSet = Set.Make (Int)
|
||||||
module IntMap = Map.Make (Int)
|
module IntHashtbl = Hashtbl.Make (Int)
|
||||||
|
|
||||||
(** [add_rule a b m] adds the rule that [a] must appear before [b] to the rule
|
(** [add_rule a b m] adds the rule that [a] must appear before [b] to the rule
|
||||||
map [m]. *)
|
map [m]. Returns the updated map [m] *)
|
||||||
let add_rule a b =
|
let add_rule a b m =
|
||||||
let update_rule = function
|
match IntHashtbl.find_opt m a with
|
||||||
| None -> Some (IntSet.singleton b)
|
| None ->
|
||||||
| Some s -> Some (IntSet.add b s)
|
IntHashtbl.add m a (IntSet.singleton b);
|
||||||
in
|
m
|
||||||
IntMap.update a update_rule
|
| Some s ->
|
||||||
|
IntHashtbl.replace m a (IntSet.add b s);
|
||||||
|
m
|
||||||
|
|
||||||
(** [find_rule a b m] returns [true] if the rule map [m] says that [a] should
|
(** [find_rule a b m] returns [true] if the rule map [m] says that [a] should
|
||||||
appear before [b]. *)
|
appear before [b]. *)
|
||||||
let find_rule a b m =
|
let find_rule a b m =
|
||||||
match IntMap.find_opt a m with
|
match IntHashtbl.find_opt m a with
|
||||||
| Some s -> ( match IntSet.find_opt b s with Some _ -> true | None -> false)
|
| Some s -> ( match IntSet.find_opt b s with Some _ -> true | None -> false)
|
||||||
| None -> false
|
| None -> false
|
||||||
|
|
||||||
@@ -51,7 +53,7 @@ let parse_rules =
|
|||||||
| [ a; b ] -> impl (add_rule a b acc) t
|
| [ a; b ] -> impl (add_rule a b acc) t
|
||||||
| _ -> failwith "parse_rules.impl")
|
| _ -> failwith "parse_rules.impl")
|
||||||
in
|
in
|
||||||
impl IntMap.empty
|
impl (IntHashtbl.create 17)
|
||||||
|
|
||||||
(** [parse_page_orders lst] parses a list of page orders. *)
|
(** [parse_page_orders lst] parses a list of page orders. *)
|
||||||
let parse_page_orders =
|
let parse_page_orders =
|
||||||
|
Reference in New Issue
Block a user