Skip to content

Representation tweak? #35

Description

@treeowl

We don't actually need a lazy spine. An alternative representation for a queue, for example:

data N10 n a = N10 !(Array n a) !()
data N11 n a = N11 !(Array n a) !() !(Array n a)
-- () separates the front digit from the rear for clarity.
-- ...

data Queue n a
  = Empty
  | Q10 (N10 n a) !(Queue ('Twice n) a)
  | ...

This has a little more indirection and space overhead, so presumably the fundamental operations will be slower. But it also has some benefits:

  1. length becomes logarithmic time.
  2. We can index into the queue faster. While we have to pay off debits on all the nodes en route to the one we seek, we don't actually have to force them. This should win a nice constant-factor improvement, I believe.
  3. If I'm right about how efficient (still linear time) appending will work, I believe we should get better cache performance by waiting to force nodes until we've calculated out the shapes they're copied into.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions