Skip to content
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

IntSet foldl and foldr smell funny #666

Open
Tracked by #1059
treeowl opened this issue Jul 17, 2019 · 1 comment · May be fixed by #667
Open
Tracked by #1059

IntSet foldl and foldr smell funny #666

treeowl opened this issue Jul 17, 2019 · 1 comment · May be fixed by #667

Comments

@treeowl
Copy link
Contributor

treeowl commented Jul 17, 2019

The implementations of foldl'Bits and foldr'Bits look efficient. The implementations of foldlBits and foldrBits, on the other hand, don't look efficient for their purposes. I'd expect foldlBits to look more like foldr'Bits, and I'd expect foldrBits to look more like foldl'Bits.

@treeowl
Copy link
Contributor Author

treeowl commented Jul 17, 2019

Roughly speaking:

foldrBits !prefix f z = go
  where
        go 0 = z
        go bm = f (prefix + bi) $ go (bm `xor` bitmask)
          where
                !bitmask = lowestBitMask bm
                !bi = indexOfTheOnlyBit bitmask

treeowl added a commit to treeowl/containers that referenced this issue Jul 18, 2019
`foldrBits` was previously defined just like `foldr'Bits`, and
`foldlBits` was defined just like `foldl'Bits`. That is, each of them
built up an accumulator, lazily, across a whole leaf before producing
anything. Swap that around so the folds can process values promptly.

Fixes haskell#666
@treeowl treeowl linked a pull request Jul 18, 2019 that will close this issue
@meooow25 meooow25 mentioned this issue Oct 31, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants