From d4ac1389e30dfdb7809f8f7a9194c473af9568ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Fri, 29 Sep 2017 18:43:13 +0200 Subject: [PATCH] Shell: add comparison operators to `Tezos_data` --- src/environment/v1/tezos_data.mli | 9 +++++++ src/utils/tezos_data.ml | 45 +++++++++++++++++++++++++++++++ src/utils/tezos_data.mli | 9 +++++++ 3 files changed, 63 insertions(+) diff --git a/src/environment/v1/tezos_data.mli b/src/environment/v1/tezos_data.mli index f6f1e1af0..38d39cfd3 100644 --- a/src/environment/v1/tezos_data.mli +++ b/src/environment/v1/tezos_data.mli @@ -14,6 +14,15 @@ module type DATA = sig val compare: t -> t -> int val equal: t -> t -> bool + val (=): t -> t -> bool + val (<>): t -> t -> bool + val (<): t -> t -> bool + val (<=): t -> t -> bool + val (>=): t -> t -> bool + val (>): t -> t -> bool + val min: t -> t -> t + val max: t -> t -> t + val pp: Format.formatter -> t -> unit val encoding: t Data_encoding.t diff --git a/src/utils/tezos_data.ml b/src/utils/tezos_data.ml index cec0c32db..b59dc3703 100644 --- a/src/utils/tezos_data.ml +++ b/src/utils/tezos_data.ml @@ -16,6 +16,15 @@ module type DATA = sig val compare: t -> t -> int val equal: t -> t -> bool + val (=): t -> t -> bool + val (<>): t -> t -> bool + val (<): t -> t -> bool + val (<=): t -> t -> bool + val (>=): t -> t -> bool + val (>): t -> t -> bool + val min: t -> t -> t + val max: t -> t -> t + val pp: Format.formatter -> t -> unit val encoding: t Data_encoding.t @@ -71,6 +80,15 @@ module Fitness = struct let equal f1 f2 = compare f1 f2 = 0 + let (=) = equal + let (<>) x y = compare x y <> 0 + let (<) x y = compare x y < 0 + let (<=) x y = compare x y <= 0 + let (>=) x y = compare x y >= 0 + let (>) x y = compare x y > 0 + let min x y = if x <= y then x else y + let max x y = if x <= y then y else x + let rec pp fmt = function | [] -> () | [f] -> Format.fprintf fmt "%s" (Hex_encode.hex_of_bytes f) @@ -128,6 +146,15 @@ module Operation = struct MBytes.compare o1.proto o2.proto let equal b1 b2 = compare b1 b2 = 0 + let (=) = equal + let (<>) x y = compare x y <> 0 + let (<) x y = compare x y < 0 + let (<=) x y = compare x y <= 0 + let (>=) x y = compare x y >= 0 + let (>) x y = compare x y > 0 + let min x y = if x <= y then x else y + let max x y = if x <= y then y else x + let to_bytes v = Data_encoding.Binary.to_bytes encoding v let of_bytes b = Data_encoding.Binary.of_bytes encoding b let of_bytes_exn b = Data_encoding.Binary.of_bytes_exn encoding b @@ -214,6 +241,15 @@ module Block_header = struct let equal b1 b2 = compare b1 b2 = 0 + let (=) = equal + let (<>) x y = compare x y <> 0 + let (<) x y = compare x y < 0 + let (<=) x y = compare x y <= 0 + let (>=) x y = compare x y >= 0 + let (>) x y = compare x y > 0 + let min x y = if x <= y then x else y + let max x y = if x <= y then y else x + let to_bytes v = Data_encoding.Binary.to_bytes encoding v let of_bytes b = Data_encoding.Binary.of_bytes encoding b let of_bytes_exn b = Data_encoding.Binary.of_bytes_exn encoding b @@ -273,6 +309,15 @@ module Protocol = struct let compare = Pervasives.compare let equal = (=) + let (=) = equal + let (<>) x y = compare x y <> 0 + let (<) x y = compare x y < 0 + let (<=) x y = compare x y <= 0 + let (>=) x y = compare x y >= 0 + let (>) x y = compare x y > 0 + let min x y = if x <= y then x else y + let max x y = if x <= y then y else x + let to_bytes v = Data_encoding.Binary.to_bytes encoding v let of_bytes b = Data_encoding.Binary.of_bytes encoding b let of_bytes_exn b = Data_encoding.Binary.of_bytes_exn encoding b diff --git a/src/utils/tezos_data.mli b/src/utils/tezos_data.mli index 0898822d5..3a5802f58 100644 --- a/src/utils/tezos_data.mli +++ b/src/utils/tezos_data.mli @@ -16,6 +16,15 @@ module type DATA = sig val compare: t -> t -> int val equal: t -> t -> bool + val (=): t -> t -> bool + val (<>): t -> t -> bool + val (<): t -> t -> bool + val (<=): t -> t -> bool + val (>=): t -> t -> bool + val (>): t -> t -> bool + val min: t -> t -> t + val max: t -> t -> t + val pp: Format.formatter -> t -> unit val encoding: t Data_encoding.t