Skip to content

Idea on Iterators #26

@orxfun

Description

@orxfun

Currently, iter returns an arbitrary order iterator. This is also the case in the std implementation.

However, if we are working with a queue, we would probably like to iterate in order. This would work like a whole-queue version of the peek in that instead of peeking to the root, we are peeking to the entire queue without popping them. In most (all?) implementations, this would require an allocation of O(log N) space, which might be okay.

This is important to achieve the following. We want IntoIterator to consume the queue in order. This would provided nice ergonomics. Instead of while let Some(node) = queue.pop(); we could use for node in queue.into_iter(). We expect the iterator obtained from iter and into_iter to yield elements in the same order. Therefore, the above ordered non-consuming iterator is critical.

Then, the priority queues would implicitly implement Collection and Iterable on the orx-iterable crate.

Having these in place, we can also have iter_x and into_iter_x methods which return iterators in arbitrary (but the same with each other) order.

This would be a breaking change on the iter method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions