Skip to content

Commit 1c02b8a

Browse files
committed
Merge branch 'main' into histbuf-api-additions
2 parents b4c8ca8 + fc099ec commit 1c02b8a

File tree

12 files changed

+135
-73
lines changed

12 files changed

+135
-73
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Added
1111

1212
- Added `format` macro.
13+
- Added `String::from_utf16`.
1314
- Added `is_filled`, `recent_index`, `oldest`, and `oldest_index` to `HistoryBuffer`
1415

1516
### Changed

src/binary_heap.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//! A priority queue implemented with a binary heap.
22
//!
3-
//! Insertion and popping the largest element have `O(log n)` time complexity. Checking the largest
4-
//! / smallest element is `O(1)`.
3+
//! Insertion and popping the largest element have *O*(log n) time complexity.
4+
//! Checking the smallest/largest element is *O*(1).
55
66
// TODO not yet implemented
7-
// Converting a vector to a binary heap can be done in-place, and has `O(n)` complexity. A binary
8-
// heap can also be converted to a sorted vector in-place, allowing it to be used for an `O(n log
9-
// n)` in-place heapsort.
7+
// Converting a vector to a binary heap can be done in-place, and has *O*(n) complexity. A binary
8+
// heap can also be converted to a sorted vector in-place, allowing it to be used for an
9+
// *O*(n log n) in-place heapsort.
1010

1111
use core::{
1212
cmp::Ordering,
@@ -97,7 +97,6 @@ impl private::Sealed for Min {}
9797
/// // The heap should now be empty.
9898
/// assert!(heap.is_empty())
9999
/// ```
100-
101100
pub struct BinaryHeap<T, K, const N: usize> {
102101
pub(crate) _kind: PhantomData<K>,
103102
pub(crate) data: Vec<T, N>,
@@ -337,7 +336,7 @@ where
337336
self.sift_up(0, old_len);
338337
}
339338

340-
/// Returns the underlying ```Vec<T,N>```. Order is arbitrary and time is O(1).
339+
/// Returns the underlying `Vec<T,N>`. Order is arbitrary and time is *O*(1).
341340
pub fn into_vec(self) -> Vec<T, N> {
342341
self.data
343342
}

src/indexmap.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use hash32::{BuildHasherDefault, FnvHasher};
1212

1313
use crate::Vec;
1414

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

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

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

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

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

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

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

754754
/// Remove all key-value pairs in the map, while preserving its capacity.
755755
///
756-
/// Computes in **O(n)** time.
756+
/// Computes in *O*(n) time.
757757
///
758758
/// ```
759759
/// use heapless::FnvIndexMap;
@@ -815,7 +815,7 @@ where
815815
/// The key may be any borrowed form of the map's key type, but `Hash` and `Eq` on the borrowed
816816
/// form *must* match those for the key type.
817817
///
818-
/// Computes in **O(1)** time (average).
818+
/// Computes in *O*(1) time (average).
819819
///
820820
/// ```
821821
/// use heapless::FnvIndexMap;
@@ -839,7 +839,7 @@ where
839839
/// The key may be any borrowed form of the map's key type, but `Hash` and `Eq` on the borrowed
840840
/// form *must* match those for the key type.
841841
///
842-
/// Computes in **O(1)** time (average).
842+
/// Computes in *O*(1) time (average).
843843
///
844844
/// # Examples
845845
///
@@ -864,7 +864,7 @@ where
864864
/// The key may be any borrowed form of the map's key type, but `Hash` and `Eq` on the borrowed
865865
/// form *must* match those for the key type.
866866
///
867-
/// Computes in **O(1)** time (average).
867+
/// Computes in *O*(1) time (average).
868868
///
869869
/// # Examples
870870
///
@@ -899,7 +899,7 @@ where
899899
/// If no equivalent key existed in the map: the new key-value pair is inserted, last in order,
900900
/// and `None` is returned.
901901
///
902-
/// Computes in **O(1)** time (average).
902+
/// Computes in *O*(1) time (average).
903903
///
904904
/// See also entry if you you want to insert or modify or if you need to get the index of the
905905
/// corresponding key-value pair.
@@ -927,7 +927,7 @@ where
927927

928928
/// Same as [`swap_remove`](Self::swap_remove)
929929
///
930-
/// Computes in **O(1)** time (average).
930+
/// Computes in *O*(1) time (average).
931931
///
932932
/// # Examples
933933
///
@@ -954,7 +954,7 @@ where
954954
///
955955
/// Return `None` if `key` is not in map.
956956
///
957-
/// Computes in **O(1)** time (average).
957+
/// Computes in *O*(1) time (average).
958958
pub fn swap_remove<Q>(&mut self, key: &Q) -> Option<V>
959959
where
960960
K: Borrow<Q>,

src/indexset.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use core::{
77
};
88
use hash32::{BuildHasherDefault, FnvHasher};
99

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

136136
/// Get the first value
137137
///
138-
/// Computes in **O(1)** time
138+
/// Computes in *O*(1) time
139139
pub fn first(&self) -> Option<&T> {
140140
self.map.first().map(|(k, _v)| k)
141141
}
142142

143143
/// Get the last value
144144
///
145-
/// Computes in **O(1)** time
145+
/// Computes in *O*(1) time
146146
pub fn last(&self) -> Option<&T> {
147147
self.map.last().map(|(k, _v)| k)
148148
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
//! Because they have fixed capacity `heapless` data structures don't implicitly reallocate. This
3434
//! means that operations like `heapless::Vec.push` are *truly* constant time rather than amortized
3535
//! constant time with potentially unbounded (depends on the allocator) worst case execution time
36-
//! (which is bad / unacceptable for hard real time applications).
36+
//! (which is bad/unacceptable for hard real time applications).
3737
//!
3838
//! `heapless` data structures don't use a memory allocator which means no risk of an uncatchable
3939
//! Out Of Memory (OOM) condition while performing operations on them. It's certainly possible to
@@ -97,7 +97,7 @@ mod histbuf;
9797
mod indexmap;
9898
mod indexset;
9999
mod linear_map;
100-
mod string;
100+
pub mod string;
101101
mod vec;
102102

103103
#[cfg(feature = "serde")]

src/linear_map.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use crate::Vec;
22
use core::{borrow::Borrow, fmt, iter::FromIterator, mem, ops, slice};
33

4-
/// A fixed capacity map / dictionary that performs lookups via linear search
4+
/// A fixed capacity map/dictionary that performs lookups via linear search.
55
///
6-
/// Note that as this map doesn't use hashing so most operations are **O(N)** instead of O(1)
6+
/// Note that as this map doesn't use hashing so most operations are *O*(n) instead of *O*(1).
77
88
pub struct LinearMap<K, V, const N: usize> {
99
pub(crate) buffer: Vec<(K, V), N>,
1010
}
1111

1212
impl<K, V, const N: usize> LinearMap<K, V, N> {
13-
/// Creates an empty `LinearMap`
13+
/// Creates an empty `LinearMap`.
1414
///
1515
/// # Examples
1616
///
@@ -32,9 +32,9 @@ impl<K, V, const N: usize> LinearMap<K, V, N>
3232
where
3333
K: Eq,
3434
{
35-
/// Returns the number of elements that the map can hold
35+
/// Returns the number of elements that the map can hold.
3636
///
37-
/// Computes in **O(1)** time
37+
/// Computes in *O*(1) time.
3838
///
3939
/// # Examples
4040
///
@@ -48,9 +48,9 @@ where
4848
N
4949
}
5050

51-
/// Clears the map, removing all key-value pairs
51+
/// Clears the map, removing all key-value pairs.
5252
///
53-
/// Computes in **O(1)** time
53+
/// Computes in *O*(1) time.
5454
///
5555
/// # Examples
5656
///
@@ -68,7 +68,7 @@ where
6868

6969
/// Returns true if the map contains a value for the specified key.
7070
///
71-
/// Computes in **O(N)** time
71+
/// Computes in *O*(n) time.
7272
///
7373
/// # Examples
7474
///
@@ -84,9 +84,9 @@ where
8484
self.get(key).is_some()
8585
}
8686

87-
/// Returns a reference to the value corresponding to the key
87+
/// Returns a reference to the value corresponding to the key.
8888
///
89-
/// Computes in **O(N)** time
89+
/// Computes in *O*(n) time.
9090
///
9191
/// # Examples
9292
///
@@ -108,9 +108,9 @@ where
108108
.map(|(_, v)| v)
109109
}
110110

111-
/// Returns a mutable reference to the value corresponding to the key
111+
/// Returns a mutable reference to the value corresponding to the key.
112112
///
113-
/// Computes in **O(N)** time
113+
/// Computes in *O*(n) time.
114114
///
115115
/// # Examples
116116
///
@@ -134,9 +134,9 @@ where
134134
.map(|(_, v)| v)
135135
}
136136

137-
/// Returns the number of elements in this map
137+
/// Returns the number of elements in this map.
138138
///
139-
/// Computes in **O(1)** time
139+
/// Computes in *O*(1) time.
140140
///
141141
/// # Examples
142142
///
@@ -158,7 +158,7 @@ where
158158
///
159159
/// If the map did have this key present, the value is updated, and the old value is returned.
160160
///
161-
/// Computes in **O(N)** time
161+
/// Computes in *O*(n) time
162162
///
163163
/// # Examples
164164
///
@@ -183,9 +183,9 @@ where
183183
Ok(None)
184184
}
185185

186-
/// Returns true if the map contains no elements
186+
/// Returns true if the map contains no elements.
187187
///
188-
/// Computes in **O(1)** time
188+
/// Computes in *O*(1) time.
189189
///
190190
/// # Examples
191191
///
@@ -223,8 +223,8 @@ where
223223
}
224224
}
225225

226-
/// An iterator visiting all key-value pairs in arbitrary order, with mutable references to the
227-
/// values
226+
/// An iterator visiting all key-value pairs in arbitrary order,
227+
/// with mutable references to the values.
228228
///
229229
/// # Examples
230230
///
@@ -251,7 +251,7 @@ where
251251
}
252252
}
253253

254-
/// An iterator visiting all keys in arbitrary order
254+
/// An iterator visiting all keys in arbitrary order.
255255
///
256256
/// # Examples
257257
///
@@ -271,10 +271,10 @@ where
271271
self.iter().map(|(k, _)| k)
272272
}
273273

274-
/// Removes a key from the map, returning the value at the key if the key was previously in the
275-
/// map
274+
/// Removes a key from the map, returning the value at
275+
/// the key if the key was previously in the map.
276276
///
277-
/// Computes in **O(N)** time
277+
/// Computes in *O*(n) time
278278
///
279279
/// # Examples
280280
///
@@ -300,7 +300,7 @@ where
300300
idx.map(|idx| self.buffer.swap_remove(idx).1)
301301
}
302302

303-
/// An iterator visiting all values in arbitrary order
303+
/// An iterator visiting all values in arbitrary order.
304304
///
305305
/// # Examples
306306
///
@@ -320,7 +320,7 @@ where
320320
self.iter().map(|(_, v)| v)
321321
}
322322

323-
/// An iterator visiting all values mutably in arbitrary order
323+
/// An iterator visiting all values mutably in arbitrary order.
324324
///
325325
/// # Examples
326326
///

0 commit comments

Comments
 (0)