sw17ch / data-clist

A purely functional ring data structure for Haskell.
Other
8 stars 9 forks source link

Make rotN more efficient #25

Closed isaacvando closed 1 month ago

isaacvando commented 1 year ago

This PR adds a size parameter to the CList type which allows for rotations to be performed modulo the size. Additionally any call to rotN will result in at most size/2 rotations.

For example, rotN 9999999 (fromList [1..1000000] currently does 9999999 right rotations. With this PR it now does 1 left rotation.

Additionally, rotN 400 (fromList [1,2,3,4]) now does 0 rotations instead of 400.

Further this means the size function is now O(1).

isaacvando commented 1 year ago

Could someone take a look at this PR? @jeremyjh @sw17ch