Use SmallVec
in bitsets
This doesn't increase their size and means that we don't have to heap allocate for small sets.
This commit is contained in:
parent
66676820eb
commit
29c11327c7
1 changed files with 7 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
use crate::vec::{Idx, IndexVec};
|
use crate::vec::{Idx, IndexVec};
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
|
use smallvec::{smallvec, SmallVec};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
@ -111,7 +112,7 @@ macro_rules! bit_relations_inherent_impls {
|
||||||
#[derive(Eq, PartialEq, Hash, Decodable, Encodable)]
|
#[derive(Eq, PartialEq, Hash, Decodable, Encodable)]
|
||||||
pub struct BitSet<T> {
|
pub struct BitSet<T> {
|
||||||
domain_size: usize,
|
domain_size: usize,
|
||||||
words: Vec<Word>,
|
words: SmallVec<[Word; 2]>,
|
||||||
marker: PhantomData<T>,
|
marker: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,14 +128,15 @@ impl<T: Idx> BitSet<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_empty(domain_size: usize) -> BitSet<T> {
|
pub fn new_empty(domain_size: usize) -> BitSet<T> {
|
||||||
let num_words = num_words(domain_size);
|
let num_words = num_words(domain_size);
|
||||||
BitSet { domain_size, words: vec![0; num_words], marker: PhantomData }
|
BitSet { domain_size, words: smallvec![0; num_words], marker: PhantomData }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new, filled bitset with a given `domain_size`.
|
/// Creates a new, filled bitset with a given `domain_size`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_filled(domain_size: usize) -> BitSet<T> {
|
pub fn new_filled(domain_size: usize) -> BitSet<T> {
|
||||||
let num_words = num_words(domain_size);
|
let num_words = num_words(domain_size);
|
||||||
let mut result = BitSet { domain_size, words: vec![!0; num_words], marker: PhantomData };
|
let mut result =
|
||||||
|
BitSet { domain_size, words: smallvec![!0; num_words], marker: PhantomData };
|
||||||
result.clear_excess_bits();
|
result.clear_excess_bits();
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -1571,7 +1573,7 @@ impl<T: Idx> From<BitSet<T>> for GrowableBitSet<T> {
|
||||||
pub struct BitMatrix<R: Idx, C: Idx> {
|
pub struct BitMatrix<R: Idx, C: Idx> {
|
||||||
num_rows: usize,
|
num_rows: usize,
|
||||||
num_columns: usize,
|
num_columns: usize,
|
||||||
words: Vec<Word>,
|
words: SmallVec<[Word; 2]>,
|
||||||
marker: PhantomData<(R, C)>,
|
marker: PhantomData<(R, C)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1584,7 +1586,7 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> {
|
||||||
BitMatrix {
|
BitMatrix {
|
||||||
num_rows,
|
num_rows,
|
||||||
num_columns,
|
num_columns,
|
||||||
words: vec![0; num_rows * words_per_row],
|
words: smallvec![0; num_rows * words_per_row],
|
||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue