Skip to content

Commit

Permalink
FEAT: Add .sort_keys()
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Jan 3, 2018
1 parent 3a77c7f commit e711dbb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,18 @@ impl<K, V, S> OrderMap<K, V, S>
});
}

/// Sort the map’s key-value pairs by the default ordering of the keys.
pub fn sort_keys(&mut self)
where K: Ord,
{
self.sort_by(|k1, _, k2, _| Ord::cmp(k1, k2))
}

/// Sort the map’s key-value pairs in place using the comparison
/// function `compare`.
///
/// The comparison function receives two key and value pairs to compare (you
/// can sort by keys or values or their combination as needed).
pub fn sort_by<F>(&mut self, mut compare: F)
where F: FnMut(&K, &V, &K, &V) -> Ordering,
{
Expand Down

0 comments on commit e711dbb

Please sign in to comment.