Skip to content

Commit e7e9f2e

Browse files
committed
Remove IdxSet typedef and Rename {,Hybrid}IdxSetBuf as {,Hybrid}IdxSet.
Now that the `Buf` vs. non-`Buf` distinction has been removed, it makes sense to drop the `Buf` suffix and use the shorter names everywhere.
1 parent ab8dfbc commit e7e9f2e

File tree

14 files changed

+111
-114
lines changed

14 files changed

+111
-114
lines changed

src/librustc/ty/query/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
4949
use util::common::{ErrorReported};
5050
use util::profiling::ProfileCategory::*;
5151

52-
use rustc_data_structures::indexed_set::IdxSetBuf;
52+
use rustc_data_structures::indexed_set::IdxSet;
5353
use rustc_target::spec::PanicStrategy;
5454
use rustc_data_structures::indexed_vec::IndexVec;
5555
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -208,7 +208,7 @@ define_queries! { <'tcx>
208208
/// Maps DefId's that have an associated Mir to the result
209209
/// of the MIR qualify_consts pass. The actual meaning of
210210
/// the value isn't known except to the pass itself.
211-
[] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc<IdxSetBuf<mir::Local>>),
211+
[] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc<IdxSet<mir::Local>>),
212212

213213
/// Fetch the MIR for a given def-id right after it's built - this includes
214214
/// unreachable code.

src/librustc_data_structures/indexed_set.rs

+58-61
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,30 @@ use rustc_serialize;
2727
///
2828
/// The representation is dense, using one bit per possible element.
2929
#[derive(Eq, PartialEq)]
30-
pub struct IdxSetBuf<T: Idx> {
30+
pub struct IdxSet<T: Idx> {
3131
_pd: PhantomData<fn(&T)>,
3232
bits: Vec<Word>,
3333
}
3434

35-
// FIXME: temporary
36-
pub type IdxSet<T> = IdxSetBuf<T>;
37-
38-
impl<T: Idx> Clone for IdxSetBuf<T> {
35+
impl<T: Idx> Clone for IdxSet<T> {
3936
fn clone(&self) -> Self {
40-
IdxSetBuf { _pd: PhantomData, bits: self.bits.clone() }
37+
IdxSet { _pd: PhantomData, bits: self.bits.clone() }
4138
}
4239
}
4340

44-
impl<T: Idx> rustc_serialize::Encodable for IdxSetBuf<T> {
41+
impl<T: Idx> rustc_serialize::Encodable for IdxSet<T> {
4542
fn encode<E: rustc_serialize::Encoder>(&self,
4643
encoder: &mut E)
4744
-> Result<(), E::Error> {
4845
self.bits.encode(encoder)
4946
}
5047
}
5148

52-
impl<T: Idx> rustc_serialize::Decodable for IdxSetBuf<T> {
53-
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<IdxSetBuf<T>, D::Error> {
49+
impl<T: Idx> rustc_serialize::Decodable for IdxSet<T> {
50+
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<IdxSet<T>, D::Error> {
5451
let words: Vec<Word> = rustc_serialize::Decodable::decode(d)?;
5552

56-
Ok(IdxSetBuf {
53+
Ok(IdxSet {
5754
_pd: PhantomData,
5855
bits: words,
5956
})
@@ -62,18 +59,18 @@ impl<T: Idx> rustc_serialize::Decodable for IdxSetBuf<T> {
6259

6360
const BITS_PER_WORD: usize = mem::size_of::<Word>() * 8;
6461

65-
impl<T: Idx> fmt::Debug for IdxSetBuf<T> {
62+
impl<T: Idx> fmt::Debug for IdxSet<T> {
6663
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
6764
w.debug_list()
6865
.entries(self.iter())
6966
.finish()
7067
}
7168
}
7269

73-
impl<T: Idx> IdxSetBuf<T> {
70+
impl<T: Idx> IdxSet<T> {
7471
fn new(init: Word, universe_size: usize) -> Self {
7572
let num_words = (universe_size + (BITS_PER_WORD - 1)) / BITS_PER_WORD;
76-
IdxSetBuf {
73+
IdxSet {
7774
_pd: Default::default(),
7875
bits: vec![init; num_words],
7976
}
@@ -92,13 +89,13 @@ impl<T: Idx> IdxSetBuf<T> {
9289
}
9390

9491
/// Duplicates as a hybrid set.
95-
pub fn to_hybrid(&self) -> HybridIdxSetBuf<T> {
92+
pub fn to_hybrid(&self) -> HybridIdxSet<T> {
9693
// This universe_size may be slightly larger than the one specified
9794
// upon creation, due to rounding up to a whole word. That's ok.
9895
let universe_size = self.bits.len() * BITS_PER_WORD;
9996

10097
// Note: we currently don't bother trying to make a Sparse set.
101-
HybridIdxSetBuf::Dense(self.to_owned(), universe_size)
98+
HybridIdxSet::Dense(self.to_owned(), universe_size)
10299
}
103100

104101
/// Removes all elements
@@ -171,20 +168,20 @@ impl<T: Idx> IdxSetBuf<T> {
171168
bitwise(self.words_mut(), other.words(), &Union)
172169
}
173170

174-
/// Like `union()`, but takes a `SparseIdxSetBuf` argument.
175-
fn union_sparse(&mut self, other: &SparseIdxSetBuf<T>) -> bool {
171+
/// Like `union()`, but takes a `SparseIdxSet` argument.
172+
fn union_sparse(&mut self, other: &SparseIdxSet<T>) -> bool {
176173
let mut changed = false;
177174
for elem in other.iter() {
178175
changed |= self.add(&elem);
179176
}
180177
changed
181178
}
182179

183-
/// Like `union()`, but takes a `HybridIdxSetBuf` argument.
184-
pub fn union_hybrid(&mut self, other: &HybridIdxSetBuf<T>) -> bool {
180+
/// Like `union()`, but takes a `HybridIdxSet` argument.
181+
pub fn union_hybrid(&mut self, other: &HybridIdxSet<T>) -> bool {
185182
match other {
186-
HybridIdxSetBuf::Sparse(sparse, _) => self.union_sparse(sparse),
187-
HybridIdxSetBuf::Dense(dense, _) => self.union(dense),
183+
HybridIdxSet::Sparse(sparse, _) => self.union_sparse(sparse),
184+
HybridIdxSet::Dense(dense, _) => self.union(dense),
188185
}
189186
}
190187

@@ -194,20 +191,20 @@ impl<T: Idx> IdxSetBuf<T> {
194191
bitwise(self.words_mut(), other.words(), &Subtract)
195192
}
196193

197-
/// Like `subtract()`, but takes a `SparseIdxSetBuf` argument.
198-
fn subtract_sparse(&mut self, other: &SparseIdxSetBuf<T>) -> bool {
194+
/// Like `subtract()`, but takes a `SparseIdxSet` argument.
195+
fn subtract_sparse(&mut self, other: &SparseIdxSet<T>) -> bool {
199196
let mut changed = false;
200197
for elem in other.iter() {
201198
changed |= self.remove(&elem);
202199
}
203200
changed
204201
}
205202

206-
/// Like `subtract()`, but takes a `HybridIdxSetBuf` argument.
207-
pub fn subtract_hybrid(&mut self, other: &HybridIdxSetBuf<T>) -> bool {
203+
/// Like `subtract()`, but takes a `HybridIdxSet` argument.
204+
pub fn subtract_hybrid(&mut self, other: &HybridIdxSet<T>) -> bool {
208205
match other {
209-
HybridIdxSetBuf::Sparse(sparse, _) => self.subtract_sparse(sparse),
210-
HybridIdxSetBuf::Dense(dense, _) => self.subtract(dense),
206+
HybridIdxSet::Sparse(sparse, _) => self.subtract_sparse(sparse),
207+
HybridIdxSet::Dense(dense, _) => self.subtract(dense),
211208
}
212209
}
213210

@@ -255,15 +252,15 @@ impl<'a, T: Idx> Iterator for Iter<'a, T> {
255252
const SPARSE_MAX: usize = 8;
256253

257254
/// A sparse index set with a maximum of SPARSE_MAX elements. Used by
258-
/// HybridIdxSetBuf; do not use directly.
255+
/// HybridIdxSet; do not use directly.
259256
///
260257
/// The elements are stored as an unsorted vector with no duplicates.
261258
#[derive(Clone, Debug)]
262-
pub struct SparseIdxSetBuf<T: Idx>(ArrayVec<[T; SPARSE_MAX]>);
259+
pub struct SparseIdxSet<T: Idx>(ArrayVec<[T; SPARSE_MAX]>);
263260

264-
impl<T: Idx> SparseIdxSetBuf<T> {
261+
impl<T: Idx> SparseIdxSet<T> {
265262
fn new() -> Self {
266-
SparseIdxSetBuf(ArrayVec::new())
263+
SparseIdxSet(ArrayVec::new())
267264
}
268265

269266
fn len(&self) -> usize {
@@ -296,8 +293,8 @@ impl<T: Idx> SparseIdxSetBuf<T> {
296293
}
297294
}
298295

299-
fn to_dense(&self, universe_size: usize) -> IdxSetBuf<T> {
300-
let mut dense = IdxSetBuf::new_empty(universe_size);
296+
fn to_dense(&self, universe_size: usize) -> IdxSet<T> {
297+
let mut dense = IdxSet::new_empty(universe_size);
301298
for elem in self.0.iter() {
302299
dense.add(elem);
303300
}
@@ -323,97 +320,97 @@ impl<'a, T: Idx> Iterator for SparseIter<'a, T> {
323320
}
324321
}
325322

326-
/// Like IdxSetBuf, but with a hybrid representation: sparse when there are few
323+
/// Like IdxSet, but with a hybrid representation: sparse when there are few
327324
/// elements in the set, but dense when there are many. It's especially
328325
/// efficient for sets that typically have a small number of elements, but a
329326
/// large `universe_size`, and are cleared frequently.
330327
#[derive(Clone, Debug)]
331-
pub enum HybridIdxSetBuf<T: Idx> {
332-
Sparse(SparseIdxSetBuf<T>, usize),
333-
Dense(IdxSetBuf<T>, usize),
328+
pub enum HybridIdxSet<T: Idx> {
329+
Sparse(SparseIdxSet<T>, usize),
330+
Dense(IdxSet<T>, usize),
334331
}
335332

336-
impl<T: Idx> HybridIdxSetBuf<T> {
333+
impl<T: Idx> HybridIdxSet<T> {
337334
pub fn new_empty(universe_size: usize) -> Self {
338-
HybridIdxSetBuf::Sparse(SparseIdxSetBuf::new(), universe_size)
335+
HybridIdxSet::Sparse(SparseIdxSet::new(), universe_size)
339336
}
340337

341338
fn universe_size(&mut self) -> usize {
342339
match *self {
343-
HybridIdxSetBuf::Sparse(_, size) => size,
344-
HybridIdxSetBuf::Dense(_, size) => size,
340+
HybridIdxSet::Sparse(_, size) => size,
341+
HybridIdxSet::Dense(_, size) => size,
345342
}
346343
}
347344

348345
pub fn clear(&mut self) {
349346
let universe_size = self.universe_size();
350-
*self = HybridIdxSetBuf::new_empty(universe_size);
347+
*self = HybridIdxSet::new_empty(universe_size);
351348
}
352349

353350
/// Returns true iff set `self` contains `elem`.
354351
pub fn contains(&self, elem: &T) -> bool {
355352
match self {
356-
HybridIdxSetBuf::Sparse(sparse, _) => sparse.contains(elem),
357-
HybridIdxSetBuf::Dense(dense, _) => dense.contains(elem),
353+
HybridIdxSet::Sparse(sparse, _) => sparse.contains(elem),
354+
HybridIdxSet::Dense(dense, _) => dense.contains(elem),
358355
}
359356
}
360357

361358
/// Adds `elem` to the set `self`.
362359
pub fn add(&mut self, elem: &T) -> bool {
363360
match self {
364-
HybridIdxSetBuf::Sparse(sparse, _) if sparse.len() < SPARSE_MAX => {
361+
HybridIdxSet::Sparse(sparse, _) if sparse.len() < SPARSE_MAX => {
365362
// The set is sparse and has space for `elem`.
366363
sparse.add(elem)
367364
}
368-
HybridIdxSetBuf::Sparse(sparse, _) if sparse.contains(elem) => {
365+
HybridIdxSet::Sparse(sparse, _) if sparse.contains(elem) => {
369366
// The set is sparse and does not have space for `elem`, but
370367
// that doesn't matter because `elem` is already present.
371368
false
372369
}
373-
HybridIdxSetBuf::Sparse(_, _) => {
370+
HybridIdxSet::Sparse(_, _) => {
374371
// The set is sparse and full. Convert to a dense set.
375372
//
376373
// FIXME: This code is awful, but I can't work out how else to
377374
// appease the borrow checker.
378-
let dummy = HybridIdxSetBuf::Sparse(SparseIdxSetBuf::new(), 0);
375+
let dummy = HybridIdxSet::Sparse(SparseIdxSet::new(), 0);
379376
match mem::replace(self, dummy) {
380-
HybridIdxSetBuf::Sparse(sparse, universe_size) => {
377+
HybridIdxSet::Sparse(sparse, universe_size) => {
381378
let mut dense = sparse.to_dense(universe_size);
382379
let changed = dense.add(elem);
383380
assert!(changed);
384-
mem::replace(self, HybridIdxSetBuf::Dense(dense, universe_size));
381+
mem::replace(self, HybridIdxSet::Dense(dense, universe_size));
385382
changed
386383
}
387384
_ => panic!("impossible"),
388385
}
389386
}
390387

391-
HybridIdxSetBuf::Dense(dense, _) => dense.add(elem),
388+
HybridIdxSet::Dense(dense, _) => dense.add(elem),
392389
}
393390
}
394391

395392
/// Removes `elem` from the set `self`.
396393
pub fn remove(&mut self, elem: &T) -> bool {
397394
// Note: we currently don't bother going from Dense back to Sparse.
398395
match self {
399-
HybridIdxSetBuf::Sparse(sparse, _) => sparse.remove(elem),
400-
HybridIdxSetBuf::Dense(dense, _) => dense.remove(elem),
396+
HybridIdxSet::Sparse(sparse, _) => sparse.remove(elem),
397+
HybridIdxSet::Dense(dense, _) => dense.remove(elem),
401398
}
402399
}
403400

404401
/// Converts to a dense set, consuming itself in the process.
405-
pub fn to_dense(self) -> IdxSetBuf<T> {
402+
pub fn to_dense(self) -> IdxSet<T> {
406403
match self {
407-
HybridIdxSetBuf::Sparse(sparse, universe_size) => sparse.to_dense(universe_size),
408-
HybridIdxSetBuf::Dense(dense, _) => dense,
404+
HybridIdxSet::Sparse(sparse, universe_size) => sparse.to_dense(universe_size),
405+
HybridIdxSet::Dense(dense, _) => dense,
409406
}
410407
}
411408

412409
/// Iteration order is unspecified.
413410
pub fn iter(&self) -> HybridIter<T> {
414411
match self {
415-
HybridIdxSetBuf::Sparse(sparse, _) => HybridIter::Sparse(sparse.iter()),
416-
HybridIdxSetBuf::Dense(dense, _) => HybridIter::Dense(dense.iter()),
412+
HybridIdxSet::Sparse(sparse, _) => HybridIter::Sparse(sparse.iter()),
413+
HybridIdxSet::Dense(dense, _) => HybridIter::Dense(dense.iter()),
417414
}
418415
}
419416
}
@@ -439,7 +436,7 @@ fn test_trim_to() {
439436
use std::cmp;
440437

441438
for i in 0..256 {
442-
let mut idx_buf: IdxSetBuf<usize> = IdxSetBuf::new_filled(128);
439+
let mut idx_buf: IdxSet<usize> = IdxSet::new_filled(128);
443440
idx_buf.trim_to(i);
444441

445442
let elems: Vec<usize> = idx_buf.iter().collect();
@@ -452,7 +449,7 @@ fn test_trim_to() {
452449
fn test_set_up_to() {
453450
for i in 0..128 {
454451
for mut idx_buf in
455-
vec![IdxSetBuf::new_empty(128), IdxSetBuf::new_filled(128)]
452+
vec![IdxSet::new_empty(128), IdxSet::new_filled(128)]
456453
.into_iter()
457454
{
458455
idx_buf.set_up_to(i);
@@ -467,7 +464,7 @@ fn test_set_up_to() {
467464
#[test]
468465
fn test_new_filled() {
469466
for i in 0..128 {
470-
let idx_buf = IdxSetBuf::new_filled(i);
467+
let idx_buf = IdxSet::new_filled(i);
471468
let elems: Vec<usize> = idx_buf.iter().collect();
472469
let expected: Vec<usize> = (0..i).collect();
473470
assert_eq!(elems, expected);

src/librustc_data_structures/stable_hasher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl<I: ::indexed_vec::Idx, T, CTX> HashStable<CTX> for ::indexed_vec::IndexVec<
432432
}
433433

434434

435-
impl<I: ::indexed_vec::Idx, CTX> HashStable<CTX> for ::indexed_set::IdxSetBuf<I>
435+
impl<I: ::indexed_vec::Idx, CTX> HashStable<CTX> for ::indexed_set::IdxSet<I>
436436
{
437437
fn hash_stable<W: StableHasherResult>(&self,
438438
ctx: &mut CTX,

src/librustc_data_structures/work_queue.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use indexed_set::IdxSetBuf;
11+
use indexed_set::IdxSet;
1212
use indexed_vec::Idx;
1313
use std::collections::VecDeque;
1414

@@ -20,7 +20,7 @@ use std::collections::VecDeque;
2020
/// and also use a bit set to track occupancy.
2121
pub struct WorkQueue<T: Idx> {
2222
deque: VecDeque<T>,
23-
set: IdxSetBuf<T>,
23+
set: IdxSet<T>,
2424
}
2525

2626
impl<T: Idx> WorkQueue<T> {
@@ -29,7 +29,7 @@ impl<T: Idx> WorkQueue<T> {
2929
pub fn with_all(len: usize) -> Self {
3030
WorkQueue {
3131
deque: (0..len).map(T::new).collect(),
32-
set: IdxSetBuf::new_filled(len),
32+
set: IdxSet::new_filled(len),
3333
}
3434
}
3535

@@ -38,7 +38,7 @@ impl<T: Idx> WorkQueue<T> {
3838
pub fn with_none(len: usize) -> Self {
3939
WorkQueue {
4040
deque: VecDeque::with_capacity(len),
41-
set: IdxSetBuf::new_empty(len),
41+
set: IdxSet::new_empty(len),
4242
}
4343
}
4444

src/librustc_metadata/cstore_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use syntax::edition::Edition;
4343
use syntax::parse::filemap_to_stream;
4444
use syntax::symbol::Symbol;
4545
use syntax_pos::{Span, NO_EXPANSION, FileName};
46-
use rustc_data_structures::indexed_set::IdxSetBuf;
46+
use rustc_data_structures::indexed_set::IdxSet;
4747
use rustc::hir;
4848

4949
macro_rules! provide {
@@ -142,7 +142,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
142142
mir
143143
}
144144
mir_const_qualif => {
145-
(cdata.mir_const_qualif(def_id.index), Lrc::new(IdxSetBuf::new_empty(0)))
145+
(cdata.mir_const_qualif(def_id.index), Lrc::new(IdxSet::new_empty(0)))
146146
}
147147
fn_sig => { cdata.fn_sig(def_id.index, tcx) }
148148
inherent_impls => { Lrc::new(cdata.get_inherent_implementations_for_type(def_id.index)) }

0 commit comments

Comments
 (0)