Skip to content

Commit 4819253

Browse files
committed
Document the first/last methods
1 parent eca535d commit 4819253

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/map.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,18 +717,30 @@ impl<K, V, S> IndexMap<K, V, S> {
717717
self.as_entries_mut().get_mut(index).map(Bucket::muts)
718718
}
719719

720+
/// Get the first key-value pair
721+
///
722+
/// Computes in **O(1)** time.
720723
pub fn first(&self) -> Option<(&K, &V)> {
721724
self.as_entries().first().map(Bucket::refs)
722725
}
723726

727+
/// Get the first key-value pair, with mutable access to the value
728+
///
729+
/// Computes in **O(1)** time.
724730
pub fn first_mut(&mut self) -> Option<(&K, &mut V)> {
725731
self.as_entries_mut().first_mut().map(Bucket::ref_mut)
726732
}
727733

734+
/// Get the last key-value pair
735+
///
736+
/// Computes in **O(1)** time.
728737
pub fn last(&self) -> Option<(&K, &V)> {
729738
self.as_entries().last().map(Bucket::refs)
730739
}
731740

741+
/// Get the last key-value pair, with mutable access to the value
742+
///
743+
/// Computes in **O(1)** time.
732744
pub fn last_mut(&mut self) -> Option<(&K, &mut V)> {
733745
self.as_entries_mut().last_mut().map(Bucket::ref_mut)
734746
}

src/set.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,16 @@ impl<T, S> IndexSet<T, S> {
602602
self.as_entries().get(index).map(Bucket::key_ref)
603603
}
604604

605+
/// Get the first value
606+
///
607+
/// Computes in **O(1)** time.
605608
pub fn first(&self) -> Option<&T> {
606609
self.as_entries().first().map(Bucket::key_ref)
607610
}
608611

612+
/// Get the last value
613+
///
614+
/// Computes in **O(1)** time.
609615
pub fn last(&self) -> Option<&T> {
610616
self.as_entries().last().map(Bucket::key_ref)
611617
}

0 commit comments

Comments
 (0)