Make rustc_index::bit_set
available on stable
This commit is contained in:
parent
e646c9f723
commit
f30c5956f5
@ -9,6 +9,7 @@ use std::slice;
|
|||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
use rustc_macros::{Decodable, Encodable};
|
use rustc_macros::{Decodable, Encodable};
|
||||||
|
|
||||||
use crate::{Idx, IndexVec};
|
use crate::{Idx, IndexVec};
|
||||||
@ -111,7 +112,8 @@ macro_rules! bit_relations_inherent_impls {
|
|||||||
/// to or greater than the domain size. All operations that involve two bitsets
|
/// to or greater than the domain size. All operations that involve two bitsets
|
||||||
/// will panic if the bitsets have differing domain sizes.
|
/// will panic if the bitsets have differing domain sizes.
|
||||||
///
|
///
|
||||||
#[derive(Eq, PartialEq, Hash, Decodable, Encodable)]
|
#[cfg_attr(feature = "nightly", derive(Decodable, Encodable))]
|
||||||
|
#[derive(Eq, PartialEq, Hash)]
|
||||||
pub struct BitSet<T> {
|
pub struct BitSet<T> {
|
||||||
domain_size: usize,
|
domain_size: usize,
|
||||||
words: SmallVec<[Word; 2]>,
|
words: SmallVec<[Word; 2]>,
|
||||||
@ -491,10 +493,21 @@ impl<T: Idx> ChunkedBitSet<T> {
|
|||||||
match *chunk {
|
match *chunk {
|
||||||
Zeros(chunk_domain_size) => {
|
Zeros(chunk_domain_size) => {
|
||||||
if chunk_domain_size > 1 {
|
if chunk_domain_size > 1 {
|
||||||
// We take some effort to avoid copying the words.
|
#[cfg(feature = "nightly")]
|
||||||
let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed();
|
let mut words = {
|
||||||
// SAFETY: `words` can safely be all zeroes.
|
// We take some effort to avoid copying the words.
|
||||||
let mut words = unsafe { words.assume_init() };
|
let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed();
|
||||||
|
// SAFETY: `words` can safely be all zeroes.
|
||||||
|
unsafe { words.assume_init() }
|
||||||
|
};
|
||||||
|
#[cfg(not(feature = "nightly"))]
|
||||||
|
let mut words = {
|
||||||
|
let words = mem::MaybeUninit::<[Word; CHUNK_WORDS]>::zeroed();
|
||||||
|
// SAFETY: `words` can safely be all zeroes.
|
||||||
|
let words = unsafe { words.assume_init() };
|
||||||
|
// Unfortunate possibly-large copy
|
||||||
|
Rc::new(words)
|
||||||
|
};
|
||||||
let words_ref = Rc::get_mut(&mut words).unwrap();
|
let words_ref = Rc::get_mut(&mut words).unwrap();
|
||||||
|
|
||||||
let (word_index, mask) = chunk_word_index_and_mask(elem);
|
let (word_index, mask) = chunk_word_index_and_mask(elem);
|
||||||
@ -545,10 +558,21 @@ impl<T: Idx> ChunkedBitSet<T> {
|
|||||||
Zeros(_) => false,
|
Zeros(_) => false,
|
||||||
Ones(chunk_domain_size) => {
|
Ones(chunk_domain_size) => {
|
||||||
if chunk_domain_size > 1 {
|
if chunk_domain_size > 1 {
|
||||||
// We take some effort to avoid copying the words.
|
#[cfg(feature = "nightly")]
|
||||||
let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed();
|
let mut words = {
|
||||||
// SAFETY: `words` can safely be all zeroes.
|
// We take some effort to avoid copying the words.
|
||||||
let mut words = unsafe { words.assume_init() };
|
let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed();
|
||||||
|
// SAFETY: `words` can safely be all zeroes.
|
||||||
|
unsafe { words.assume_init() }
|
||||||
|
};
|
||||||
|
#[cfg(not(feature = "nightly"))]
|
||||||
|
let mut words = {
|
||||||
|
let words = mem::MaybeUninit::<[Word; CHUNK_WORDS]>::zeroed();
|
||||||
|
// SAFETY: `words` can safely be all zeroes.
|
||||||
|
let words = unsafe { words.assume_init() };
|
||||||
|
// Unfortunate possibly-large copy
|
||||||
|
Rc::new(words)
|
||||||
|
};
|
||||||
let words_ref = Rc::get_mut(&mut words).unwrap();
|
let words_ref = Rc::get_mut(&mut words).unwrap();
|
||||||
|
|
||||||
// Set only the bits in use.
|
// Set only the bits in use.
|
||||||
@ -1564,7 +1588,8 @@ impl<T: Idx> From<BitSet<T>> for GrowableBitSet<T> {
|
|||||||
///
|
///
|
||||||
/// All operations that involve a row and/or column index will panic if the
|
/// All operations that involve a row and/or column index will panic if the
|
||||||
/// index exceeds the relevant bound.
|
/// index exceeds the relevant bound.
|
||||||
#[derive(Clone, Eq, PartialEq, Hash, Decodable, Encodable)]
|
#[cfg_attr(feature = "nightly", derive(Decodable, Encodable))]
|
||||||
|
#[derive(Clone, Eq, PartialEq, Hash)]
|
||||||
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,
|
||||||
@ -1993,7 +2018,8 @@ impl std::fmt::Debug for FiniteBitSet<u32> {
|
|||||||
|
|
||||||
/// A fixed-sized bitset type represented by an integer type. Indices outwith than the range
|
/// A fixed-sized bitset type represented by an integer type. Indices outwith than the range
|
||||||
/// representable by `T` are considered set.
|
/// representable by `T` are considered set.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Decodable, Encodable)]
|
#[cfg_attr(feature = "nightly", derive(Decodable, Encodable))]
|
||||||
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||||
pub struct FiniteBitSet<T: FiniteBitSetTy>(pub T);
|
pub struct FiniteBitSet<T: FiniteBitSetTy>(pub T);
|
||||||
|
|
||||||
impl<T: FiniteBitSetTy> FiniteBitSet<T> {
|
impl<T: FiniteBitSetTy> FiniteBitSet<T> {
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
)]
|
)]
|
||||||
#![cfg_attr(feature = "nightly", allow(internal_features))]
|
#![cfg_attr(feature = "nightly", allow(internal_features))]
|
||||||
|
|
||||||
#[cfg(feature = "nightly")]
|
|
||||||
pub mod bit_set;
|
pub mod bit_set;
|
||||||
#[cfg(feature = "nightly")]
|
#[cfg(feature = "nightly")]
|
||||||
pub mod interval;
|
pub mod interval;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user