Skip to content

Commit

Permalink
Run through rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Nov 1, 2015
1 parent 776046c commit 58e2223
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 112 deletions.
27 changes: 19 additions & 8 deletions phf/src/map.rs
Expand Up @@ -14,7 +14,7 @@ use phf_shared;
/// The fields of this struct are public so that they may be initialized by the
/// `phf_map!` macro and code generation. They are subject to change at any
/// time and should never be accessed directly.
pub struct Map<K:'static, V:'static> {
pub struct Map<K: 'static, V: 'static> {
#[doc(hidden)]
pub key: u64,
#[doc(hidden)]
Expand Down Expand Up @@ -49,26 +49,37 @@ impl<K, V> Map<K, V> {
}

/// Determines if `key` is in the `Map`.
pub fn contains_key<T: ?Sized>(&self, key: &T) -> bool where T: Eq + PhfHash, K: Borrow<T> {
pub fn contains_key<T: ?Sized>(&self, key: &T) -> bool
where T: Eq + PhfHash,
K: Borrow<T>
{
self.get(key).is_some()
}

/// Returns a reference to the value that `key` maps to.
pub fn get<T: ?Sized>(&self, key: &T) -> Option<&V> where T: Eq + PhfHash, K: Borrow<T> {
pub fn get<T: ?Sized>(&self, key: &T) -> Option<&V>
where T: Eq + PhfHash,
K: Borrow<T>
{
self.get_entry(key).map(|e| e.1)
}

/// Returns a reference to the map's internal static instance of the given
/// key.
///
/// This can be useful for interning schemes.
pub fn get_key<T: ?Sized>(&self, key: &T) -> Option<&K> where T: Eq + PhfHash, K: Borrow<T> {
pub fn get_key<T: ?Sized>(&self, key: &T) -> Option<&K>
where T: Eq + PhfHash,
K: Borrow<T>
{
self.get_entry(key).map(|e| e.0)
}

/// Like `get`, but returns both the key and the value.
pub fn get_entry<T: ?Sized>(&self, key: &T) -> Option<(&K, &V)>
where T: Eq + PhfHash, K: Borrow<T> {
where T: Eq + PhfHash,
K: Borrow<T>
{
let hash = phf_shared::hash(key, self.key);
let index = phf_shared::get_index(hash, self.disps, self.entries.len());
let entry = &self.entries[index as usize];
Expand Down Expand Up @@ -112,7 +123,7 @@ impl<'a, K, V> IntoIterator for &'a Map<K, V> {
}

/// An iterator over the key/value pairs in a `Map`.
pub struct Entries<'a, K:'a, V:'a> {
pub struct Entries<'a, K: 'a, V: 'a> {
iter: slice::Iter<'a, (K, V)>,
}

Expand All @@ -137,7 +148,7 @@ impl<'a, K, V> DoubleEndedIterator for Entries<'a, K, V> {
impl<'a, K, V> ExactSizeIterator for Entries<'a, K, V> {}

/// An iterator over the keys in a `Map`.
pub struct Keys<'a, K:'a, V:'a> {
pub struct Keys<'a, K: 'a, V: 'a> {
iter: Entries<'a, K, V>,
}

Expand All @@ -162,7 +173,7 @@ impl<'a, K, V> DoubleEndedIterator for Keys<'a, K, V> {
impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {}

/// An iterator over the values in a `Map`.
pub struct Values<'a, K:'a, V:'a> {
pub struct Values<'a, K: 'a, V: 'a> {
iter: Entries<'a, K, V>,
}

Expand Down
35 changes: 25 additions & 10 deletions phf/src/ordered_map.rs
Expand Up @@ -18,7 +18,7 @@ use phf_shared;
/// The fields of this struct are public so that they may be initialized by the
/// `phf_ordered_map!` macro and code generation. They are subject to change at
/// any time and should never be accessed directly.
pub struct OrderedMap<K:'static, V:'static> {
pub struct OrderedMap<K: 'static, V: 'static> {
#[doc(hidden)]
pub key: u64,
#[doc(hidden)]
Expand Down Expand Up @@ -55,27 +55,38 @@ impl<K, V> OrderedMap<K, V> {
}

/// Returns a reference to the value that `key` maps to.
pub fn get<T: ?Sized>(&self, key: &T) -> Option<&V> where T: Eq + PhfHash, K: Borrow<T> {
pub fn get<T: ?Sized>(&self, key: &T) -> Option<&V>
where T: Eq + PhfHash,
K: Borrow<T>
{
self.get_entry(key).map(|e| e.1)
}

/// Returns a reference to the map's internal static instance of the given
/// key.
///
/// This can be useful for interning schemes.
pub fn get_key<T: ?Sized>(&self, key: &T) -> Option<&K> where T: Eq + PhfHash, K: Borrow<T> {
pub fn get_key<T: ?Sized>(&self, key: &T) -> Option<&K>
where T: Eq + PhfHash,
K: Borrow<T>
{
self.get_entry(key).map(|e| e.0)
}

/// Determines if `key` is in the `Map`.
pub fn contains_key<T: ?Sized>(&self, key: &T) -> bool where T: Eq + PhfHash, K: Borrow<T> {
pub fn contains_key<T: ?Sized>(&self, key: &T) -> bool
where T: Eq + PhfHash,
K: Borrow<T>
{
self.get(key).is_some()
}

/// Returns the index of the key within the list used to initialize
/// the ordered map.
pub fn get_index<T: ?Sized>(&self, key: &T) -> Option<usize>
where T: Eq + PhfHash, K: Borrow<T> {
where T: Eq + PhfHash,
K: Borrow<T>
{
self.get_internal(key).map(|(i, _)| i)
}

Expand All @@ -87,12 +98,16 @@ impl<K, V> OrderedMap<K, V> {

/// Like `get`, but returns both the key and the value.
pub fn get_entry<T: ?Sized>(&self, key: &T) -> Option<(&K, &V)>
where T: Eq + PhfHash, K: Borrow<T> {
where T: Eq + PhfHash,
K: Borrow<T>
{
self.get_internal(key).map(|(_, e)| e)
}

fn get_internal<T: ?Sized>(&self, key: &T) -> Option<(usize, (&K, &V))>
where T: Eq + PhfHash, K: Borrow<T> {
where T: Eq + PhfHash,
K: Borrow<T>
{
let hash = phf_shared::hash(key, self.key);
let idx_index = phf_shared::get_index(hash, self.disps, self.idxs.len());
let idx = self.idxs[idx_index as usize];
Expand Down Expand Up @@ -138,7 +153,7 @@ impl<'a, K, V> IntoIterator for &'a OrderedMap<K, V> {
}

/// An iterator over the entries in a `OrderedMap`.
pub struct Entries<'a, K:'a, V:'a> {
pub struct Entries<'a, K: 'a, V: 'a> {
iter: slice::Iter<'a, (K, V)>,
}

Expand All @@ -163,7 +178,7 @@ impl<'a, K, V> DoubleEndedIterator for Entries<'a, K, V> {
impl<'a, K, V> ExactSizeIterator for Entries<'a, K, V> {}

/// An iterator over the keys in a `OrderedMap`.
pub struct Keys<'a, K:'a, V:'a> {
pub struct Keys<'a, K: 'a, V: 'a> {
iter: Entries<'a, K, V>,
}

Expand All @@ -188,7 +203,7 @@ impl<'a, K, V> DoubleEndedIterator for Keys<'a, K, V> {
impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {}

/// An iterator over the values in a `OrderedMap`.
pub struct Values<'a, K:'a, V:'a> {
pub struct Values<'a, K: 'a, V: 'a> {
iter: Entries<'a, K, V>,
}

Expand Down
18 changes: 13 additions & 5 deletions phf/src/ordered_set.rs
Expand Up @@ -15,7 +15,7 @@ use {PhfHash, OrderedMap};
/// The fields of this struct are public so that they may be initialized by the
/// `phf_ordered_set!` macro and code generation. They are subject to change at
/// any time and should never be accessed directly.
pub struct OrderedSet<T:'static> {
pub struct OrderedSet<T: 'static> {
#[doc(hidden)]
pub map: OrderedMap<T, ()>,
}
Expand All @@ -41,14 +41,19 @@ impl<T> OrderedSet<T> {
/// key.
///
/// This can be useful for interning schemes.
pub fn get_key<U: ?Sized>(&self, key: &U) -> Option<&T> where U: Eq + PhfHash, T: Borrow<U> {
pub fn get_key<U: ?Sized>(&self, key: &U) -> Option<&T>
where U: Eq + PhfHash,
T: Borrow<U>
{
self.map.get_key(key)
}

/// Returns the index of the key within the list used to initialize
/// the ordered set.
pub fn get_index<U: ?Sized>(&self, key: &U) -> Option<usize>
where U: Eq + PhfHash, T: Borrow<U> {
where U: Eq + PhfHash,
T: Borrow<U>
{
self.map.get_index(key)
}

Expand All @@ -59,7 +64,10 @@ impl<T> OrderedSet<T> {
}

/// Returns true if `value` is in the `Set`.
pub fn contains<U: ?Sized>(&self, value: &U) -> bool where U: Eq + PhfHash, T: Borrow<U> {
pub fn contains<U: ?Sized>(&self, value: &U) -> bool
where U: Eq + PhfHash,
T: Borrow<U>
{
self.map.contains_key(value)
}

Expand Down Expand Up @@ -101,7 +109,7 @@ impl<'a, T> IntoIterator for &'a OrderedSet<T> {
}

/// An iterator over the values in a `OrderedSet`.
pub struct Iter<'a, T:'a> {
pub struct Iter<'a, T: 'a> {
iter: ordered_map::Keys<'a, T, ()>,
}

Expand Down
16 changes: 11 additions & 5 deletions phf/src/set.rs
Expand Up @@ -14,9 +14,9 @@ use Map;
/// The fields of this struct are public so that they may be initialized by the
/// `phf_set!` macro and code generation. They are subject to change at any
/// time and should never be accessed directly.
pub struct Set<T:'static> {
pub struct Set<T: 'static> {
#[doc(hidden)]
pub map: Map<T, ()>
pub map: Map<T, ()>,
}

impl<T> fmt::Debug for Set<T> where T: fmt::Debug {
Expand All @@ -40,12 +40,18 @@ impl<T> Set<T> {
/// key.
///
/// This can be useful for interning schemes.
pub fn get_key<U: ?Sized>(&self, key: &U) -> Option<&T> where U: Eq + PhfHash, T: Borrow<U> {
pub fn get_key<U: ?Sized>(&self, key: &U) -> Option<&T>
where U: Eq + PhfHash,
T: Borrow<U>
{
self.map.get_key(key)
}

/// Returns true if `value` is in the `Set`.
pub fn contains<U: ?Sized>(&self, value: &U) -> bool where U: Eq + PhfHash, T: Borrow<U> {
pub fn contains<U: ?Sized>(&self, value: &U) -> bool
where U: Eq + PhfHash,
T: Borrow<U>
{
self.map.contains_key(value)
}

Expand Down Expand Up @@ -84,7 +90,7 @@ impl<'a, T> IntoIterator for &'a Set<T> {
}

/// An iterator over the values in a `Set`.
pub struct Iter<'a, T:'static> {
pub struct Iter<'a, T: 'static> {
iter: map::Keys<'a, T, ()>,
}

Expand Down

0 comments on commit 58e2223

Please sign in to comment.