From e1aab0a8fb92b17bd22d8345503a2f69dfe33e65 Mon Sep 17 00:00:00 2001 From: Jacob Date: Sat, 23 May 2026 20:49:44 -0400 Subject: [PATCH] feat: get first or last (left) element with data of `OneToManyUniqueBTreeMapWithData` --- src/one_to_many_with_data.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/one_to_many_with_data.rs b/src/one_to_many_with_data.rs index c1ee244..2b2b7a0 100644 --- a/src/one_to_many_with_data.rs +++ b/src/one_to_many_with_data.rs @@ -40,7 +40,7 @@ where old } - pub fn get_rights_for(&self, left: &Left) -> Option<&BTreeMap> { + pub fn get_rights_and_data_for(&self, left: &Left) -> Option<&BTreeMap> { self.left_to_rights.get(left) } @@ -48,9 +48,17 @@ where self.right_to_left.get(right) } + pub fn first_left_and_rights_and_data(&self) -> Option<(&Left, &BTreeMap)> { + self.left_to_rights.first_key_value() + } + + pub fn last_left_and_rights_and_data(&self) -> Option<(&Left, &BTreeMap)> { + self.left_to_rights.last_key_value() + } + pub fn get_left_and_data_for(&self, right: &Right) -> Option<(&Left, &RightData)> { let left = self.right_to_left.get(right)?; - let rights = self.get_rights_for(left)?; + let rights = self.get_rights_and_data_for(left)?; let right_data = rights.get(right)?;