-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize IntSet.Bin #998
Merged
Merged
Optimize IntSet.Bin #998
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
080dde1
Optimize IntSet.Bin
meooow25 b3ae761
Fix LookupGE_IntMap
meooow25 40f8503
IntSet validity: Tip cannot be empty
meooow25 3d49a54
Generate large keys in Arbitrary IntSet
meooow25 4a1c12b
Fix subsetCmp error
meooow25 fce6246
union, intersection, difference tests using Arbitrary IntSet
meooow25 d18a3c6
Fix prefixOk not checking all Bins
meooow25 bd18faf
nudge
meooow25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,17 +38,15 @@ main = defaultMain $ testGroup "intset-properties" | |
, testProperty "prop_UnionInsert" prop_UnionInsert | ||
, testProperty "prop_UnionAssoc" prop_UnionAssoc | ||
, testProperty "prop_UnionComm" prop_UnionComm | ||
, testProperty "prop_Diff" prop_Diff | ||
, testProperty "prop_Int" prop_Int | ||
, testProperty "prop_union" prop_union | ||
, testProperty "prop_difference" prop_difference | ||
, testProperty "prop_intersection" prop_intersection | ||
, testProperty "prop_Ordered" prop_Ordered | ||
, testProperty "prop_List" prop_List | ||
, testProperty "prop_DescList" prop_DescList | ||
, testProperty "prop_AscDescList" prop_AscDescList | ||
, testProperty "prop_fromList" prop_fromList | ||
, testProperty "prop_fromRange" prop_fromRange | ||
, testProperty "prop_MaskPow2" prop_MaskPow2 | ||
, testProperty "prop_Prefix" prop_Prefix | ||
, testProperty "prop_LeftRight" prop_LeftRight | ||
, testProperty "prop_isProperSubsetOf" prop_isProperSubsetOf | ||
, testProperty "prop_isProperSubsetOf2" prop_isProperSubsetOf2 | ||
, testProperty "prop_isSubsetOf" prop_isSubsetOf | ||
|
@@ -113,9 +111,8 @@ test_split = do | |
Arbitrary, reasonably balanced trees | ||
--------------------------------------------------------------------} | ||
instance Arbitrary IntSet where | ||
arbitrary = do{ xs <- arbitrary | ||
; return (fromList xs) | ||
} | ||
arbitrary = fromList <$> oneof [arbitrary, fmap (fmap getLarge) arbitrary] | ||
shrink = fmap fromList . shrink . toAscList | ||
|
||
{-------------------------------------------------------------------- | ||
Valid IntMaps | ||
|
@@ -232,19 +229,26 @@ prop_UnionComm :: IntSet -> IntSet -> Bool | |
prop_UnionComm t1 t2 | ||
= (union t1 t2 == union t2 t1) | ||
|
||
prop_Diff :: [Int] -> [Int] -> Property | ||
prop_Diff xs ys = | ||
case difference (fromList xs) (fromList ys) of | ||
prop_union :: IntSet -> IntSet -> Property | ||
prop_union xs ys = | ||
case union xs ys of | ||
t -> | ||
valid t .&&. | ||
toAscList t === List.sort ((List.\\) (nub xs) (nub ys)) | ||
toAscList t === List.nub (List.sort (toAscList xs ++ toAscList ys)) | ||
|
||
prop_Int :: [Int] -> [Int] -> Property | ||
prop_Int xs ys = | ||
case intersection (fromList xs) (fromList ys) of | ||
prop_difference :: IntSet -> IntSet -> Property | ||
prop_difference xs ys = | ||
case difference xs ys of | ||
t -> | ||
valid t .&&. | ||
toAscList t === List.sort (nub ((List.intersect) (xs) (ys))) | ||
toAscList t === (toAscList xs List.\\ toAscList ys) | ||
|
||
prop_intersection :: IntSet -> IntSet -> Property | ||
prop_intersection xs ys = | ||
case intersection xs ys of | ||
t -> | ||
valid t .&&. | ||
toAscList t === (toAscList xs `List.intersect` toAscList ys) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, |
||
|
||
prop_disjoint :: IntSet -> IntSet -> Bool | ||
prop_disjoint a b = a `disjoint` b == null (a `intersection` b) | ||
|
@@ -284,28 +288,6 @@ prop_fromRange = forAll (scale (*100) arbitrary) go | |
go (l,h) = valid t .&&. t === fromAscList [l..h] | ||
where t = fromRange (l,h) | ||
|
||
{-------------------------------------------------------------------- | ||
Bin invariants | ||
--------------------------------------------------------------------} | ||
powersOf2 :: IntSet | ||
powersOf2 = fromList [2^i | i <- [0..63]] | ||
|
||
-- Check the invariant that the mask is a power of 2. | ||
prop_MaskPow2 :: IntSet -> Bool | ||
prop_MaskPow2 (Bin _ msk left right) = member msk powersOf2 && prop_MaskPow2 left && prop_MaskPow2 right | ||
prop_MaskPow2 _ = True | ||
|
||
-- Check that the prefix satisfies its invariant. | ||
prop_Prefix :: IntSet -> Bool | ||
prop_Prefix s@(Bin prefix msk left right) = all (\elem -> match elem prefix msk) (toList s) && prop_Prefix left && prop_Prefix right | ||
prop_Prefix _ = True | ||
|
||
-- Check that the left elements don't have the mask bit set, and the right | ||
-- ones do. | ||
prop_LeftRight :: IntSet -> Bool | ||
prop_LeftRight (Bin _ msk left right) = and [x .&. msk == 0 | x <- toList left] && and [x .&. msk == msk | x <- toList right] | ||
prop_LeftRight _ = True | ||
|
||
{-------------------------------------------------------------------- | ||
IntSet operations are like Set operations | ||
--------------------------------------------------------------------} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data.List.Ordered.minus
would be faster than\\
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean from data-ordlist? Surely this is not worth a new dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, from that package. I imagine we can copy what we like, though I haven't checked its license to be sure. My only real concern about the dependency is that the package doesn't seem to be actively maintained, so it might run into annoying issues with
base
changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the tests are quite fast (as mentioned the other comment), this seems like something that shouldn't cause too much worry.
Besides, a new function/dependency is another chance to introduce a bug. Data.List is a little more trustworthy in that regard, I'd say.