Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ name = "platform_trees"
path = "src/lib.rs"

[dependencies]
num-traits = "0.2.19"
platform-num = "0.6.0"
platform-num = "0.8.0"

[lints.rust]
unsafe_code = "allow"
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ impl AbsoluteCircularLinkedList<usize> for MyListStorage {}

## Depend on

- [num-traits](https://crates.io/crates/num-traits)
- [platform-num](https://crates.io/crates/platform-num)
([Numbers](https://github.com/linksplatform/Numbers))

Expand Down
13 changes: 13 additions & 0 deletions changelog.d/20260414_replace_linktype_with_linkreference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
bump: minor
---

### Changed

- **Breaking:** Removed `LinkType` trait entirely — use `LinkReference` from `platform-num` instead
- All trait bounds now use `T: LinkReference` instead of `T: LinkType`
- Replaced all `funty()` calls with `from_byte()` from `LinkReference`
- Re-exported `LinkReference` from `platform_num` in the public API
- Removed direct `num-traits` dependency (now provided transitively via `platform-num`)
- Upgraded `platform-num` from 0.6.0 to 0.8.0
- Added `u128` support via `LinkReference`
16 changes: 5 additions & 11 deletions experiments/test_funty_compatibility.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
// Experiment: Verify that removing the `funty` crate dependency from trees-rs
// does NOT break the public `funty()` method API.
// Experiment: Verify that `LinkReference::from_byte()` works correctly.
//
// Key finding: The `funty` crate and the `funty()` method are different things.
// - `funty` crate: provides `funty::Unsigned` trait
// - `funty()` method: a convenience method on the `LinkType` trait for creating
// small integer values from u8
//
// PR #9 removed the `funty` crate dependency but PRESERVED the `funty()` method
// on the `LinkType` trait. The `funty()` method now uses `num_traits::Unsigned`
// instead of `funty::Unsigned` for the trait bound, but the method signature
// and behavior are identical.
// History:
// - `funty` crate was removed in PR #9, but `funty()` method was preserved
// - Issue #30 replaced both `LinkType` and `funty()` with `LinkReference`
// and `from_byte()` from `platform-num`, unifying the trait hierarchy
//
// See tests/funty_compatibility.rs for the runnable test version.
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//!
//! | Trait | Description |
//! |---|---|
//! | [`LinkType`] | Marker trait for unsigned integer types usable as node indices |
//! | [`LinkReference`] | Unsigned integer type usable as a node index (from `platform-num`) |
//! | [`LinkedList`] | Base doubly-linked list with `get_previous`/`get_next` |
//! | [`AbsoluteLinkedList`] | List with direct `first`/`last`/`size` access |
//! | [`RelativeLinkedList`] | List with head-relative `first`/`last`/`size` |
Expand All @@ -24,9 +24,8 @@
//! ## Quick start
//!
//! ```rust
//! use platform_trees::{
//! LinkType, LinkedList, AbsoluteLinkedList, AbsoluteCircularLinkedList,
//! };
//! use platform_trees::{LinkedList, AbsoluteLinkedList, AbsoluteCircularLinkedList};
//! use platform_num::LinkReference;
//!
//! // 1. Define your storage
//! #[derive(Default, Clone, Copy)]
Expand Down Expand Up @@ -70,14 +69,13 @@
//! assert_eq!(list.get_last(), 2);
//! ```

mod link_type;
mod lists;
mod trees;

pub use link_type::LinkType;
pub use lists::{
AbsoluteCircularLinkedList, AbsoluteLinkedList, LinkedList, RelativeCircularLinkedList,
RelativeLinkedList,
};
pub use platform_num::LinkReference;

pub use trees::{IterativeSizeBalancedTree, RecursiveSizeBalancedTree};
51 changes: 0 additions & 51 deletions src/link_type.rs

This file was deleted.

19 changes: 10 additions & 9 deletions src/lists/absolute_circular_linked_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{AbsoluteLinkedList, LinkType};
use crate::AbsoluteLinkedList;
use platform_num::LinkReference;

/// Circular doubly-linked list with absolute (direct) head/tail access.
///
Expand All @@ -8,7 +9,7 @@ use crate::{AbsoluteLinkedList, LinkType};
///
/// All methods have default implementations — an empty `impl` block
/// is sufficient once [`AbsoluteLinkedList`] is implemented.
pub trait AbsoluteCircularLinkedList<T: LinkType>: AbsoluteLinkedList<T> {
pub trait AbsoluteCircularLinkedList<T: LinkReference>: AbsoluteLinkedList<T> {
/// Inserts `new_element` immediately before `base_element`.
///
/// If `base_element` is the current first element, the first
Expand Down Expand Up @@ -47,7 +48,7 @@ pub trait AbsoluteCircularLinkedList<T: LinkType>: AbsoluteLinkedList<T> {
/// with its previous and next pointers pointing to itself.
fn attach_as_first(&mut self, element: T) {
let first = self.get_first();
if first == T::funty(0) {
if first == T::from_byte(0) {
self.set_first(element);
self.set_last(element);
self.set_previous(element, element);
Expand All @@ -63,7 +64,7 @@ pub trait AbsoluteCircularLinkedList<T: LinkType>: AbsoluteLinkedList<T> {
/// If the list is empty, delegates to [`attach_as_first`](Self::attach_as_first).
fn attach_as_last(&mut self, element: T) {
let last = self.get_last();
if last == T::funty(0) {
if last == T::from_byte(0) {
self.attach_as_first(element);
} else {
self.attach_after(last, element);
Expand All @@ -73,13 +74,13 @@ pub trait AbsoluteCircularLinkedList<T: LinkType>: AbsoluteLinkedList<T> {
/// Removes `element` from the list.
///
/// Updates head/tail pointers as needed and clears the element's
/// previous and next pointers to `T::funty(0)`.
/// previous and next pointers to `T::from_byte(0)`.
fn detach(&mut self, element: T) {
let element_previous = self.get_previous(element);
let element_next = self.get_next(element);
if element_next == element {
self.set_first(T::funty(0));
self.set_last(T::funty(0));
self.set_first(T::from_byte(0));
self.set_last(T::from_byte(0));
} else {
self.set_next(element_previous, element_next);
self.set_previous(element_next, element_previous);
Expand All @@ -90,8 +91,8 @@ pub trait AbsoluteCircularLinkedList<T: LinkType>: AbsoluteLinkedList<T> {
self.set_last(element_previous);
}
}
self.set_previous(element, T::funty(0));
self.set_next(element, T::funty(0));
self.set_previous(element, T::from_byte(0));
self.set_next(element, T::from_byte(0));
self.dec_size();
}
}
13 changes: 7 additions & 6 deletions src/lists/absolute_linked_list.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use crate::{LinkType, LinkedList};
use crate::LinkedList;
use platform_num::LinkReference;

/// Linked list with direct (absolute) access to the first and last
/// elements and a size counter.
///
/// This is typically used when a single list instance owns its own
/// head/tail/size metadata. For multiple lists sharing the same
/// storage, see [`RelativeLinkedList`](super::RelativeLinkedList).
pub trait AbsoluteLinkedList<T: LinkType>: LinkedList<T> {
/// Returns the first element (head) of the list, or `T::funty(0)` if empty.
pub trait AbsoluteLinkedList<T: LinkReference>: LinkedList<T> {
/// Returns the first element (head) of the list, or `T::from_byte(0)` if empty.
fn get_first(&self) -> T;

/// Returns the last element (tail) of the list, or `T::funty(0)` if empty.
/// Returns the last element (tail) of the list, or `T::from_byte(0)` if empty.
fn get_last(&self) -> T;

/// Returns the number of elements in the list.
Expand All @@ -27,11 +28,11 @@ pub trait AbsoluteLinkedList<T: LinkType>: LinkedList<T> {

/// Increments the list size by one.
fn inc_size(&mut self) {
self.set_size(self.get_size() + T::funty(1));
self.set_size(self.get_size() + T::from_byte(1));
}

/// Decrements the list size by one.
fn dec_size(&mut self) {
self.set_size(self.get_size() - T::funty(1));
self.set_size(self.get_size() - T::from_byte(1));
}
}
4 changes: 2 additions & 2 deletions src/lists/linked_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::LinkType;
use platform_num::LinkReference;

/// Base doubly-linked list trait providing node-level navigation.
///
Expand Down Expand Up @@ -28,7 +28,7 @@ use crate::LinkType;
/// list.set_next(1, 2);
/// assert_eq!(list.get_next(1), 2);
/// ```
pub trait LinkedList<T: LinkType> {
pub trait LinkedList<T: LinkReference> {
/// Returns the previous element of `element`.
fn get_previous(&self, element: T) -> T;

Expand Down
17 changes: 9 additions & 8 deletions src/lists/relative_circular_linked_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{LinkType, RelativeLinkedList};
use crate::RelativeLinkedList;
use platform_num::LinkReference;

/// Circular doubly-linked list with head-relative positioning.
///
Expand All @@ -8,7 +9,7 @@ use crate::{LinkType, RelativeLinkedList};
///
/// All methods have default implementations — an empty `impl` block
/// is sufficient once [`RelativeLinkedList`] is implemented.
pub trait RelativeCircularLinkedList<T: LinkType>: RelativeLinkedList<T> {
pub trait RelativeCircularLinkedList<T: LinkReference>: RelativeLinkedList<T> {
/// Inserts `new_element` immediately before `base_element` in the
/// list identified by `head`.
fn attach_before(&mut self, head: T, base_element: T, new_element: T) {
Expand Down Expand Up @@ -41,7 +42,7 @@ pub trait RelativeCircularLinkedList<T: LinkType>: RelativeLinkedList<T> {
/// by `head`.
fn attach_as_first(&mut self, head: T, element: T) {
let first = self.get_first(head);
if first == T::funty(0) {
if first == T::from_byte(0) {
self.set_first(head, element);
self.set_last(head, element);
self.set_previous(element, element);
Expand All @@ -56,7 +57,7 @@ pub trait RelativeCircularLinkedList<T: LinkType>: RelativeLinkedList<T> {
/// by `head`.
fn attach_as_last(&mut self, head: T, element: T) {
let last = self.get_last(head);
if last == T::funty(0) {
if last == T::from_byte(0) {
self.attach_as_first(head, element);
} else {
self.attach_after(head, last, element);
Expand All @@ -68,8 +69,8 @@ pub trait RelativeCircularLinkedList<T: LinkType>: RelativeLinkedList<T> {
let element_previous = self.get_previous(element);
let element_next = self.get_next(element);
if element_next == element {
self.set_first(head, T::funty(0));
self.set_last(head, T::funty(0));
self.set_first(head, T::from_byte(0));
self.set_last(head, T::from_byte(0));
} else {
self.set_next(element_previous, element_next);
self.set_previous(element_next, element_previous);
Expand All @@ -80,8 +81,8 @@ pub trait RelativeCircularLinkedList<T: LinkType>: RelativeLinkedList<T> {
self.set_last(head, element_previous);
}
}
self.set_previous(element, T::funty(0));
self.set_next(element, T::funty(0));
self.set_previous(element, T::from_byte(0));
self.set_next(element, T::from_byte(0));
self.dec_size(head);
}
}
9 changes: 5 additions & 4 deletions src/lists/relative_doubly_linked_list.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::{LinkType, LinkedList};
use crate::LinkedList;
use platform_num::LinkReference;

/// Linked list with head-relative access to first, last, and size.
///
/// Unlike [`AbsoluteLinkedList`](super::AbsoluteLinkedList), this trait
/// stores head/tail/size per `head` index, allowing multiple independent
/// lists to share the same underlying node storage.
pub trait RelativeLinkedList<T: LinkType>: LinkedList<T> {
pub trait RelativeLinkedList<T: LinkReference>: LinkedList<T> {
/// Returns the first element of the list identified by `head`.
fn get_first(&self, head: T) -> T;

Expand All @@ -26,11 +27,11 @@ pub trait RelativeLinkedList<T: LinkType>: LinkedList<T> {

/// Increments the size of the list identified by `head` by one.
fn inc_size(&mut self, head: T) {
self.set_size(head, self.get_size(head) + T::funty(1));
self.set_size(head, self.get_size(head) + T::from_byte(1));
}

/// Decrements the size of the list identified by `head` by one.
fn dec_size(&mut self, head: T) {
self.set_size(head, self.get_size(head) - T::funty(1));
self.set_size(head, self.get_size(head) - T::from_byte(1));
}
}
Loading