@@ -43,7 +43,7 @@ use crate::Idx;
43
43
/// is not garranteed though as we store the domain size rounded up to the next multiple of
44
44
/// [`WORD_BITS`].
45
45
#[ repr( C ) ]
46
- pub union ThinBitSet < T > {
46
+ pub union DenseBitSet < T > {
47
47
/// The bit set fits in a single [`Word`] stored inline on the stack.
48
48
///
49
49
/// The most significant bit is set to 1 to distinguish this from the other variants. You
@@ -72,7 +72,7 @@ pub union ThinBitSet<T> {
72
72
marker : PhantomData < T > ,
73
73
}
74
74
75
- impl < T > ThinBitSet < T > {
75
+ impl < T > DenseBitSet < T > {
76
76
/// The maximum domain size that could be stored inlined on the stack.
77
77
pub const INLINE_CAPACITY : usize = WORD_BITS - 1 ;
78
78
@@ -463,7 +463,7 @@ impl<T> ThinBitSet<T> {
463
463
super :: bit_relations_inherent_impls! { }
464
464
}
465
465
466
- impl < T > BitRelations < ThinBitSet < T > > for ThinBitSet < T > {
466
+ impl < T > BitRelations < DenseBitSet < T > > for DenseBitSet < T > {
467
467
#[ inline( always) ]
468
468
fn union ( & mut self , other : & Self ) -> bool {
469
469
if self . is_empty_unallocated ( ) {
@@ -505,7 +505,7 @@ impl<T> BitRelations<ThinBitSet<T>> for ThinBitSet<T> {
505
505
}
506
506
}
507
507
508
- impl < T : Idx > ThinBitSet < T > {
508
+ impl < T : Idx > DenseBitSet < T > {
509
509
/// Checks if the bit set contains `elem`.
510
510
#[ inline( always) ]
511
511
pub fn contains ( & self , elem : T ) -> bool {
@@ -709,7 +709,7 @@ impl<T: Idx> ThinBitSet<T> {
709
709
}
710
710
}
711
711
712
- impl < T : Idx > BitRelations < ChunkedBitSet < T > > for ThinBitSet < T > {
712
+ impl < T : Idx > BitRelations < ChunkedBitSet < T > > for DenseBitSet < T > {
713
713
fn union ( & mut self , other : & ChunkedBitSet < T > ) -> bool {
714
714
other. iter ( ) . fold ( false , |changed, elem| self . insert ( elem) || changed)
715
715
}
@@ -778,7 +778,7 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ThinBitSet<T> {
778
778
}
779
779
}
780
780
781
- impl < S : Encoder , T > Encodable < S > for ThinBitSet < T > {
781
+ impl < S : Encoder , T > Encodable < S > for DenseBitSet < T > {
782
782
#[ inline( never) ] // FIXME: For profiling purposes
783
783
fn encode ( & self , s : & mut S ) {
784
784
/* FIXME: This is new incompatable encoding
@@ -821,7 +821,7 @@ impl<S: Encoder, T> Encodable<S> for ThinBitSet<T> {
821
821
}
822
822
}
823
823
824
- impl < D : Decoder , T > Decodable < D > for ThinBitSet < T > {
824
+ impl < D : Decoder , T > Decodable < D > for DenseBitSet < T > {
825
825
#[ inline( never) ] // FIXME: For profiling purposes
826
826
fn decode ( d : & mut D ) -> Self {
827
827
/* FIXME: This is new incompatable decoding.
@@ -833,7 +833,7 @@ impl<D: Decoder, T> Decodable<D> for ThinBitSet<T> {
833
833
let n_words = word as usize;
834
834
assert!(
835
835
n_words > 0,
836
- "ThinBitSet decoder error: At least one word must be stored with the `on_heap` variant."
836
+ "DenseBitSet decoder error: At least one word must be stored with the `on_heap` variant."
837
837
);
838
838
let mut on_heap = BitSetOnHeap::new_empty(n_words);
839
839
@@ -846,7 +846,7 @@ impl<D: Decoder, T> Decodable<D> for ThinBitSet<T> {
846
846
*word = Word::decode(d);
847
847
}
848
848
849
- ThinBitSet { on_heap: ManuallyDrop::new(on_heap) }
849
+ DenseBitSet { on_heap: ManuallyDrop::new(on_heap) }
850
850
} else {
851
851
// Both the `inline` and `empty_unallocated` variants are encoded by one `Word`. We can
852
852
// just assume the `inline` variant because the `empty_unallocated` variant is smaller
@@ -865,7 +865,7 @@ impl<D: Decoder, T> Decodable<D> for ThinBitSet<T> {
865
865
}
866
866
}
867
867
868
- impl < T > Clone for ThinBitSet < T > {
868
+ impl < T > Clone for DenseBitSet < T > {
869
869
#[ inline( always) ]
870
870
fn clone ( & self ) -> Self {
871
871
if self . is_inline ( ) {
@@ -882,7 +882,7 @@ impl<T> Clone for ThinBitSet<T> {
882
882
}
883
883
}
884
884
885
- impl < T > Drop for ThinBitSet < T > {
885
+ impl < T > Drop for DenseBitSet < T > {
886
886
#[ inline( always) ]
887
887
fn drop ( & mut self ) {
888
888
// Deallocate if `self` is not inlined.
@@ -1108,13 +1108,13 @@ impl<'a, T: Idx> Iterator for BitIter<'a, T> {
1108
1108
1109
1109
impl < ' a , T : Idx > FusedIterator for BitIter < ' a , T > { }
1110
1110
1111
- impl < T : Idx > fmt:: Debug for ThinBitSet < T > {
1111
+ impl < T : Idx > fmt:: Debug for DenseBitSet < T > {
1112
1112
fn fmt ( & self , w : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1113
1113
w. debug_list ( ) . entries ( self . iter ( ) ) . finish ( )
1114
1114
}
1115
1115
}
1116
1116
1117
- impl < T > PartialEq for ThinBitSet < T > {
1117
+ impl < T > PartialEq for DenseBitSet < T > {
1118
1118
#[ inline]
1119
1119
fn eq ( & self , other : & Self ) -> bool {
1120
1120
if self . is_inline ( ) {
@@ -1153,9 +1153,9 @@ impl<T> PartialEq for ThinBitSet<T> {
1153
1153
}
1154
1154
}
1155
1155
1156
- impl < T > Eq for ThinBitSet < T > { }
1156
+ impl < T > Eq for DenseBitSet < T > { }
1157
1157
1158
- impl < T > Hash for ThinBitSet < T > {
1158
+ impl < T > Hash for DenseBitSet < T > {
1159
1159
#[ inline]
1160
1160
fn hash < H : Hasher > ( & self , hasher : & mut H ) {
1161
1161
if self . is_inline ( ) {
@@ -1186,7 +1186,7 @@ impl<T> Hash for ThinBitSet<T> {
1186
1186
/// to or greater than the domain size.
1187
1187
#[ derive( Clone , PartialEq ) ]
1188
1188
pub struct GrowableBitSet < T > {
1189
- bit_set : ThinBitSet < T > ,
1189
+ bit_set : DenseBitSet < T > ,
1190
1190
}
1191
1191
1192
1192
impl < T > Default for GrowableBitSet < T > {
@@ -1204,28 +1204,28 @@ impl<T> GrowableBitSet<T> {
1204
1204
1205
1205
if self . bit_set . is_inline ( ) {
1206
1206
// The set must change from being inlined to allocate on the heap.
1207
- debug_assert ! ( min_domain_size > ThinBitSet :: <T >:: INLINE_CAPACITY ) ;
1207
+ debug_assert ! ( min_domain_size > DenseBitSet :: <T >:: INLINE_CAPACITY ) ;
1208
1208
1209
- let mut new_bit_set = ThinBitSet :: new_empty ( min_domain_size) ;
1209
+ let mut new_bit_set = DenseBitSet :: new_empty ( min_domain_size) ;
1210
1210
if !self . bit_set . is_empty ( ) {
1211
1211
// SAFETY: We know that `self.is_inline()` is true.
1212
- let word = unsafe { self . bit_set . inline } ^ ThinBitSet :: < T > :: IS_INLINE_TAG_BIT ;
1212
+ let word = unsafe { self . bit_set . inline } ^ DenseBitSet :: < T > :: IS_INLINE_TAG_BIT ;
1213
1213
new_bit_set. on_heap_get_or_alloc ( ) . as_mut_slice ( ) [ 0 ] = word;
1214
1214
}
1215
1215
self . bit_set = new_bit_set;
1216
1216
} else if self . bit_set . is_empty_unallocated ( ) {
1217
- self . bit_set = ThinBitSet :: new_empty ( min_domain_size) ;
1217
+ self . bit_set = DenseBitSet :: new_empty ( min_domain_size) ;
1218
1218
} else {
1219
1219
self . bit_set . on_heap_mut ( ) . unwrap ( ) . ensure_capacity ( min_domain_size) ;
1220
1220
}
1221
1221
}
1222
1222
1223
1223
pub fn new_empty ( ) -> GrowableBitSet < T > {
1224
- GrowableBitSet { bit_set : ThinBitSet :: new_empty ( 0 ) }
1224
+ GrowableBitSet { bit_set : DenseBitSet :: new_empty ( 0 ) }
1225
1225
}
1226
1226
1227
1227
pub fn with_capacity ( capacity : usize ) -> GrowableBitSet < T > {
1228
- GrowableBitSet { bit_set : ThinBitSet :: new_empty ( capacity) }
1228
+ GrowableBitSet { bit_set : DenseBitSet :: new_empty ( capacity) }
1229
1229
}
1230
1230
1231
1231
/// Insert the element with index `idx`. Returns `true` if the set has changed.
@@ -1271,13 +1271,13 @@ impl<T: Idx> GrowableBitSet<T> {
1271
1271
}
1272
1272
}
1273
1273
1274
- impl < T > From < ThinBitSet < T > > for GrowableBitSet < T > {
1275
- fn from ( bit_set : ThinBitSet < T > ) -> Self {
1274
+ impl < T > From < DenseBitSet < T > > for GrowableBitSet < T > {
1275
+ fn from ( bit_set : DenseBitSet < T > ) -> Self {
1276
1276
Self { bit_set }
1277
1277
}
1278
1278
}
1279
1279
1280
- impl < T > From < GrowableBitSet < T > > for ThinBitSet < T > {
1280
+ impl < T > From < GrowableBitSet < T > > for DenseBitSet < T > {
1281
1281
fn from ( bit_set : GrowableBitSet < T > ) -> Self {
1282
1282
bit_set. bit_set
1283
1283
}
@@ -1476,9 +1476,9 @@ mod tests {
1476
1476
fn test_with_domain_size ( domain_size : usize ) {
1477
1477
const TEST_ITERATIONS : u32 = 512 ;
1478
1478
1479
- let mut set_1 = ThinBitSet :: < usize > :: new_empty ( domain_size) ;
1479
+ let mut set_1 = DenseBitSet :: < usize > :: new_empty ( domain_size) ;
1480
1480
let mut set_1_reference = IndexVec :: < usize , bool > :: from_elem_n ( false , domain_size) ;
1481
- let mut set_2 = ThinBitSet :: < usize > :: new_empty ( domain_size) ;
1481
+ let mut set_2 = DenseBitSet :: < usize > :: new_empty ( domain_size) ;
1482
1482
let mut set_2_reference = IndexVec :: < usize , bool > :: from_elem_n ( false , domain_size) ;
1483
1483
1484
1484
let hasher = BuildHasherDefault :: < DefaultHasher > :: new ( ) ;
@@ -1613,12 +1613,12 @@ mod tests {
1613
1613
97 ..100 => {
1614
1614
// Test new_filled().
1615
1615
if rng. next_bool ( ) {
1616
- set_1 = ThinBitSet :: new_filled ( domain_size) ;
1616
+ set_1 = DenseBitSet :: new_filled ( domain_size) ;
1617
1617
for x in set_1_reference. iter_mut ( ) {
1618
1618
* x = true ;
1619
1619
}
1620
1620
} else {
1621
- set_2 = ThinBitSet :: new_filled ( domain_size) ;
1621
+ set_2 = DenseBitSet :: new_filled ( domain_size) ;
1622
1622
for x in set_2_reference. iter_mut ( ) {
1623
1623
* x = true ;
1624
1624
}
@@ -1687,7 +1687,7 @@ mod tests {
1687
1687
set_1. encode ( & mut encoder) ;
1688
1688
1689
1689
let mut decoder = DecoderLittleEndian :: new ( & encoder. bytes ) ;
1690
- let decoded = ThinBitSet :: < usize > :: decode ( & mut decoder) ;
1690
+ let decoded = DenseBitSet :: < usize > :: decode ( & mut decoder) ;
1691
1691
assert_eq ! (
1692
1692
decoder. position( ) ,
1693
1693
encoder. bytes. len( ) ,
@@ -1704,7 +1704,7 @@ mod tests {
1704
1704
fn test_relations_with_chunked_set ( domain_size : usize ) {
1705
1705
const TEST_ITERATIONS : u32 = 64 ;
1706
1706
1707
- let mut dense_set = ThinBitSet :: < usize > :: new_empty ( domain_size) ;
1707
+ let mut dense_set = DenseBitSet :: < usize > :: new_empty ( domain_size) ;
1708
1708
let mut chunked_set = ChunkedBitSet :: new_empty ( domain_size) ;
1709
1709
1710
1710
let mut rng = Rng :: new ( 42 ) ;
@@ -1786,11 +1786,11 @@ mod tests {
1786
1786
}
1787
1787
1788
1788
#[ test]
1789
- fn test_thin_bit_set ( ) {
1789
+ fn test_dense_bit_set ( ) {
1790
1790
assert_eq ! (
1791
- size_of:: <ThinBitSet <usize >>( ) ,
1791
+ size_of:: <DenseBitSet <usize >>( ) ,
1792
1792
size_of:: <Word >( ) ,
1793
- "ThinBitSet should have the same size as a Word"
1793
+ "DenseBitSet should have the same size as a Word"
1794
1794
) ;
1795
1795
1796
1796
test_with_domain_size ( 0 ) ;
@@ -1825,8 +1825,8 @@ mod tests {
1825
1825
for _ in 0 ..TEST_ITERATIONS {
1826
1826
match rng. next ( ) % 100 {
1827
1827
0 ..30 => {
1828
- // Insert an element in the `0..=(ThinBitSet ::INLINE_CAPACITY + 2)` range.
1829
- let elem = rng. next ( ) % ( ThinBitSet :: < usize > :: INLINE_CAPACITY + 3 ) ;
1828
+ // Insert an element in the `0..=(DenseBitSet ::INLINE_CAPACITY + 2)` range.
1829
+ let elem = rng. next ( ) % ( DenseBitSet :: < usize > :: INLINE_CAPACITY + 3 ) ;
1830
1830
set. insert ( elem) ;
1831
1831
reference_set. insert ( elem) ;
1832
1832
}
0 commit comments