Lines Matching full:cursor
245 /// Returns a cursor over the tree nodes, starting with the smallest key.
246 pub fn cursor_front(&mut self) -> Option<Cursor<'_, K, V>> { in cursor_front()
253 Cursor { in cursor_front()
260 /// Returns a cursor over the tree nodes, starting with the largest key.
261 pub fn cursor_back(&mut self) -> Option<Cursor<'_, K, V>> { in cursor_back()
268 Cursor { in cursor_back()
419 /// Returns a cursor over the tree nodes based on the given key.
421 /// If the given key exists, the cursor starts there.
424 pub fn cursor_lower_bound(&mut self, key: &K) -> Option<Cursor<'_, K, V>> in cursor_lower_bound()
473 Cursor { in cursor_lower_bound()
510 /// A bidirectional cursor over the tree nodes, sorted by key.
514 /// In the following example, we obtain a cursor to the first element in the tree.
515 /// The cursor allows us to iterate bidirectionally over key/value pairs in the tree.
528 /// // Get a cursor to the first element.
529 /// let mut cursor = tree.cursor_front().unwrap();
530 /// let mut current = cursor.current();
533 /// // Move the cursor, updating it to the 2nd element.
534 /// cursor = cursor.move_next().unwrap();
535 /// current = cursor.current();
538 /// // Peek at the next element without impacting the cursor.
539 /// let next = cursor.peek_next().unwrap();
541 /// current = cursor.current();
544 /// // Moving past the last element causes the cursor to return [`None`].
545 /// cursor = cursor.move_next().unwrap();
546 /// current = cursor.current();
548 /// let cursor = cursor.move_next();
549 /// assert!(cursor.is_none());
554 /// A cursor can also be obtained at the last element in the tree.
567 /// let mut cursor = tree.cursor_back().unwrap();
568 /// let current = cursor.current();
574 /// Obtaining a cursor returns [`None`] if the tree is empty.
600 /// // If the provided key exists, a cursor to that key is returned.
601 /// let cursor = tree.cursor_lower_bound(&20).unwrap();
602 /// let current = cursor.current();
605 /// // If the provided key doesn't exist, a cursor to the first larger element in sort order is ret…
606 /// let cursor = tree.cursor_lower_bound(&25).unwrap();
607 /// let current = cursor.current();
611 /// let cursor = tree.cursor_lower_bound(&55);
612 /// assert!(cursor.is_none());
617 /// The cursor allows mutation of values in the tree.
630 /// // Retrieve a cursor.
631 /// let mut cursor = tree.cursor_front().unwrap();
634 /// let (k, v) = cursor.current_mut();
658 /// let mut cursor = tree.cursor_front().unwrap();
659 /// let mut current = cursor.current();
661 /// cursor = cursor.remove_current().0.unwrap();
664 /// current = cursor.current();
667 /// // Get a cursor to the last element, and remove it.
668 /// cursor = tree.cursor_back().unwrap();
669 /// current = cursor.current();
673 /// cursor = cursor.remove_current().0.unwrap();
674 /// current = cursor.current();
678 /// assert!(cursor.remove_current().0.is_none());
696 /// // Get a cursor to the first element.
697 /// let mut cursor = tree.cursor_front().unwrap();
698 /// let mut current = cursor.current();
702 /// assert!(cursor.remove_prev().is_none());
704 /// // Get a cursor to the last element.
705 /// cursor = tree.cursor_back().unwrap();
706 /// current = cursor.current();
710 /// assert_eq!(cursor.remove_prev().unwrap().to_key_value(), (20, 200));
713 /// assert!(cursor.remove_next().is_none());
716 /// cursor = cursor.move_prev().unwrap();
717 /// current = cursor.current();
721 /// assert_eq!(cursor.remove_next().unwrap().to_key_value(), (30, 300));
729 pub struct Cursor<'a, K, V> { struct
734 // SAFETY: The [`Cursor`] has exclusive access to both `K` and `V`, so it is sufficient to require … argument
735 // The cursor only gives out immutable references to the keys, but since it has excusive access to …
737 unsafe impl<'a, K: Send, V: Send> Send for Cursor<'a, K, V> {} implementation
739 // SAFETY: The [`Cursor`] gives out immutable references to K and mutable references to V,
741 unsafe impl<'a, K: Sync, V: Sync> Sync for Cursor<'a, K, V> {} implementation
743 impl<'a, K, V> Cursor<'a, K, V> { implementation
762 /// Returns a tuple where the first element is a cursor to the next node, if it exists,
774 // SAFETY: The reference to the tree used to create the cursor outlives the cursor, so in remove_current()
780 let cursor = next.or(prev).map(|current| Self { in remove_current() localVariable
785 (cursor, node) in remove_current()
801 // SAFETY: The reference to the tree used to create the cursor outlives the cursor, so in remove_neighbor()
814 /// Move the cursor to the previous node, returning [`None`] if it doesn't exist.
819 /// Move the cursor to the next node, returning [`None`] if it doesn't exist.
833 /// Access the previous node without moving the cursor.
838 /// Access the previous node without moving the cursor.
852 /// Access the previous node mutably without moving the cursor.
857 /// Access the next node mutably without moving the cursor.
923 /// Direction for [`Cursor`] operations.