Skip to content

Commit

Permalink
Improve documentation formatting consistency.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Nov 22, 2023
1 parent 3195233 commit ce7bf45
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 68 deletions.
12 changes: 6 additions & 6 deletions src/binary_heap.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! A priority queue implemented with a binary heap.
//!
//! Insertion and popping the largest element have `O(log n)` time complexity. Checking the largest
//! / smallest element is `O(1)`.
//! Insertion and popping the largest element have *O*(log n) time complexity.
//! Checking the smallest/largest element is *O*(1).

// TODO not yet implemented
// Converting a vector to a binary heap can be done in-place, and has `O(n)` complexity. A binary
// heap can also be converted to a sorted vector in-place, allowing it to be used for an `O(n log
// n)` in-place heapsort.
// Converting a vector to a binary heap can be done in-place, and has *O*(n) complexity. A binary
// heap can also be converted to a sorted vector in-place, allowing it to be used for an
// *O*(n log n) in-place heapsort.

use core::{
cmp::Ordering,
Expand Down Expand Up @@ -337,7 +337,7 @@ where
self.sift_up(0, old_len);
}

/// Returns the underlying ```Vec<T,N>```. Order is arbitrary and time is O(1).
/// Returns the underlying `Vec<T,N>`. Order is arbitrary and time is *O*(1).
pub fn into_vec(self) -> Vec<T, N> {
self.data
}
Expand Down
28 changes: 14 additions & 14 deletions src/indexmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use hash32::{BuildHasherDefault, FnvHasher};

use crate::Vec;

/// A [`IndexMap`] using the default FNV hasher
/// An [`IndexMap`] using the default FNV hasher.
///
/// A list of all Methods and Traits available for `FnvIndexMap` can be found in
/// the [`IndexMap`] documentation.
Expand Down Expand Up @@ -681,7 +681,7 @@ impl<K, V, S, const N: usize> IndexMap<K, V, S, N> {

/// Get the first key-value pair
///
/// Computes in **O(1)** time
/// Computes in *O*(1)* time
pub fn first(&self) -> Option<(&K, &V)> {
self.core
.entries
Expand All @@ -691,7 +691,7 @@ impl<K, V, S, const N: usize> IndexMap<K, V, S, N> {

/// Get the first key-value pair, with mutable access to the value
///
/// Computes in **O(1)** time
/// Computes in *O*(1)* time
pub fn first_mut(&mut self) -> Option<(&K, &mut V)> {
self.core
.entries
Expand All @@ -701,7 +701,7 @@ impl<K, V, S, const N: usize> IndexMap<K, V, S, N> {

/// Get the last key-value pair
///
/// Computes in **O(1)** time
/// Computes in *O*(1)* time
pub fn last(&self) -> Option<(&K, &V)> {
self.core
.entries
Expand All @@ -711,7 +711,7 @@ impl<K, V, S, const N: usize> IndexMap<K, V, S, N> {

/// Get the last key-value pair, with mutable access to the value
///
/// Computes in **O(1)** time
/// Computes in *O*(1)* time
pub fn last_mut(&mut self) -> Option<(&K, &mut V)> {
self.core
.entries
Expand All @@ -721,7 +721,7 @@ impl<K, V, S, const N: usize> IndexMap<K, V, S, N> {

/// Return the number of key-value pairs in the map.
///
/// Computes in **O(1)** time.
/// Computes in *O*(1)* time.
///
/// ```
/// use heapless::FnvIndexMap;
Expand All @@ -737,7 +737,7 @@ impl<K, V, S, const N: usize> IndexMap<K, V, S, N> {

/// Returns true if the map contains no elements.
///
/// Computes in **O(1)** time.
/// Computes in *O*(1)* time.
///
/// ```
/// use heapless::FnvIndexMap;
Expand All @@ -753,7 +753,7 @@ impl<K, V, S, const N: usize> IndexMap<K, V, S, N> {

/// Remove all key-value pairs in the map, while preserving its capacity.
///
/// Computes in **O(n)** time.
/// Computes in *O*(n) time.
///
/// ```
/// use heapless::FnvIndexMap;
Expand Down Expand Up @@ -815,7 +815,7 @@ where
/// The key may be any borrowed form of the map's key type, but `Hash` and `Eq` on the borrowed
/// form *must* match those for the key type.
///
/// Computes in **O(1)** time (average).
/// Computes in *O*(1)* time (average).
///
/// ```
/// use heapless::FnvIndexMap;
Expand All @@ -839,7 +839,7 @@ where
/// The key may be any borrowed form of the map's key type, but `Hash` and `Eq` on the borrowed
/// form *must* match those for the key type.
///
/// Computes in **O(1)** time (average).
/// Computes in *O*(1)* time (average).
///
/// # Examples
///
Expand All @@ -864,7 +864,7 @@ where
/// The key may be any borrowed form of the map's key type, but `Hash` and `Eq` on the borrowed
/// form *must* match those for the key type.
///
/// Computes in **O(1)** time (average).
/// Computes in *O*(1)* time (average).
///
/// # Examples
///
Expand Down Expand Up @@ -899,7 +899,7 @@ where
/// If no equivalent key existed in the map: the new key-value pair is inserted, last in order,
/// and `None` is returned.
///
/// Computes in **O(1)** time (average).
/// Computes in *O*(1)* time (average).
///
/// See also entry if you you want to insert or modify or if you need to get the index of the
/// corresponding key-value pair.
Expand Down Expand Up @@ -927,7 +927,7 @@ where

/// Same as [`swap_remove`](Self::swap_remove)
///
/// Computes in **O(1)** time (average).
/// Computes in *O*(1)* time (average).
///
/// # Examples
///
Expand All @@ -954,7 +954,7 @@ where
///
/// Return `None` if `key` is not in map.
///
/// Computes in **O(1)** time (average).
/// Computes in *O*(1)* time (average).
pub fn swap_remove<Q>(&mut self, key: &Q) -> Option<V>
where
K: Borrow<Q>,
Expand Down
8 changes: 4 additions & 4 deletions src/indexset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use core::{
};
use hash32::{BuildHasherDefault, FnvHasher};

/// A [`IndexSet`] using the
/// default FNV hasher.
/// An [`IndexSet`] using the default FNV hasher.
///
/// A list of all Methods and Traits available for `FnvIndexSet` can be found in
/// the [`IndexSet`] documentation.
///
Expand Down Expand Up @@ -135,14 +135,14 @@ impl<T, S, const N: usize> IndexSet<T, S, N> {

/// Get the first value
///
/// Computes in **O(1)** time
/// Computes in *O*(1)* time
pub fn first(&self) -> Option<&T> {
self.map.first().map(|(k, _v)| k)
}

/// Get the last value
///
/// Computes in **O(1)** time
/// Computes in *O*(1)* time
pub fn last(&self) -> Option<&T> {
self.map.last().map(|(k, _v)| k)
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//! Because they have fixed capacity `heapless` data structures don't implicitly reallocate. This
//! means that operations like `heapless::Vec.push` are *truly* constant time rather than amortized
//! constant time with potentially unbounded (depends on the allocator) worst case execution time
//! (which is bad / unacceptable for hard real time applications).
//! (which is bad/unacceptable for hard real time applications).
//!
//! `heapless` data structures don't use a memory allocator which means no risk of an uncatchable
//! Out Of Memory (OOM) condition while performing operations on them. It's certainly possible to
Expand Down
50 changes: 25 additions & 25 deletions src/linear_map.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use crate::Vec;
use core::{borrow::Borrow, fmt, iter::FromIterator, mem, ops, slice};

/// A fixed capacity map / dictionary that performs lookups via linear search
/// A fixed capacity map/dictionary that performs lookups via linear search.
///
/// Note that as this map doesn't use hashing so most operations are **O(N)** instead of O(1)
/// Note that as this map doesn't use hashing so most operations are *O*(n) instead of *O*(1).

pub struct LinearMap<K, V, const N: usize> {
pub(crate) buffer: Vec<(K, V), N>,
}

impl<K, V, const N: usize> LinearMap<K, V, N> {
/// Creates an empty `LinearMap`
/// Creates an empty `LinearMap`.
///
/// # Examples
///
Expand All @@ -32,9 +32,9 @@ impl<K, V, const N: usize> LinearMap<K, V, N>
where
K: Eq,
{
/// Returns the number of elements that the map can hold
/// Returns the number of elements that the map can hold.
///
/// Computes in **O(1)** time
/// Computes in *O*(1)* time.
///
/// # Examples
///
Expand All @@ -48,9 +48,9 @@ where
N
}

/// Clears the map, removing all key-value pairs
/// Clears the map, removing all key-value pairs.
///
/// Computes in **O(1)** time
/// Computes in *O*(1)* time.
///
/// # Examples
///
Expand All @@ -68,7 +68,7 @@ where

/// Returns true if the map contains a value for the specified key.
///
/// Computes in **O(N)** time
/// Computes in *O*(n) time.
///
/// # Examples
///
Expand All @@ -84,9 +84,9 @@ where
self.get(key).is_some()
}

/// Returns a reference to the value corresponding to the key
/// Returns a reference to the value corresponding to the key.
///
/// Computes in **O(N)** time
/// Computes in *O*(n) time.
///
/// # Examples
///
Expand All @@ -108,9 +108,9 @@ where
.map(|(_, v)| v)
}

/// Returns a mutable reference to the value corresponding to the key
/// Returns a mutable reference to the value corresponding to the key.
///
/// Computes in **O(N)** time
/// Computes in *O*(n) time.
///
/// # Examples
///
Expand All @@ -134,9 +134,9 @@ where
.map(|(_, v)| v)
}

/// Returns the number of elements in this map
/// Returns the number of elements in this map.
///
/// Computes in **O(1)** time
/// Computes in *O*(1)* time.
///
/// # Examples
///
Expand All @@ -158,7 +158,7 @@ where
///
/// If the map did have this key present, the value is updated, and the old value is returned.
///
/// Computes in **O(N)** time
/// Computes in *O*(n) time
///
/// # Examples
///
Expand All @@ -183,9 +183,9 @@ where
Ok(None)
}

/// Returns true if the map contains no elements
/// Returns true if the map contains no elements.
///
/// Computes in **O(1)** time
/// Computes in *O*(1)* time.
///
/// # Examples
///
Expand Down Expand Up @@ -223,8 +223,8 @@ where
}
}

/// An iterator visiting all key-value pairs in arbitrary order, with mutable references to the
/// values
/// An iterator visiting all key-value pairs in arbitrary order,
/// with mutable references to the values.
///
/// # Examples
///
Expand All @@ -251,7 +251,7 @@ where
}
}

/// An iterator visiting all keys in arbitrary order
/// An iterator visiting all keys in arbitrary order.
///
/// # Examples
///
Expand All @@ -271,10 +271,10 @@ where
self.iter().map(|(k, _)| k)
}

/// Removes a key from the map, returning the value at the key if the key was previously in the
/// map
/// Removes a key from the map, returning the value at
/// the key if the key was previously in the map.
///
/// Computes in **O(N)** time
/// Computes in *O*(n) time
///
/// # Examples
///
Expand All @@ -300,7 +300,7 @@ where
idx.map(|idx| self.buffer.swap_remove(idx).1)
}

/// An iterator visiting all values in arbitrary order
/// An iterator visiting all values in arbitrary order.
///
/// # Examples
///
Expand All @@ -320,7 +320,7 @@ where
self.iter().map(|(_, v)| v)
}

/// An iterator visiting all values mutably in arbitrary order
/// An iterator visiting all values mutably in arbitrary order.
///
/// # Examples
///
Expand Down
6 changes: 3 additions & 3 deletions src/mpmc.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! A fixed capacity Multiple-Producer Multiple-Consumer (MPMC) lock-free queue
//! A fixed capacity Multiple-Producer Multiple-Consumer (MPMC) lock-free queue.
//!
//! NOTE: This module requires atomic CAS operations. On targets where they're not natively available,
//! they are emulated by the [`portable-atomic`](https://crates.io/crates/portable-atomic) crate.
//!
//! # Example
//!
//! This queue can be constructed in "const context". Placing it in a `static` variable lets *all*
//! contexts (interrupts / threads / `main`) safely enqueue and dequeue items from it.
//! contexts (interrupts/threads/`main`) safely enqueue and dequeue items from it.
//!
//! ``` ignore
//! #![no_main]
Expand Down Expand Up @@ -62,7 +62,7 @@
//! 2|69 |71 |
//!
//! - `N` denotes the number of *interruptions*. On Cortex-M, an interruption consists of an
//! interrupt handler preempting the would-be atomic section of the `enqueue` / `dequeue`
//! interrupt handler preempting the would-be atomic section of the `enqueue`/`dequeue`
//! operation. Note that it does *not* matter if the higher priority handler uses the queue or
//! not.
//! - All execution times are in clock cycles. 1 clock cycle = 125 ns.
Expand Down
2 changes: 1 addition & 1 deletion src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! # Target support
//!
//! This module / API is only available on these compilation targets:
//! This module/API is only available on these compilation targets:
//!
//! - ARM architectures which instruction set include the LDREX, CLREX and STREX instructions, e.g.
//! `thumbv7m-none-eabi` but not `thumbv6m-none-eabi`
Expand Down
Loading

0 comments on commit ce7bf45

Please sign in to comment.