50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
//! Node types for the TST module.
|
|
|
|
/// Represents a node in the ternary search tree.
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub struct TSTNode {
|
|
/// The character stored at this node.
|
|
pub character: char,
|
|
|
|
/// Value stored at this node (empty if not end of key).
|
|
pub value: Vec<u8>,
|
|
|
|
/// Whether this node represents the end of a key.
|
|
pub is_end_of_key: bool,
|
|
|
|
/// Reference to the left child node (for characters < current character).
|
|
pub left_id: Option<u32>,
|
|
|
|
/// Reference to the middle child node (for next character in key).
|
|
pub middle_id: Option<u32>,
|
|
|
|
/// Reference to the right child node (for characters > current character).
|
|
pub right_id: Option<u32>,
|
|
}
|
|
|
|
impl TSTNode {
|
|
/// Creates a new node.
|
|
pub fn new(character: char, value: Vec<u8>, is_end_of_key: bool) -> Self {
|
|
Self {
|
|
character,
|
|
value,
|
|
is_end_of_key,
|
|
left_id: None,
|
|
middle_id: None,
|
|
right_id: None,
|
|
}
|
|
}
|
|
|
|
/// Creates a new root node.
|
|
pub fn new_root() -> Self {
|
|
Self {
|
|
character: '\0', // Use null character for root
|
|
value: Vec::new(),
|
|
is_end_of_key: false,
|
|
left_id: None,
|
|
middle_id: None,
|
|
right_id: None,
|
|
}
|
|
}
|
|
}
|