Skip to content
This repository was archived by the owner on Jan 18, 2025. It is now read-only.

Conversation

@LebranceBW
Copy link
Contributor

@LebranceBW LebranceBW commented Feb 14, 2021

Some basic fn, some test cases but document hasn't been written.
I'm not confident about the code. could you take a review 🔖 😄?

Copy link
Owner

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Overall looks great! Just need to be more ergonomic As a library user, the default constraint is way too limited. Also, the code could be more idiomatic, Rust provides lots of handy feature you can use without hardcoded or explicitly denoting.

In addition, have you ever tried implementing this with Rc? I think it might work to avoid any single line of unsafe Rust.

* up/master: (23 commits)
  fix: deque API doc link
  fix: non_fmt_panic warning
  doc: update collection description
  refactor: move deque into collections
  fix: api doc for deque
  doc: deque
  refactor(deque): polish doc
  refactor(deque): rename try_resize -> try_grow
  fix(deque): correct layout size to dealloc
  fix(deque): handel_alloc_error
  refactor(deque): polish API documentation
  refactor(deque): remove inline for simplification
  refactor(deque): move is_full next to private fn
  test(deque): complext heap allocation elements
  feat(deque): support zero-sized types
  feat(deque): Drop
  refactor(deque): move RawVec next to impl block
  fix: rustfmt
  fix(deque): panic on zero-sized allocation
  feat(deque): Debug
  ...
@LebranceBW
Copy link
Contributor Author

@weihanglo Thank you very much for taking the time to review my code, 😃 and I'm sorry for my poor simple mistakes.

whereas, I have tried the implement the skiplist with Rc, but I'm trapped by the implement of iter just like the book. for example:

struct SkipNode<K, V> {
    entry: Entry<K, V>,
    next_by_height: [Option<Rc<RefCell<SkipNode>>>; MAX_HEIGHT],
}
impl<K, V> SkipNode<K, V> {
   pub fn iter() -> Iter<K, V> {
     ...//omittied
  }
}
pub struct Iter<'a, K, V>
{
    ptr: Option<Rc<RefCell<SkipNode<K, V>>>, // 1
    _marker: marker::PhantomData<&'a K>,
}
impl<'a, K, V: 'a> Iterator for Iter<'a, K, V>
{
    type Item =  std::cell::Ref('a, (K, V)); //2
    fn next(&mut self) -> Option<Self::Item> {
        self.ptr.map(|node| node.as_ref().borrow()); //3
    }
}

Because the RefCell holds the SkipNode, and the borrow() fn return a Ref. The code above will complain at 2 about return the temporary variable. I don't know how to overcome. Could you provide a solution? or tell me some other code just like this?

@LebranceBW LebranceBW closed this Feb 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants