From 582a8e61648d2e1b88fc61ab19654c9f2d40a5c8 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 16 Apr 2017 22:30:06 -0400 Subject: [PATCH] Replace the "equivalent" function with a "normalize"-based comparison. --- src/Cidr.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Cidr.hs b/src/Cidr.hs index 8991c7f..d071586 100644 --- a/src/Cidr.hs +++ b/src/Cidr.hs @@ -19,7 +19,7 @@ module Cidr normalize ) where -import Data.List (nubBy) +import Data.List (nub) import Data.List.Split (splitOneOf) import Data.Maybe (catMaybes, mapMaybe) @@ -58,14 +58,14 @@ instance Arbitrary Cidr where instance Eq Cidr where - cidr1 == cidr2 = (cidr1 `equivalent` cidr2) - + -- | Two CIDRs are equal if they have the same network bits and if + -- their masks are the same. In other words, if they are the same + -- after normalization. + cidr1 == cidr2 = addr1 == addr2 && mask1 == mask2 + where + Cidr addr1 mask1 = normalize cidr1 + Cidr addr2 mask2 = normalize cidr2 --- | Two CIDR ranges are equivalent if they have the same network bits --- and the masks are the same. -equivalent :: Cidr -> Cidr -> Bool -equivalent (Cidr addr1 mbits1) (Cidr addr2 mbits2) = - (mbits1 == mbits2) && ((apply_mask addr1 mbits1 B.Zero) == (apply_mask addr2 mbits2 B.Zero)) -- | Returns the mask portion of a CIDR address. That is, everything -- after the trailing slash. @@ -220,7 +220,7 @@ combine_all cidrs | cidrs == (combine_contained unique_cidrs) = cidrs | otherwise = combine_all (combine_contained unique_cidrs) where - unique_cidrs = nubBy equivalent cidr_combinations + unique_cidrs = nub cidr_combinations cidr_combinations = cidrs ++ (catMaybes [ (combine_adjacent x y) | x <- cidrs, y <- cidrs ]) -- 2.43.2