Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deque #144

Closed
wants to merge 13 commits into from
Closed

Deque #144

wants to merge 13 commits into from

Conversation

rostyslavtyshko
Copy link
Contributor

@rostyslavtyshko rostyslavtyshko commented Apr 25, 2023

Type of change

  • New feature
    Deque library

Notes

  • Note 1

Related Issues

Closes #134

@rostyslavtyshko rostyslavtyshko marked this pull request as ready for review May 2, 2023 07:29
@rostyslavtyshko rostyslavtyshko requested a review from a team as a code owner May 2, 2023 07:29
@Braqzen Braqzen added New Feature New addition that does not currently exist Libs: Data Structures Label used to filter for the library issue labels May 2, 2023
Copy link
Contributor

@Braqzen Braqzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We should test the code via in-language tests rather than Rust code.
  2. We do not need to import modules from the prelude e.g. the assert is automatically imported for us
  3. I'm uncertain about this implementation which involves 2 fields. It does not behave as I expect, but I could be incorrect in my assumption. I expect something to track where the start / end is via an index and then using the index to determine where we insert / remove the item based on the method called. I would reconsider this implementation

libs/deque/.gitignore Outdated Show resolved Hide resolved
libs/deque/src/main.sw Outdated Show resolved Hide resolved
}
}

/// Appends an element to the back of the deque.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Appends an element to the back of the deque.
/// Appends an element to the end of the deque.

Sorry, I feel the need to be pedantic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it would be better to use conventional terminology (back, front etc), so that the users are comfortable with the library.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say follow what Rust does here as usual.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to not use a similar implementation from Rust @rostyslavtyshko ?

self.back.push(value);
}

/// Inserts an element at the front of the deque.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Inserts an element at the front of the deque.
/// Inserts an element at the start of the deque.

Here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same argument as here

tests/src/deque/src/main.sw Outdated Show resolved Hide resolved
tests/src/deque/src/main.sw Outdated Show resolved Hide resolved
pub fn pop_front(ref mut self) -> Option<T> {
if self.front.is_empty() {
if !self.back.is_empty() {
self.front.push(self.back.remove(0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.front.push(self.back.remove(0))
self.back.remove(0)

Is there a reason that we do not actually remove from the front? Here we remove the first item from the back but then we add it to the end of the front which effectively does not pop the item.

May need to run forc fmt here. and same below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to unify the logic and always to pop from front, even if due to some reasons all the elements were in back

forc fmt is run by CI, so seems to be fine

libs/deque/src/main.sw Show resolved Hide resolved
@rostyslavtyshko
Copy link
Contributor Author

rostyslavtyshko commented May 3, 2023

  1. We should test the code via in-language tests rather than Rust code.

    1. We do not need to import modules from the prelude e.g. the assert is automatically imported for us

    2. I'm uncertain about this implementation which involves 2 fields. It does not behave as I expect, but I could be incorrect in my assumption. I expect something to track where the start / end is via an index and then using the index to determine where we insert / remove the item based on the method called. I would reconsider this implementation

  1. Moved tests from Rust.
  2. Not an issue since all the tests are now in-language.

@bitzoic
Copy link
Member

bitzoic commented May 20, 2024

Closing due to inactivity

@bitzoic bitzoic closed this May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Libs: Data Structures Label used to filter for the library issue New Feature New addition that does not currently exist
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deque
4 participants