Skip to content

Dequeues aren't amortized O(1) when using both unsnoc and uncons #2531

@ZiyaoWei

Description

@ZiyaoWei

It seems dequeues are not amortized O(1) when both unsnoc and uncons are called; in fact, the underlying two lists might "oscillate" such that the operations are amortized O(n). When only one of these is used it is amortized O(1).

See https://scastie.scala-lang.org/lrP3QumzQuSMQ1rQMBUGow for a demonstration.

Given this has already been there for a while it is probably enough for real world use cases - should the docs be updated?

Note that Okasaki does contain an amortized O(1) banker's deque, which we can implement if we truly want amortized constant time operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions