Skip to content

Commit

Permalink
Use equal instead of = in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Evans committed Feb 3, 2023
1 parent a8cc3a1 commit ff4c07a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
11 changes: 7 additions & 4 deletions bootstrap/bin/hocc/attribs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,25 @@ end
module Aval = struct
module T = struct
type t = {
ergo_lr1itemset: Lr1Itemset.t;
ergo_lr1itemset: Lr1Itemset.t; (* Only the core matters for `hash_fold`/`cmp`/`equal`. *)
contrib: Contrib.t;
}

let hash_fold {ergo_lr1itemset; contrib} state =
state
|> Uns.hash_fold 0L |> Lr1Itemset.hash_fold ergo_lr1itemset
|> Uns.hash_fold 0L |> Lr0Itemset.hash_fold (Lr1Itemset.core ergo_lr1itemset)
|> Uns.hash_fold 1L |> Contrib.hash_fold contrib

let cmp {ergo_lr1itemset=e0; contrib=c0} {ergo_lr1itemset=e1; contrib=c1} =
let open Cmp in
match Lr1Itemset.cmp e0 e1 with
match Lr0Itemset.cmp (Lr1Itemset.core e0) (Lr1Itemset.core e1) with
| Lt -> Lt
| Eq -> Contrib.cmp c0 c1
| Gt -> Gt

let equal {ergo_lr1itemset=e0; contrib=c0} {ergo_lr1itemset=e1; contrib=c1} =
Lr0Itemset.equal (Lr1Itemset.core e0) (Lr1Itemset.core e1) && Contrib.equal c0 c1

let pp {ergo_lr1itemset; contrib} formatter =
formatter
|> Fmt.fmt "{ergo_lr1itemset=" |> Lr1Itemset.pp ergo_lr1itemset
Expand Down Expand Up @@ -122,7 +125,7 @@ include Identifiable.Make(T)
let length = Ordmap.length

let equal t0 t1 =
Ordmap.equal (fun (_akey0, aval0) (_akey1, aval1) -> Aval.(=) aval0 aval1) t0 t1
Ordmap.equal (fun (_akey0, aval0) (_akey1, aval1) -> Aval.equal aval0 aval1) t0 t1

module Seq = struct
type container = t
Expand Down
3 changes: 3 additions & 0 deletions bootstrap/bin/hocc/contrib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ module T = struct
| Eq -> Ordset.cmp r0 r1
| Gt -> Gt

let equal {shift=s0; reduce=r0} {shift=s1; reduce=r1} =
Bool.(s0 = s1) && Ordset.equal r0 r1

let pp {shift; reduce} formatter =
formatter
|> Fmt.fmt "{shift=" |> Bool.pp shift
Expand Down
2 changes: 2 additions & 0 deletions bootstrap/bin/hocc/contrib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type t

include IdentifiableIntf.S with type t := t

val equal: t -> t -> bool

val pp_hr: Symbols.t -> Prods.t -> t -> (module Fmt.Formatter) -> (module Fmt.Formatter)
(** Formatter which outputs contrib in human-readable form. *)

Expand Down
2 changes: 2 additions & 0 deletions bootstrap/bin/hocc/lr0Itemset.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ end
include T
include Identifiable.Make(T)

let equal = Ordset.equal

let empty = Ordset.empty (module Lr0Item)

let singleton lr0item =
Expand Down
2 changes: 2 additions & 0 deletions bootstrap/bin/hocc/lr0Itemset.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type t = (Lr0Item.t, Lr0Item.cmper_witness) Ordset.t

include IdentifiableIntf.S with type t := t

val equal: t -> t -> bool

val empty: t

val singleton: Lr0Item.t -> t
Expand Down

0 comments on commit ff4c07a

Please sign in to comment.