Skip to content

Commit 7453721

Browse files
authored
Merge pull request #397 from cuviper/no-entries
Remove the internal `trait Entries`
2 parents 3e9ecf2 + b698d3b commit 7453721

File tree

12 files changed

+75
-111
lines changed

12 files changed

+75
-111
lines changed

src/lib.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ extern crate alloc;
108108
#[macro_use]
109109
extern crate std;
110110

111-
use alloc::vec::{self, Vec};
112-
113111
mod arbitrary;
114112
#[macro_use]
115113
mod macros;
@@ -203,16 +201,6 @@ impl<K, V> Bucket<K, V> {
203201
}
204202
}
205203

206-
trait Entries {
207-
type Entry;
208-
fn into_entries(self) -> Vec<Self::Entry>;
209-
fn as_entries(&self) -> &[Self::Entry];
210-
fn as_entries_mut(&mut self) -> &mut [Self::Entry];
211-
fn with_entries<F>(&mut self, f: F)
212-
where
213-
F: FnOnce(&mut [Self::Entry]);
214-
}
215-
216204
/// The error type for [`try_reserve`][IndexMap::try_reserve] methods.
217205
#[derive(Clone, PartialEq, Eq, Debug)]
218206
pub struct TryReserveError {

src/map.rs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use std::collections::hash_map::RandomState;
3838

3939
use self::core::IndexMapCore;
4040
use crate::util::{third, try_simplify_range};
41-
use crate::{Bucket, Entries, Equivalent, GetDisjointMutError, HashValue, TryReserveError};
41+
use crate::{Bucket, Equivalent, GetDisjointMutError, HashValue, TryReserveError};
4242

4343
/// A hash table where the iteration order of the key-value pairs is independent
4444
/// of the hash values of the keys.
@@ -113,32 +113,6 @@ where
113113
}
114114
}
115115

116-
impl<K, V, S> Entries for IndexMap<K, V, S> {
117-
type Entry = Bucket<K, V>;
118-
119-
#[inline]
120-
fn into_entries(self) -> Vec<Self::Entry> {
121-
self.core.into_entries()
122-
}
123-
124-
#[inline]
125-
fn as_entries(&self) -> &[Self::Entry] {
126-
self.core.as_entries()
127-
}
128-
129-
#[inline]
130-
fn as_entries_mut(&mut self) -> &mut [Self::Entry] {
131-
self.core.as_entries_mut()
132-
}
133-
134-
fn with_entries<F>(&mut self, f: F)
135-
where
136-
F: FnOnce(&mut [Self::Entry]),
137-
{
138-
self.core.with_entries(f);
139-
}
140-
}
141-
142116
impl<K, V, S> fmt::Debug for IndexMap<K, V, S>
143117
where
144118
K: fmt::Debug,
@@ -205,6 +179,28 @@ impl<K, V, S> IndexMap<K, V, S> {
205179
}
206180
}
207181

182+
#[inline]
183+
pub(crate) fn into_entries(self) -> Vec<Bucket<K, V>> {
184+
self.core.into_entries()
185+
}
186+
187+
#[inline]
188+
pub(crate) fn as_entries(&self) -> &[Bucket<K, V>] {
189+
self.core.as_entries()
190+
}
191+
192+
#[inline]
193+
pub(crate) fn as_entries_mut(&mut self) -> &mut [Bucket<K, V>] {
194+
self.core.as_entries_mut()
195+
}
196+
197+
pub(crate) fn with_entries<F>(&mut self, f: F)
198+
where
199+
F: FnOnce(&mut [Bucket<K, V>]),
200+
{
201+
self.core.with_entries(f);
202+
}
203+
208204
/// Return the number of elements the map can hold without reallocating.
209205
///
210206
/// This number is a lower bound; the map might be able to hold more,

src/map/core.rs

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ mod entry;
1111

1212
pub mod raw_entry_v1;
1313

14-
use hashbrown::hash_table;
15-
16-
use crate::vec::{self, Vec};
17-
use crate::TryReserveError;
14+
use alloc::vec::{self, Vec};
1815
use core::mem;
1916
use core::ops::RangeBounds;
17+
use hashbrown::hash_table;
2018

2119
use crate::util::simplify_range;
22-
use crate::{Bucket, Equivalent, HashValue};
20+
use crate::{Bucket, Equivalent, HashValue, TryReserveError};
2321

2422
type Indices = hash_table::HashTable<usize>;
2523
type Entries<K, V> = Vec<Bucket<K, V>>;
@@ -109,33 +107,6 @@ where
109107
}
110108
}
111109

112-
impl<K, V> crate::Entries for IndexMapCore<K, V> {
113-
type Entry = Bucket<K, V>;
114-
115-
#[inline]
116-
fn into_entries(self) -> Vec<Self::Entry> {
117-
self.entries
118-
}
119-
120-
#[inline]
121-
fn as_entries(&self) -> &[Self::Entry] {
122-
&self.entries
123-
}
124-
125-
#[inline]
126-
fn as_entries_mut(&mut self) -> &mut [Self::Entry] {
127-
&mut self.entries
128-
}
129-
130-
fn with_entries<F>(&mut self, f: F)
131-
where
132-
F: FnOnce(&mut [Self::Entry]),
133-
{
134-
f(&mut self.entries);
135-
self.rebuild_hash_table();
136-
}
137-
}
138-
139110
impl<K, V> IndexMapCore<K, V> {
140111
/// The maximum capacity before the `entries` allocation would exceed `isize::MAX`.
141112
const MAX_ENTRIES_CAPACITY: usize = (isize::MAX as usize) / mem::size_of::<Bucket<K, V>>();
@@ -161,6 +132,29 @@ impl<K, V> IndexMapCore<K, V> {
161132
}
162133
}
163134

135+
#[inline]
136+
pub(crate) fn into_entries(self) -> Entries<K, V> {
137+
self.entries
138+
}
139+
140+
#[inline]
141+
pub(crate) fn as_entries(&self) -> &[Bucket<K, V>] {
142+
&self.entries
143+
}
144+
145+
#[inline]
146+
pub(crate) fn as_entries_mut(&mut self) -> &mut [Bucket<K, V>] {
147+
&mut self.entries
148+
}
149+
150+
pub(crate) fn with_entries<F>(&mut self, f: F)
151+
where
152+
F: FnOnce(&mut [Bucket<K, V>]),
153+
{
154+
f(&mut self.entries);
155+
self.rebuild_hash_table();
156+
}
157+
164158
#[inline]
165159
pub(crate) fn len(&self) -> usize {
166160
self.indices.len()

src/map/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::core::IndexMapCore;
2-
use super::{Bucket, Entries, IndexMap, Slice};
2+
use super::{Bucket, IndexMap, Slice};
33

44
use alloc::vec::{self, Vec};
55
use core::fmt;

src/map/mutable.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use core::hash::{BuildHasher, Hash};
22

33
use super::{
4-
Bucket, Entries, Entry, Equivalent, IndexMap, IndexedEntry, IterMut2, OccupiedEntry,
5-
VacantEntry,
4+
Bucket, Entry, Equivalent, IndexMap, IndexedEntry, IterMut2, OccupiedEntry, VacantEntry,
65
};
76

87
/// Opt-in mutable access to [`IndexMap`] keys.

src/map/slice.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::{
2-
Bucket, Entries, IndexMap, IntoIter, IntoKeys, IntoValues, Iter, IterMut, Keys, Values,
3-
ValuesMut,
2+
Bucket, IndexMap, IntoIter, IntoKeys, IntoValues, Iter, IterMut, Keys, Values, ValuesMut,
43
};
54
use crate::util::{slice_eq, try_simplify_range};
65
use crate::GetDisjointMutError;

src/rayon/map.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ use super::collect;
77
use rayon::iter::plumbing::{Consumer, ProducerCallback, UnindexedConsumer};
88
use rayon::prelude::*;
99

10-
use crate::vec::Vec;
1110
use alloc::boxed::Box;
11+
use alloc::vec::Vec;
1212
use core::cmp::Ordering;
1313
use core::fmt;
1414
use core::hash::{BuildHasher, Hash};
1515
use core::ops::RangeBounds;
1616

1717
use crate::map::Slice;
1818
use crate::Bucket;
19-
use crate::Entries;
2019
use crate::IndexMap;
2120

2221
impl<K, V, S> IntoParallelIterator for IndexMap<K, V, S>

src/rayon/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
use rayon::prelude::*;
44

55
use alloc::collections::LinkedList;
6-
7-
use crate::vec::Vec;
6+
use alloc::vec::Vec;
87

98
pub mod map;
109
pub mod set;

src/rayon/set.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ use super::collect;
77
use rayon::iter::plumbing::{Consumer, ProducerCallback, UnindexedConsumer};
88
use rayon::prelude::*;
99

10-
use crate::vec::Vec;
1110
use alloc::boxed::Box;
11+
use alloc::vec::Vec;
1212
use core::cmp::Ordering;
1313
use core::fmt;
1414
use core::hash::{BuildHasher, Hash};
1515
use core::ops::RangeBounds;
1616

1717
use crate::set::Slice;
18-
use crate::Entries;
1918
use crate::IndexSet;
2019

2120
type Bucket<T> = crate::Bucket<T, ()>;

src/set.rs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use core::fmt;
2828
use core::hash::{BuildHasher, Hash};
2929
use core::ops::{BitAnd, BitOr, BitXor, Index, RangeBounds, Sub};
3030

31-
use super::{Entries, Equivalent, IndexMap};
31+
use super::{Equivalent, IndexMap};
3232

3333
type Bucket<T> = super::Bucket<T, ()>;
3434

@@ -105,32 +105,6 @@ where
105105
}
106106
}
107107

108-
impl<T, S> Entries for IndexSet<T, S> {
109-
type Entry = Bucket<T>;
110-
111-
#[inline]
112-
fn into_entries(self) -> Vec<Self::Entry> {
113-
self.map.into_entries()
114-
}
115-
116-
#[inline]
117-
fn as_entries(&self) -> &[Self::Entry] {
118-
self.map.as_entries()
119-
}
120-
121-
#[inline]
122-
fn as_entries_mut(&mut self) -> &mut [Self::Entry] {
123-
self.map.as_entries_mut()
124-
}
125-
126-
fn with_entries<F>(&mut self, f: F)
127-
where
128-
F: FnOnce(&mut [Self::Entry]),
129-
{
130-
self.map.with_entries(f);
131-
}
132-
}
133-
134108
impl<T, S> fmt::Debug for IndexSet<T, S>
135109
where
136110
T: fmt::Debug,
@@ -189,6 +163,23 @@ impl<T, S> IndexSet<T, S> {
189163
}
190164
}
191165

166+
#[inline]
167+
pub(crate) fn into_entries(self) -> Vec<Bucket<T>> {
168+
self.map.into_entries()
169+
}
170+
171+
#[inline]
172+
pub(crate) fn as_entries(&self) -> &[Bucket<T>] {
173+
self.map.as_entries()
174+
}
175+
176+
pub(crate) fn with_entries<F>(&mut self, f: F)
177+
where
178+
F: FnOnce(&mut [Bucket<T>]),
179+
{
180+
self.map.with_entries(f);
181+
}
182+
192183
/// Return the number of elements the set can hold without reallocating.
193184
///
194185
/// This number is a lower bound; the set might be able to hold more,

src/set/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Bucket, Entries, IndexSet, Slice};
1+
use super::{Bucket, IndexSet, Slice};
22

33
use alloc::vec::{self, Vec};
44
use core::fmt;

src/set/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Bucket, Entries, IndexSet, IntoIter, Iter};
1+
use super::{Bucket, IndexSet, IntoIter, Iter};
22
use crate::util::{slice_eq, try_simplify_range};
33

44
use alloc::boxed::Box;

0 commit comments

Comments
 (0)