From f43a9cf4aa2aefc9e743727697ec65a0ba6cc29e Mon Sep 17 00:00:00 2001 From: Floogle <18466542+skyfloogle@users.noreply.github.com> Date: Wed, 9 Jun 2021 16:54:03 +0200 Subject: [PATCH] Replace `std::borrow::Borrow` with `PhfBorrow` for ordered maps and sets --- phf/src/ordered_map.rs | 17 ++++++++--------- phf/src/ordered_set.rs | 10 +++++----- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/phf/src/ordered_map.rs b/phf/src/ordered_map.rs index f91b36cc..fa028d07 100644 --- a/phf/src/ordered_map.rs +++ b/phf/src/ordered_map.rs @@ -1,10 +1,9 @@ //! An order-preserving immutable map constructed at compile time. -use core::borrow::Borrow; use core::iter::IntoIterator; use core::ops::Index; use core::fmt; use core::slice; -use phf_shared::{self, PhfHash, HashKey}; +use phf_shared::{self, PhfHash, PhfBorrow, HashKey}; use crate::Slice; @@ -35,7 +34,7 @@ impl fmt::Debug for OrderedMap where K: fmt::Debug, V: fmt::Debug { } } -impl<'a, K, V, T: ?Sized> Index<&'a T> for OrderedMap where T: Eq + PhfHash, K: Borrow { +impl<'a, K, V, T: ?Sized> Index<&'a T> for OrderedMap where T: Eq + PhfHash, K: PhfBorrow { type Output = V; fn index(&self, k: &'a T) -> &V { @@ -57,7 +56,7 @@ impl OrderedMap { /// Returns a reference to the value that `key` maps to. pub fn get(&self, key: &T) -> Option<&V> where T: Eq + PhfHash, - K: Borrow + K: PhfBorrow { self.get_entry(key).map(|e| e.1) } @@ -68,7 +67,7 @@ impl OrderedMap { /// This can be useful for interning schemes. pub fn get_key(&self, key: &T) -> Option<&K> where T: Eq + PhfHash, - K: Borrow + K: PhfBorrow { self.get_entry(key).map(|e| e.0) } @@ -76,7 +75,7 @@ impl OrderedMap { /// Determines if `key` is in the `Map`. pub fn contains_key(&self, key: &T) -> bool where T: Eq + PhfHash, - K: Borrow + K: PhfBorrow { self.get(key).is_some() } @@ -85,7 +84,7 @@ impl OrderedMap { /// the ordered map. pub fn get_index(&self, key: &T) -> Option where T: Eq + PhfHash, - K: Borrow + K: PhfBorrow { self.get_internal(key).map(|(i, _)| i) } @@ -99,14 +98,14 @@ impl OrderedMap { /// Like `get`, but returns both the key and the value. pub fn get_entry(&self, key: &T) -> Option<(&K, &V)> where T: Eq + PhfHash, - K: Borrow + K: PhfBorrow { self.get_internal(key).map(|(_, e)| e) } fn get_internal(&self, key: &T) -> Option<(usize, (&K, &V))> where T: Eq + PhfHash, - K: Borrow + K: PhfBorrow { if self.disps.len() == 0 { return None; } //Prevent panic on empty map let hashes = phf_shared::hash(key, &self.key); diff --git a/phf/src/ordered_set.rs b/phf/src/ordered_set.rs index dbff7de1..9bfea464 100644 --- a/phf/src/ordered_set.rs +++ b/phf/src/ordered_set.rs @@ -1,7 +1,7 @@ //! An order-preserving immutable set constructed at compile time. -use core::borrow::Borrow; use core::iter::IntoIterator; use core::fmt; +use phf_shared::PhfBorrow; use crate::{ordered_map, PhfHash, OrderedMap}; /// An order-preserving immutable set constructed at compile time. @@ -42,7 +42,7 @@ impl OrderedSet { /// This can be useful for interning schemes. pub fn get_key(&self, key: &U) -> Option<&T> where U: Eq + PhfHash, - T: Borrow + T: PhfBorrow { self.map.get_key(key) } @@ -51,7 +51,7 @@ impl OrderedSet { /// the ordered set. pub fn get_index(&self, key: &U) -> Option where U: Eq + PhfHash, - T: Borrow + T: PhfBorrow { self.map.get_index(key) } @@ -65,7 +65,7 @@ impl OrderedSet { /// Returns true if `value` is in the `Set`. pub fn contains(&self, value: &U) -> bool where U: Eq + PhfHash, - T: Borrow + T: PhfBorrow { self.map.contains_key(value) } @@ -78,7 +78,7 @@ impl OrderedSet { } } -impl OrderedSet where T: Eq + PhfHash { +impl OrderedSet where T: Eq + PhfHash + PhfBorrow { /// Returns true if `other` shares no elements with `self`. #[inline] pub fn is_disjoint(&self, other: &OrderedSet) -> bool {