Commit 5474a3ba authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Introduce [Lr1.tabulate] and [Lr1.sum]. Remove [Misc.tabulatef], now unneeded.

parent eee0d9d3
Pipeline #117434 passed with stages
in 25 seconds
......@@ -58,7 +58,7 @@ module C = Conflict (* artificial dependency; ensures that [Conflict] runs first
reductions, as they seem to be beneficial when explaining syntax errors. *)
let has_default_reduction : Lr1.node -> (Production.index * TerminalSet.t) option =
Misc.tabulatef Lr1.number Lr1.fold Lr1.n None (fun s ->
Lr1.tabulate (fun s ->
if Lr1.forbid_default_reduction s then
None
else
......@@ -74,9 +74,9 @@ let has_default_reduction : Lr1.node -> (Production.index * TerminalSet.t) optio
let () =
let count =
Lr1.fold (fun accu s ->
if has_default_reduction s = None then accu else accu + 1
) 0
Lr1.sum (fun s ->
if has_default_reduction s = None then 0 else 1
)
in
Error.logC 1 (fun f ->
Printf.fprintf f
......
......@@ -503,6 +503,12 @@ let iterx f =
| Some _ -> f node
)
let tabulate (f : node -> 'a) =
Misc.tabulate n f
let sum (f : node -> int) =
Misc.sum n f
(* -------------------------------------------------------------------------- *)
(* We build a map of each symbol to the (reachable) nodes that have this
......
......@@ -123,6 +123,11 @@ val fold: ('a -> node -> 'a) -> 'a -> 'a
val iter: (node -> unit) -> unit
val map: (node -> 'a) -> 'a list
(* Tabulation and sum of a function over nodes. *)
val tabulate: (node -> 'a) -> (node -> 'a)
val sum: (node -> int) -> int
(* Iteration over non-start nodes *)
val foldx: ('a -> node -> 'a) -> 'a -> 'a
val iterx: (node -> unit) -> unit
......
......@@ -46,16 +46,6 @@ let sum n (f : int -> int) : int =
done;
!sum
let tabulatef number fold n dummy f =
let a = Array.make n dummy in
let () = fold (fun () element ->
a.(number element) <- f element
) () in
let get element =
a.(number element)
in
get
type 'a iter = ('a -> unit) -> unit
let separated_iter_to_string printer separator iter =
......
......@@ -40,20 +40,6 @@ val tabulate: int -> (int -> 'a) -> (int -> 'a)
val sum: int -> (int -> int) -> int
(* [tabulatef number fold n dummy f] returns a function that is extensionally
equal to [f], but relies on an internal array. Arguments to [f] are of type
['a] and are mapped by [number] into the range [0..n). [fold] allows
folding over the domain of [f]. [dummy] is used to initialize the internal
array. Its value has no impact if [fold] is surjective. *)
val tabulatef:
('a -> int) ->
((unit -> 'a -> unit) -> unit -> unit) ->
int ->
'b ->
('a -> 'b) ->
('a -> 'b)
(* [separated_list_to_string printer sep l] converts [l] into a string
representation built by using [printer] on each element and [sep] as
a separator. *)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment