sos-os / alarm

ALARM: Another Library for Allocating and Releasing Memory
Apache License 2.0
8 stars 6 forks source link

Add `front` and `back` methods to `doubly::Linked` #15

Closed jdanford closed 6 years ago

jdanford commented 6 years ago

Closes #10

hawkw commented 6 years ago

With that said, the functions you've added seem to be implemented correctly, so I'd be happy to merge these changes as well, although I'm not immediately sure what potential use-case there is for them...

hawkw commented 6 years ago

(btw, the CI failure is due to issue #14, not your fault. once #16 lands, let's rebase your branch from masterand it should build again)

jdanford commented 6 years ago

Wow I definitely got confused by the names there, my bad! I'll make a new PR that does the right thing.

hawkw commented 6 years ago

@jdanford sorry, that's entirely my fault! The issue definitely did not actually describe what we needed.

jdanford commented 6 years ago

Okay so I guess this part is confusing me:

where next() and prev() return Option<&Self>, peek_next() and peek_back() would return Option<&T> where Self: AsRef<T>

In what situation would one use peek_next() instead of next()?

hawkw commented 6 years ago

@jdanford if you want to use an intrusive list as a collection of values of type T, then the list's nodes (e.g. types implementing Linked) must store a T. I've been using implementations of AsRef<T>/AsMut<T> as a way for implementors of node types to signal "hey, my type that implements Linked is also a container of Ts".

In this case, you would use peek_next() rather than next() when you want to access the value of the next node, rather than the node itself.

If that's not clear, let me know! I need to document this stuff better anyway.