Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Stephane Raux <94983192+stefunctional@users.noreply.github.com>
  • Loading branch information
mulmarta and stefunctional authored Jun 12, 2024
1 parent 95f7ea6 commit 03c314d
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions mls-rs/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod map_impl {

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SmallMap<K: Hash + Eq + PartialEq, V>(pub(super) HashMap<K, V>);
pub struct SmallMap<K: Hash + Eq, V>(pub(super) HashMap<K, V>);

pub type LargeMap<K, V> = SmallMap<K, V>;
pub(super) type SmallMapInner<K, V> = HashMap<K, V>;
Expand All @@ -38,14 +38,14 @@ mod map_impl {
use itertools::Itertools;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SmallMap<K: Hash + Eq + PartialEq, V>(pub(super) Vec<(K, V)>);
pub struct SmallMap<K: Hash + Eq, V>(pub(super) Vec<(K, V)>);

pub type LargeMap<K, V> = BTreeMap<K, V>;
pub(super) type SmallMapInner<K, V> = Vec<(K, V)>;
pub type LargeMapEntry<'a, K, V> = Entry<'a, K, V>;

#[cfg(feature = "by_ref_proposal")]
impl<K: Hash + Eq + PartialEq, V> SmallMap<K, V> {
impl<K: Hash + Eq, V> SmallMap<K, V> {
pub fn get(&self, key: &K) -> Option<&V> {
self.find(key).map(|i| &self.0[i].1)
}
Expand All @@ -64,35 +64,34 @@ mod map_impl {
fn find(&self, key: &K) -> Option<usize> {
self.0
.iter()
.find_position(|(k, _)| k == key)
.map(|(i, _)| i)
.position(|(k, _)| k == key)
}
}
}

impl<K: Hash + Eq + PartialEq, V> Default for SmallMap<K, V> {
impl<K: Hash + Eq, V> Default for SmallMap<K, V> {
fn default() -> Self {
Self(SmallMapInner::new())
}
}

impl<K: Hash + Eq + PartialEq, V> Deref for SmallMap<K, V> {
impl<K: Hash + Eq, V> Deref for SmallMap<K, V> {
type Target = SmallMapInner<K, V>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl<K: Hash + Eq + PartialEq, V> DerefMut for SmallMap<K, V> {
impl<K: Hash + Eq, V> DerefMut for SmallMap<K, V> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl<K, V> MlsDecode for SmallMap<K, V>
where
K: Hash + Eq + PartialEq + MlsEncode + MlsDecode + MlsSize,
K: Hash + Eq + MlsEncode + MlsDecode + MlsSize,
V: MlsEncode + MlsDecode + MlsSize,
{
fn mls_decode(reader: &mut &[u8]) -> Result<Self, mls_rs_codec::Error> {
Expand All @@ -102,7 +101,7 @@ where

impl<K, V> MlsSize for SmallMap<K, V>
where
K: Hash + Eq + PartialEq + MlsEncode + MlsDecode + MlsSize,
K: Hash + Eq + MlsEncode + MlsDecode + MlsSize,
V: MlsEncode + MlsDecode + MlsSize,
{
fn mls_encoded_len(&self) -> usize {
Expand All @@ -112,7 +111,7 @@ where

impl<K, V> MlsEncode for SmallMap<K, V>
where
K: Hash + Eq + PartialEq + MlsEncode + MlsDecode + MlsSize,
K: Hash + Eq + MlsEncode + MlsDecode + MlsSize,
V: MlsEncode + MlsDecode + MlsSize,
{
fn mls_encode(&self, writer: &mut Vec<u8>) -> Result<(), mls_rs_codec::Error> {
Expand Down

0 comments on commit 03c314d

Please sign in to comment.