1
1
use crate :: vec:: { Idx , IndexVec } ;
2
2
use arrayvec:: ArrayVec ;
3
+ use smallvec:: { smallvec, SmallVec } ;
3
4
use std:: fmt;
4
5
use std:: iter;
5
6
use std:: marker:: PhantomData ;
@@ -111,7 +112,7 @@ macro_rules! bit_relations_inherent_impls {
111
112
#[ derive( Eq , PartialEq , Hash , Decodable , Encodable ) ]
112
113
pub struct BitSet < T > {
113
114
domain_size : usize ,
114
- words : Vec < Word > ,
115
+ words : SmallVec < [ Word ; 2 ] > ,
115
116
marker : PhantomData < T > ,
116
117
}
117
118
@@ -127,14 +128,15 @@ impl<T: Idx> BitSet<T> {
127
128
#[ inline]
128
129
pub fn new_empty ( domain_size : usize ) -> BitSet < T > {
129
130
let num_words = num_words ( domain_size) ;
130
- BitSet { domain_size, words : vec ! [ 0 ; num_words] , marker : PhantomData }
131
+ BitSet { domain_size, words : smallvec ! [ 0 ; num_words] , marker : PhantomData }
131
132
}
132
133
133
134
/// Creates a new, filled bitset with a given `domain_size`.
134
135
#[ inline]
135
136
pub fn new_filled ( domain_size : usize ) -> BitSet < T > {
136
137
let num_words = num_words ( domain_size) ;
137
- let mut result = BitSet { domain_size, words : vec ! [ !0 ; num_words] , marker : PhantomData } ;
138
+ let mut result =
139
+ BitSet { domain_size, words : smallvec ! [ !0 ; num_words] , marker : PhantomData } ;
138
140
result. clear_excess_bits ( ) ;
139
141
result
140
142
}
@@ -1571,7 +1573,7 @@ impl<T: Idx> From<BitSet<T>> for GrowableBitSet<T> {
1571
1573
pub struct BitMatrix < R : Idx , C : Idx > {
1572
1574
num_rows : usize ,
1573
1575
num_columns : usize ,
1574
- words : Vec < Word > ,
1576
+ words : SmallVec < [ Word ; 2 ] > ,
1575
1577
marker : PhantomData < ( R , C ) > ,
1576
1578
}
1577
1579
@@ -1584,7 +1586,7 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> {
1584
1586
BitMatrix {
1585
1587
num_rows,
1586
1588
num_columns,
1587
- words : vec ! [ 0 ; num_rows * words_per_row] ,
1589
+ words : smallvec ! [ 0 ; num_rows * words_per_row] ,
1588
1590
marker : PhantomData ,
1589
1591
}
1590
1592
}
0 commit comments