orxfun / orxfun/orx-priority-queue

Idea on Iterators

Open
#26 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
11
Forks
2
Avg merge
29m
Merged PRs (30d)
3

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the current iter and IntoIterator implementations for the priority queues and reviewing how their existing traversal order is defined. Compare the desired ordered, non-consuming and consuming behavior with the arbitrary-order iter_x and into_iter_x proposal, and review the orx-iterable expectations. Done requires an agreed design for the breaking change and matching iterator order.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.