Skip to content

Commit 2183a93

Browse files
committed
Add lightweight union ptr equality check
1 parent 9498edf commit 2183a93

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

containers/src/Data/Set/Internal.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,8 @@ unions = Foldable.foldl' union empty
831831
-- | \(O\bigl(m \log\bigl(\frac{n}{m}+1\bigr)\bigr), \; 0 < m \leq n\). The union of two sets, preferring the first set when
832832
-- equal elements are encountered.
833833
union :: Ord a => Set a -> Set a -> Set a
834-
union t1 Tip = t1
834+
union t1 t2 | t1 `ptrEq` t2 = t1
835+
union t1 Tip = t1
835836
union t1 (Bin 1 x _ _) = insertR x t1
836837
union (Bin 1 x _ _) t2 = insert x t2
837838
union Tip t2 = t2

0 commit comments

Comments
 (0)