Skip to content

Commit e85d8f4

Browse files
bors[bot]taiki-e
andauthored
Merge #655
655: Add docs for SkipSet and SkipList r=jeehoonkang a=taiki-e This is the main blocker for the crossbeam-skiplist 0.1 release. cc #635 Co-authored-by: Taiki Endo <[email protected]>
2 parents ae5ca20 + 82a173f commit e85d8f4

File tree

4 files changed

+272
-23
lines changed

4 files changed

+272
-23
lines changed

crossbeam-skiplist/src/base.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! TODO: docs
1+
//! A lock-free skip list. See [`SkipList`].
22
33
use alloc::alloc::{alloc, dealloc, handle_alloc_error, Layout};
44
use core::borrow::Borrow;
@@ -1551,6 +1551,7 @@ where
15511551
}
15521552
}
15531553
}
1554+
15541555
/// Moves to the previous entry in the skip list.
15551556
pub fn move_prev(&mut self, guard: &Guard) -> bool {
15561557
match self.prev(guard) {
@@ -1684,7 +1685,7 @@ impl<'a, K: 'a, V: 'a> RefIter<'a, K, V>
16841685
where
16851686
K: Ord,
16861687
{
1687-
/// TODO
1688+
/// Advances the iterator and returns the next value.
16881689
pub fn next(&mut self, guard: &Guard) -> Option<RefEntry<'a, K, V>> {
16891690
self.parent.check_guard(guard);
16901691
self.head = match self.head {
@@ -1710,7 +1711,7 @@ where
17101711
self.head.clone()
17111712
}
17121713

1713-
/// TODO
1714+
/// Removes and returns an element from the end of the iterator.
17141715
pub fn next_back(&mut self, guard: &Guard) -> Option<RefEntry<'a, K, V>> {
17151716
self.parent.check_guard(guard);
17161717
self.tail = match self.tail {
@@ -1888,7 +1889,7 @@ where
18881889
R: RangeBounds<Q>,
18891890
Q: Ord + ?Sized,
18901891
{
1891-
/// TODO
1892+
/// Advances the iterator and returns the next value.
18921893
pub fn next(&mut self, guard: &Guard) -> Option<RefEntry<'a, K, V>> {
18931894
self.parent.check_guard(guard);
18941895
self.head = match self.head {
@@ -1912,7 +1913,7 @@ where
19121913
self.head.clone()
19131914
}
19141915

1915-
/// TODO: docs
1916+
/// Removes and returns an element from the end of the iterator.
19161917
pub fn next_back(&mut self, guard: &Guard) -> Option<RefEntry<'a, K, V>> {
19171918
self.parent.check_guard(guard);
19181919
self.tail = match self.tail {

crossbeam-skiplist/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! multiple threads.
77
//!
88
//! # Concurrent access
9-
//! [`SkipMap`] and [`SkipSet`] implement `Send` and `Sync`,
9+
//! [`SkipMap`] and [`SkipSet`] implement [`Send`] and [`Sync`],
1010
//! so they can be shared across threads with ease.
1111
//!
1212
//! Methods which mutate the map, such as [`insert`],

crossbeam-skiplist/src/map.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ pub struct SkipMap<K, V> {
2222

2323
impl<K, V> SkipMap<K, V> {
2424
/// Returns a new, empty map.
25+
///
26+
/// # Example
27+
///
28+
/// ```
29+
/// use crossbeam_skiplist::SkipMap;
30+
///
31+
/// let map: SkipMap<i32, &str> = SkipMap::new();
32+
/// ```
2533
pub fn new() -> SkipMap<K, V> {
2634
SkipMap {
2735
inner: base::SkipList::new(epoch::default_collector().clone()),
@@ -83,8 +91,8 @@ where
8391
///
8492
/// let numbers = SkipMap::new();
8593
/// numbers.insert(5, "five");
94+
/// assert_eq!(*numbers.front().unwrap().value(), "five");
8695
/// numbers.insert(6, "six");
87-
///
8896
/// assert_eq!(*numbers.front().unwrap().value(), "five");
8997
/// ```
9098
pub fn front(&self) -> Option<Entry<'_, K, V>> {
@@ -103,8 +111,8 @@ where
103111
///
104112
/// let numbers = SkipMap::new();
105113
/// numbers.insert(5, "five");
114+
/// assert_eq!(*numbers.back().unwrap().value(), "five");
106115
/// numbers.insert(6, "six");
107-
///
108116
/// assert_eq!(*numbers.back().unwrap().value(), "six");
109117
/// ```
110118
pub fn back(&self) -> Option<Entry<'_, K, V>> {
@@ -274,9 +282,9 @@ where
274282
}
275283
}
276284

277-
/// Returns an iterator over a subset of entries in the skip list.
285+
/// Returns an iterator over a subset of entries in the map.
278286
///
279-
/// This iterator returns [`Entry`]s which
287+
/// This iterator returns [`Entry`]s which
280288
/// can be used to access keys and their associated values.
281289
///
282290
/// # Example
@@ -381,7 +389,7 @@ where
381389
/// assert_eq!(*numbers.pop_front().unwrap().value(), "twelve");
382390
///
383391
/// // All entries have been removed now.
384-
/// assert!(numbers.pop_front().is_none());
392+
/// assert!(numbers.is_empty());
385393
/// ```
386394
pub fn pop_front(&self) -> Option<Entry<'_, K, V>> {
387395
let guard = &epoch::pin();
@@ -408,7 +416,7 @@ where
408416
/// assert_eq!(*numbers.pop_back().unwrap().value(), "six");
409417
///
410418
/// // All entries have been removed now.
411-
/// assert!(numbers.pop_front().is_none());
419+
/// assert!(numbers.is_empty());
412420
/// ```
413421
pub fn pop_back(&self) -> Option<Entry<'_, K, V>> {
414422
let guard = &epoch::pin();
@@ -641,7 +649,7 @@ impl<K, V> fmt::Debug for Iter<'_, K, V> {
641649
}
642650
}
643651

644-
/// An iterator over the entries of a `SkipMap`.
652+
/// An iterator over a subset of entries of a `SkipMap`.
645653
pub struct Range<'a, Q, R, K, V>
646654
where
647655
K: Ord + Borrow<Q>,

0 commit comments

Comments
 (0)