-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martin Taillefer (from Dev Box)
committed
Dec 8, 2024
1 parent
cdd9b79
commit e485cb0
Showing
16 changed files
with
345 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
frozen-collections-core/src/maps/eytzinger_search_map.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
use alloc::boxed::Box; | ||
use alloc::vec::Vec; | ||
use core::borrow::Borrow; | ||
use core::fmt::{Debug, Formatter, Result}; | ||
use core::ops::Index; | ||
|
||
use crate::maps::decl_macros::{ | ||
contains_key_fn, debug_fn, eytzinger_search_core, get_many_mut_body, get_many_mut_fn, index_fn, | ||
into_iter_fn_for_slice, into_iter_mut_ref_fn, into_iter_ref_fn, map_boilerplate_for_slice, | ||
map_iterator_boilerplate_for_slice, partial_eq_fn, | ||
}; | ||
use crate::maps::{IntoIter, IntoKeys, IntoValues, Iter, IterMut, Keys, Values, ValuesMut}; | ||
use crate::traits::{Len, Map, MapIterator}; | ||
use crate::utils::{dedup_by_keep_last, eytzinger_search_by_key, eytzinger_sort}; | ||
|
||
/// A general purpose map implemented using binary search. | ||
/// | ||
#[doc = include_str!("../doc_snippets/type_compat_warning.md")] | ||
#[doc = include_str!("../doc_snippets/about.md")] | ||
#[doc = include_str!("../doc_snippets/order_warning.md")] | ||
/// | ||
#[derive(Clone)] | ||
pub struct EytzingerSearchMap<K, V> { | ||
entries: Box<[(K, V)]>, | ||
} | ||
|
||
impl<K, V> EytzingerSearchMap<K, V> | ||
where | ||
K: Ord, | ||
{ | ||
/// Creates a frozen map. | ||
#[must_use] | ||
pub fn new(mut entries: Vec<(K, V)>) -> Self { | ||
entries.sort_by(|x, y| x.0.cmp(&y.0)); | ||
dedup_by_keep_last(&mut entries, |x, y| x.0.eq(&y.0)); | ||
eytzinger_sort(&mut entries); | ||
Self::new_raw(entries) | ||
} | ||
|
||
/// Creates a frozen map. | ||
#[must_use] | ||
pub(crate) fn new_raw(processed_entries: Vec<(K, V)>) -> Self { | ||
Self { | ||
entries: processed_entries.into_boxed_slice(), | ||
} | ||
} | ||
} | ||
|
||
impl<K, V> EytzingerSearchMap<K, V> { | ||
eytzinger_search_core!(); | ||
} | ||
|
||
impl<K, V> Len for EytzingerSearchMap<K, V> { | ||
fn len(&self) -> usize { | ||
self.entries.len() | ||
} | ||
} | ||
|
||
impl<K, V> Debug for EytzingerSearchMap<K, V> | ||
where | ||
K: Debug, | ||
V: Debug, | ||
{ | ||
debug_fn!(); | ||
} | ||
|
||
impl<K, V> Default for EytzingerSearchMap<K, V> { | ||
fn default() -> Self { | ||
Self { | ||
entries: Box::default(), | ||
} | ||
} | ||
} | ||
|
||
impl<Q, K, V> Index<&Q> for EytzingerSearchMap<K, V> | ||
where | ||
K: Borrow<Q>, | ||
Q: ?Sized + Ord, | ||
{ | ||
index_fn!(); | ||
} | ||
|
||
impl<K, V> IntoIterator for EytzingerSearchMap<K, V> { | ||
into_iter_fn_for_slice!(entries); | ||
} | ||
|
||
impl<'a, K, V> IntoIterator for &'a EytzingerSearchMap<K, V> { | ||
into_iter_ref_fn!(); | ||
} | ||
|
||
impl<'a, K, V> IntoIterator for &'a mut EytzingerSearchMap<K, V> { | ||
into_iter_mut_ref_fn!(); | ||
} | ||
|
||
impl<K, V, MT> PartialEq<MT> for EytzingerSearchMap<K, V> | ||
where | ||
K: Ord, | ||
V: PartialEq, | ||
MT: Map<K, V>, | ||
{ | ||
partial_eq_fn!(); | ||
} | ||
|
||
impl<K, V> Eq for EytzingerSearchMap<K, V> | ||
where | ||
K: Ord, | ||
V: Eq, | ||
{ | ||
} | ||
|
||
impl<K, V> MapIterator<K, V> for EytzingerSearchMap<K, V> { | ||
type Iterator<'a> | ||
= Iter<'a, K, V> | ||
where | ||
K: 'a, | ||
V: 'a; | ||
|
||
type KeyIterator<'a> | ||
= Keys<'a, K, V> | ||
where | ||
K: 'a, | ||
V: 'a; | ||
|
||
type ValueIterator<'a> | ||
= Values<'a, K, V> | ||
where | ||
K: 'a, | ||
V: 'a; | ||
|
||
type MutIterator<'a> | ||
= IterMut<'a, K, V> | ||
where | ||
K: 'a, | ||
V: 'a; | ||
|
||
type ValueMutIterator<'a> | ||
= ValuesMut<'a, K, V> | ||
where | ||
K: 'a, | ||
V: 'a; | ||
|
||
map_iterator_boilerplate_for_slice!(entries); | ||
} | ||
|
||
impl<K, V> Map<K, V> for EytzingerSearchMap<K, V> | ||
where | ||
K: Ord, | ||
{ | ||
map_boilerplate_for_slice!(entries); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//! Simple bit vectors. | ||
use alloc::vec; | ||
use alloc::vec::Vec; | ||
|
||
|
Oops, something went wrong.