<commit_before>use alloc::raw_vec::RawVec;
use num::{self, PrimInt, Zero, cast, zero};
use std::cmp;
use std::ops::*;
use std::fmt::{self, Debug, Display};
use std::mem;
use std::ptr;
use std::marker::PhantomData;

pub trait Nbits {
    fn bits() -> usize;

    #[inline]
    fn mask() -> usize {
        (0..).take(Self::bits()).fold(0, |mask, _x| mask << 1 | 1)
    }
}

pub struct NbitsVec<T: Nbits, B = usize> {
    buf: RawVec<B>,
    len: usize,
    _marker: PhantomData<T>,
}

impl<
T:  Nbits,
B:  PrimInt,
    // :  Default
> Default for NbitsVec<T, B> {
    fn default() -> Self {
        NbitsVec {
            buf: RawVec::new(),
            len: 0,
            _marker: PhantomData,
        }
    }
}

impl<T: Nbits, B: PrimInt + Display + fmt::LowerHex> Debug for NbitsVec<T, B> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        try!(write!(f,
                    "NbitsVec<{}> {{ len: {}, buf: RawVec {{ cap: {}, [",
                    T::bits(),
                    self.len,
                    self.buf.cap()));
        let ptr = self.buf.ptr();
        for i in 0..self.buf.cap() {
            unsafe {
                try!(write!(f, "{:#x}, ", ptr::read(ptr.offset(cast(i).expect("")))));
            }
        }
        write!(f, "] }}")
    }
}

impl<
T:  Nbits,
B:  PrimInt
> NbitsVec<T, B> {
    /// Constructs a new, empty NbitsVec<T>
    ///
    /// The vector will not allocate until elements are pushed onto it.
    ///
    /// # Examples
    /// ```<commit_msg>Removed used `cast` `zero` uses.<commit_after>use alloc::raw_vec::RawVec;
use num::{self, PrimInt};
use std::cmp;
use std::ops::*;
use std::fmt::{self, Debug, Display};
use std::mem;
use std::ptr;
use std::marker::PhantomData;

pub trait Nbits {
    fn bits() -> usize;

    #[inline]
    fn mask() -> usize {
        (0..).take(Self::bits()).fold(0, |mask, _x| mask << 1 | 1)
    }
}

pub struct NbitsVec<T: Nbits, B = usize> {
    buf: RawVec<B>,
    len: usize,
    _marker: PhantomData<T>,
}

impl<
T:  Nbits,
B:  PrimInt,
> Default for NbitsVec<T, B> {
    fn default() -> Self {
        NbitsVec {
            buf: RawVec::new(),
            len: 0,
            _marker: PhantomData,
        }
    }
}

impl<T: Nbits, B: PrimInt + fmt::LowerHex> Debug for NbitsVec<T, B> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        try!(write!(f,
                    "NbitsVec<{}> {{ len: {}, buf: RawVec {{ cap: {}, [",
                    T::bits(),
                    self.len,
                    self.buf.cap()));
        let ptr = self.buf.ptr();
        for i in 0..self.buf.cap() {
            unsafe {
                try!(write!(f, "{:#x}, ", ptr::read(ptr.offset(i as isize))));
            }
        }
        write!(f, "] }}")
    }
}

impl<
T:  Nbits,
B:  PrimInt
> NbitsVec<T, B> {
    /// Constructs a new, empty NbitsVec<T>
    ///
    /// The vector will not allocate until elements are pushed onto it.
    ///
    /// # Examples
    /// ```
{'fraction_non_alphanumeric': 0.1914180355346966, 'fraction_numerical': 0.004022795843110962, 'mean_word_length': 1.8692307692307693, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3539793', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1059, 'n_words': 263}