From 008828f4a58e3a38b2241bf3eae536dc97efd0a2 Mon Sep 17 00:00:00 2001 From: Martin Becker Date: Fri, 31 Jan 2020 14:24:03 +0000 Subject: [PATCH 1/4] Adds get_index to map.rs --- src/map.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/map.rs b/src/map.rs index eecd55a1..cd819d7a 100644 --- a/src/map.rs +++ b/src/map.rs @@ -1031,6 +1031,19 @@ where } } + /// Return item index + pub fn get_index(&self, key: &Q) -> Option + where + Q: Hash + Equivalent, + { + if let Some((_, found)) = self.find(key) { + let entry = &self.core.entries[found]; + Some(found) + } else { + None + } + } + pub fn get_mut(&mut self, key: &Q) -> Option<&mut V> where Q: Hash + Equivalent, From 22d1c7247fc0146d14263823471879080c21ae45 Mon Sep 17 00:00:00 2001 From: Martin Becker Date: Fri, 31 Jan 2020 14:34:14 +0000 Subject: [PATCH 2/4] Renames get_index to entry_index --- src/map.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map.rs b/src/map.rs index cd819d7a..da85d921 100644 --- a/src/map.rs +++ b/src/map.rs @@ -1032,7 +1032,7 @@ where } /// Return item index - pub fn get_index(&self, key: &Q) -> Option + pub fn entry_index(&self, key: &Q) -> Option where Q: Hash + Equivalent, { From 29819a2ff42697f3e9804aec3195d3b9ce92791a Mon Sep 17 00:00:00 2001 From: Martin Becker Date: Mon, 10 Feb 2020 12:37:52 +0000 Subject: [PATCH 3/4] Removes superlous variable binding --- src/map.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/map.rs b/src/map.rs index da85d921..b346b77d 100644 --- a/src/map.rs +++ b/src/map.rs @@ -1037,7 +1037,6 @@ where Q: Hash + Equivalent, { if let Some((_, found)) = self.find(key) { - let entry = &self.core.entries[found]; Some(found) } else { None From 7dcdd69be9d1075046179a0b89f960274e1396e2 Mon Sep 17 00:00:00 2001 From: Martin Becker Date: Mon, 10 Feb 2020 12:38:25 +0000 Subject: [PATCH 4/4] Add entry_insex to set.rs --- src/set.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/set.rs b/src/set.rs index 4b83f4b5..005e1ff5 100644 --- a/src/set.rs +++ b/src/set.rs @@ -327,6 +327,14 @@ where self.map.get_full(value).map(|(i, x, &())| (i, x)) } + /// Return item index + pub fn entry_index(&self, value: &Q) -> Option<(usize)> + where + Q: Hash + Equivalent, + { + self.map.entry_index(value) + } + /// Adds a value to the set, replacing the existing value, if any, that is /// equal to the given one. Returns the replaced value. ///