Skip to content

Commit 4c262c6

Browse files
committed
Remove duplicate swap functions and unneeded AsBytes bounds
1 parent f0379c4 commit 4c262c6

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

benches/common.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use std::{ffi::CString, sync::OnceLock};
22

33
use blart::{
44
tests_common::{
5-
generate_key_fixed_length, generate_key_with_prefix, generate_keys_skewed, PrefixExpansion,
5+
generate_key_fixed_length, generate_key_with_prefix, generate_keys_skewed, swap,
6+
PrefixExpansion,
67
},
78
AsBytes, TreeMap,
89
};
@@ -137,10 +138,6 @@ pub fn with_prefixes_tree() -> &'static TreeMap<Box<[u8]>, usize> {
137138
}
138139

139140
pub fn dictionary_tree() -> &'static TreeMap<CString, usize> {
140-
fn swap<A, B>((a, b): (A, B)) -> (B, A) {
141-
(b, a)
142-
}
143-
144141
static TREE: OnceLock<TreeMap<CString, usize>> = OnceLock::new();
145142

146143
TREE.get_or_init(|| {

src/collections/map.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,15 +1479,15 @@ where
14791479

14801480
impl<K, V, const PREFIX_LEN: usize> Debug for TreeMap<K, V, PREFIX_LEN>
14811481
where
1482-
K: Debug + AsBytes,
1482+
K: Debug,
14831483
V: Debug,
14841484
{
14851485
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14861486
f.debug_map().entries(self.iter()).finish()
14871487
}
14881488
}
14891489

1490-
impl<K: AsBytes, V, const PREFIX_LEN: usize> Default for TreeMap<K, V, PREFIX_LEN> {
1490+
impl<K, V, const PREFIX_LEN: usize> Default for TreeMap<K, V, PREFIX_LEN> {
14911491
fn default() -> Self {
14921492
Self::with_prefix_len()
14931493
}
@@ -1544,7 +1544,7 @@ where
15441544

15451545
impl<K, V, const PREFIX_LEN: usize> Hash for TreeMap<K, V, PREFIX_LEN>
15461546
where
1547-
K: Hash + AsBytes,
1547+
K: Hash,
15481548
V: Hash,
15491549
{
15501550
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
@@ -1567,7 +1567,7 @@ where
15671567
}
15681568
}
15691569

1570-
impl<'a, K: AsBytes, V, const PREFIX_LEN: usize> IntoIterator for &'a TreeMap<K, V, PREFIX_LEN> {
1570+
impl<'a, K, V, const PREFIX_LEN: usize> IntoIterator for &'a TreeMap<K, V, PREFIX_LEN> {
15711571
type IntoIter = TreeIterator<'a, K, V, PREFIX_LEN>;
15721572
type Item = (&'a K, &'a V);
15731573

@@ -1576,9 +1576,7 @@ impl<'a, K: AsBytes, V, const PREFIX_LEN: usize> IntoIterator for &'a TreeMap<K,
15761576
}
15771577
}
15781578

1579-
impl<'a, K: AsBytes, V, const PREFIX_LEN: usize> IntoIterator
1580-
for &'a mut TreeMap<K, V, PREFIX_LEN>
1581-
{
1579+
impl<'a, K, V, const PREFIX_LEN: usize> IntoIterator for &'a mut TreeMap<K, V, PREFIX_LEN> {
15821580
type IntoIter = TreeIteratorMut<'a, K, V, PREFIX_LEN>;
15831581
type Item = (&'a K, &'a mut V);
15841582

@@ -1587,7 +1585,7 @@ impl<'a, K: AsBytes, V, const PREFIX_LEN: usize> IntoIterator
15871585
}
15881586
}
15891587

1590-
impl<K: AsBytes, V, const PREFIX_LEN: usize> IntoIterator for TreeMap<K, V, PREFIX_LEN> {
1588+
impl<K, V, const PREFIX_LEN: usize> IntoIterator for TreeMap<K, V, PREFIX_LEN> {
15911589
type IntoIter = iterators::IntoIter<K, V, PREFIX_LEN>;
15921590
type Item = (K, V);
15931591

@@ -1598,7 +1596,7 @@ impl<K: AsBytes, V, const PREFIX_LEN: usize> IntoIterator for TreeMap<K, V, PREF
15981596

15991597
impl<K, V, const PREFIX_LEN: usize> Ord for TreeMap<K, V, PREFIX_LEN>
16001598
where
1601-
K: Ord + AsBytes,
1599+
K: Ord,
16021600
V: Ord,
16031601
{
16041602
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
@@ -1608,7 +1606,7 @@ where
16081606

16091607
impl<K, V, const PREFIX_LEN: usize> PartialOrd for TreeMap<K, V, PREFIX_LEN>
16101608
where
1611-
K: PartialOrd + AsBytes,
1609+
K: PartialOrd,
16121610
V: PartialOrd,
16131611
{
16141612
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
@@ -1618,14 +1616,14 @@ where
16181616

16191617
impl<K, V, const PREFIX_LEN: usize> Eq for TreeMap<K, V, PREFIX_LEN>
16201618
where
1621-
K: Eq + AsBytes,
1619+
K: Eq,
16221620
V: Eq,
16231621
{
16241622
}
16251623

16261624
impl<K, V, const PREFIX_LEN: usize> PartialEq for TreeMap<K, V, PREFIX_LEN>
16271625
where
1628-
K: PartialEq + AsBytes,
1626+
K: PartialEq,
16291627
V: PartialEq,
16301628
{
16311629
fn eq(&self, other: &Self) -> bool {
@@ -1638,7 +1636,7 @@ where
16381636
// are also safe
16391637
unsafe impl<K, V, const PREFIX_LEN: usize> Send for TreeMap<K, V, PREFIX_LEN>
16401638
where
1641-
K: Send + AsBytes,
1639+
K: Send,
16421640
V: Send,
16431641
{
16441642
}
@@ -1648,7 +1646,7 @@ where
16481646
// are also safe
16491647
unsafe impl<K, V, const PREFIX_LEN: usize> Sync for TreeMap<K, V, PREFIX_LEN>
16501648
where
1651-
K: Sync + AsBytes,
1649+
K: Sync,
16521650
V: Sync,
16531651
{
16541652
}

src/collections/map/iterators/into_iter.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ mod tests {
172172
Arc,
173173
};
174174

175-
use crate::{AsBytes, NoPrefixesBytes, OrderedBytes};
175+
use crate::{tests_common::swap, AsBytes, NoPrefixesBytes, OrderedBytes};
176176

177177
use super::*;
178178

@@ -224,10 +224,6 @@ mod tests {
224224
fn setup_will_deallocate_unconsumed_iter_values(
225225
drop_counter: &Arc<AtomicUsize>,
226226
) -> TreeMap<DropCounter<[u8; 3]>, usize> {
227-
fn swap<A, B>((a, b): (A, B)) -> (B, A) {
228-
(b, a)
229-
}
230-
231227
assert_eq!(drop_counter.load(Ordering::Relaxed), 0);
232228

233229
[

src/collections/map/iterators/range.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,13 +539,11 @@ implement_range_iter!(
539539

540540
#[cfg(test)]
541541
mod tests {
542+
use crate::tests_common::swap;
543+
542544
use super::*;
543545

544546
fn fixture_tree() -> TreeMap<[u8; 3], usize> {
545-
fn swap<A, B>((a, b): (A, B)) -> (B, A) {
546-
(b, a)
547-
}
548-
549547
[
550548
[0, 0, 0],
551549
[0, 0, u8::MAX],

src/tests_common.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ use std::{collections::HashSet, iter};
55
use crate::{AsBytes, InsertPrefixError, InsertResult, OpaqueNodePtr, TreeMap};
66

77
/// This function swaps the elements of a 2-tuple.
8+
///
9+
/// # Examples
10+
///
11+
/// ```
12+
/// use blart::tests_common::swap;
13+
///
14+
/// assert_eq!(swap((1, 2)), (2, 1));
15+
/// ```
816
pub fn swap<A, B>((a, b): (A, B)) -> (B, A) {
917
(b, a)
1018
}

0 commit comments

Comments
 (0)