Skip to content

feat(cordyceps): singly-linked intrusive SortedList#520

Merged
jamesmunns merged 8 commits into
mainfrom
james/cordyceps-embassy
Apr 2, 2025
Merged

feat(cordyceps): singly-linked intrusive SortedList#520
jamesmunns merged 8 commits into
mainfrom
james/cordyceps-embassy

Conversation

@jamesmunns
Copy link
Copy Markdown
Collaborator

This PR implements:

  • A new method for TransferStack that reports whether the list was previously empty
  • A new type, SortedList, that is a sorted singly-linked-list

These are changes I am making for experimentation with embassy's scheduler, which I am using cordyceps for.

These changes are currently functional and minimally tested, but probably could use tweaks to better fit naturally in the library.

This PR implements:

* A new method for `TransferStack` that reports whether the list was previously empty
* A new type, `SortedList`, that is a sorted singly-linked-list
@jamesmunns jamesmunns requested a review from hawkw March 24, 2025 11:23
Comment thread cordyceps/src/stack.rs Outdated
@jamesmunns
Copy link
Copy Markdown
Collaborator Author

These changes are exercised in jamesmunns/embassy#1 as well.

Comment thread cordyceps/src/stack.rs Outdated
Comment thread cordyceps/src/stack.rs Outdated
Comment thread cordyceps/src/stack.rs Outdated
Comment thread cordyceps/src/stack.rs Outdated
Comment thread cordyceps/src/stack.rs Outdated
@hawkw
Copy link
Copy Markdown
Owner

hawkw commented Mar 24, 2025

It occurs to me that if we want to not have the insert operation be O(n), but we also don't want to go with a full intrusive tree implementation, we could probably use a skip list and binary search. If we went down that route, though, we would have to go with a Links type that's more complex than the stack::Links type, to include the skiplist pointers. However, we might still be able to maintain the ability to link a value into both a SortedList and a Stack if we did something like this:

// in sorted list module
pub struct Links<T> {
     layer_0: stack::Links<T>,
     skip_layers: [Option<NonNull<T>>; NUM_SKIP_LAYERS],
}

// Make anything that has sorted-list links "count" as having stack links too
impl<T: Linked<stack::Links<T>>> for  T where T: Linked<Links<T>> {
    // ... some wacky unsafe code to offset the pointers returned by the
    // `Linked<Links<T>>` impl to get the `stack::Links` out of them, which
    // i didn't want to write, but i'm sure is possible...
}

@jamesmunns
Copy link
Copy Markdown
Collaborator Author

I will likely not plan to add any Smarter impls for SortedList for now, but if you would like me to leave room for other impls (SkipSortedList?) somewhere, I can do so!

@jamesmunns
Copy link
Copy Markdown
Collaborator Author

jamesmunns commented Apr 1, 2025

@hawkw I think I've addressed all comments, back to you, let me know if I can help get this published!

Copy link
Copy Markdown
Owner

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

Looks good to me overall! I had some minor nits, mostly about the comments, but this should be good to merge once those are addressed.

Would you mind changing the commit message to something like

feat(cordyceps): singly-linked intrusive SortedList

or something before merging? that way, it should look nice when generating the changelog...

Comment thread cordyceps/src/sorted_list.rs
Comment thread cordyceps/src/sorted_list.rs Outdated
Comment thread cordyceps/src/sorted_list.rs
Comment thread cordyceps/src/sorted_list.rs
Comment thread cordyceps/src/sorted_list.rs Outdated
Comment thread cordyceps/src/sorted_list.rs Outdated
Comment thread cordyceps/src/sorted_list.rs Outdated
Comment thread cordyceps/src/sorted_list.rs Outdated
Comment thread cordyceps/src/sorted_list.rs
Comment thread cordyceps/src/sorted_list.rs Outdated
@jamesmunns jamesmunns changed the title Changes for Embassy scheduler experimentation feat(cordyceps): singly-linked intrusive SortedList Apr 2, 2025
@jamesmunns jamesmunns merged commit 1dad987 into main Apr 2, 2025
@jamesmunns jamesmunns deleted the james/cordyceps-embassy branch April 2, 2025 18:36
@hawkw hawkw linked an issue May 15, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cordyceps: List::insert_sorted

2 participants