11use crate :: vec:: { Idx , IndexVec } ;
22use arrayvec:: ArrayVec ;
3+ use smallvec:: { smallvec, SmallVec } ;
34use std:: fmt;
45use std:: iter;
56use std:: marker:: PhantomData ;
@@ -111,7 +112,7 @@ macro_rules! bit_relations_inherent_impls {
111112#[ derive( Eq , PartialEq , Hash , Decodable , Encodable ) ]
112113pub struct BitSet < T > {
113114 domain_size : usize ,
114- words : Vec < Word > ,
115+ words : SmallVec < [ Word ; 2 ] > ,
115116 marker : PhantomData < T > ,
116117}
117118
@@ -127,14 +128,15 @@ impl<T: Idx> BitSet<T> {
127128 #[ inline]
128129 pub fn new_empty ( domain_size : usize ) -> BitSet < T > {
129130 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 }
131132 }
132133
133134 /// Creates a new, filled bitset with a given `domain_size`.
134135 #[ inline]
135136 pub fn new_filled ( domain_size : usize ) -> BitSet < T > {
136137 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 } ;
138140 result. clear_excess_bits ( ) ;
139141 result
140142 }
@@ -1571,7 +1573,7 @@ impl<T: Idx> From<BitSet<T>> for GrowableBitSet<T> {
15711573pub struct BitMatrix < R : Idx , C : Idx > {
15721574 num_rows : usize ,
15731575 num_columns : usize ,
1574- words : Vec < Word > ,
1576+ words : SmallVec < [ Word ; 2 ] > ,
15751577 marker : PhantomData < ( R , C ) > ,
15761578}
15771579
@@ -1584,7 +1586,7 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> {
15841586 BitMatrix {
15851587 num_rows,
15861588 num_columns,
1587- words : vec ! [ 0 ; num_rows * words_per_row] ,
1589+ words : smallvec ! [ 0 ; num_rows * words_per_row] ,
15881590 marker : PhantomData ,
15891591 }
15901592 }
0 commit comments