Buglet in Data.IntSet.split and Data.IntSet.splitMember, patch included.

Hello mailinglist-members, on the #haskell IRC channel Ketil Z. Malde noted that Data.IntSet.split failed on the case
let m = 1000000 in Data.IntSet.split (16*m) $ Data.IntSet.fromList $ map (*m) [17,18,19,30,40]
so Bertram Felgenhauer (int-e@gmx.de) and I set out to fix that, noting
along the way that Data.IntSet.splitMember was broken as well, and
that negative numbers were not handled correctly either. The following
patch fixes the problems:
----- 8< --- cut here --- >8 -----
--- IntSet.hs 2005-10-27 17:18:15.000000000 +0200
+++ FixedIntSet.hs 2005-10-27 17:59:49.000000000 +0200
@@ -35,7 +35,7 @@
-- (32 or 64).
------------------------------------------------------------------------
-----
-module Data.IntSet (
+module IntSet (
-- * Set type
IntSet -- instance Eq,Show
@@ -454,8 +454,23 @@
split x t
= case t of
Bin p m l r
- | zero x m -> let (lt,gt) = split x l in (lt,union gt r)
- | otherwise -> let (lt,gt) = split x r in (union l lt,gt)
+ | m < 0 -> if x >= 0 then let (lt,gt) = split' x l in
(union r lt, gt)
+ else let (lt,gt) = split' x r in
(lt, union gt l)
+ | otherwise -> split' x t
+ Tip y
+ | x>y -> (t,Nil)
+ | x

Hello,
On 10/27/05, Arthur van Leeuwen
Hello mailinglist-members,
so Bertram Felgenhauer (int-e@gmx.de) and I set out to fix that, noting along the way that Data.IntSet.splitMember was broken as well, and that negative numbers were not handled correctly either. The following patch fixes the problems:
Note that 'fold' and other functions derived from it are also behaving strangely when presented negative numbers. Basically they are treated as unsigned. IntSet and IntMap were never designed to suport those, I think. On the other hand, I assume that no one relies on that 'strange' behaviour... which is not documented. If no one objects, I'll change that . Note that this involves a small performance penalty. Cheers, JP.
participants (2)
-
Arthur van Leeuwen
-
Jean-Philippe Bernardy