Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add String::from_utf16. #306

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Added `format` macro.
- Added `String::from_utf16`.

### Changed

Expand Down
13 changes: 6 additions & 7 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 @@ -97,7 +97,6 @@ impl private::Sealed for Min {}
/// // The heap should now be empty.
/// assert!(heap.is_empty())
/// ```
pub struct BinaryHeap<T, K, const N: usize> {
pub(crate) _kind: PhantomData<K>,
pub(crate) data: Vec<T, N>,
Expand Down Expand Up @@ -337,7 +336,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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -97,7 +97,7 @@ mod histbuf;
mod indexmap;
mod indexset;
mod linear_map;
mod string;
pub mod string;
reitermarkus marked this conversation as resolved.
Show resolved Hide resolved
newAM marked this conversation as resolved.
Show resolved Hide resolved
mod vec;

#[cfg(feature = "serde")]
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
Loading