<commit_before>pub trait Bits {
    fn bits(self, start: u32, end: u32) -> Self;
    fn bits_from(self, start: u32) -> Self;
    fn bit(self, offset: u32) -> Self;

    #[allow(clippy::wrong_self_convention)]
    fn is_bit_set(self, offset: u32) -> bool;
    fn replace_bits(self, start: u32, end: u32, value: Self) -> Self;
    fn replace_bit(self, offset: u32, value: bool) -> Self;
    fn sign_extend(self, bits: u32) -> Self;
}

impl Bits for u32 {
    #[inline(always)]
    fn bits(self, start: u32, end: u32) -> Self {
        (self >> start) & ((1 << (end - start + 1)) - 1)
    }

    #[inline(always)]
    fn bits_from(self, start: u32) -> Self {
        (self >> start) & 1
    }

    #[inline(always)]
    fn bit(self, offset: u32) -> Self {
        (self >> offset) & 1
    }

    #[inline(always)]
    fn is_bit_set(self, offset: u32) -> bool {
        self.bit(offset) != 0
    }

    #[inline(always)]
    fn replace_bits(self, start: u32, end: u32, value: Self) -> Self {
        (self & !(((1 << (end - start + 1)) - 1) << start))
            | ((value & ((1 << (end - start + 1)) - 1)) << start)
    }

    #[inline(always)]
    fn replace_bit(self, offset: u32, value: bool) -> Self {
        self.replace_bits(offset, offset, value as u32)
    }

    #[inline(always)]
    fn sign_extend(self, bits: u32) -> Self {
        (((self << (32 - bits)) as i32) >> (32 - bits)) as u32
    }
}

impl Bits for u16 {
    #[inline(always)]
    fn bits(self, start: u32, end: u32) -> Self {
        (self >> start) & ((1 << (end - start + 1)) - 1)
    }

    #[inline(always)]
    fn bits_from(self, start: u32) -> Self {
        (self >> start) & 1
    }

    #[inline(always)]
    fn bit(self, offset: u32) -> Self {
        (self >> offset) & 1
    }

    #[inline(always)]
    fn is_bit_set(self, offset: u32) -> bool {
        self.bit(offset) != 0
    }

    #[inline(always)]
    fn replace_bits(self, start: u32, end: u32, value: Self) -> Self {
        (self & !(((1 << (end - start + 1)) - 1) << start))
            | ((value & ((1 << (end - start + 1)) - 1)) << start)
    }

    #[inline(always)]
    fn replace_bit(self, offset: u32, value: bool) -> Self {
        self.replace_bits(offset, offset, value as u16)
    }

    #[inline(always)]
    fn sign_extend(self, bits: u32) -> Self {
        (((self << (16 - bits as u16)) as i16) >> (16 - bits as u16)) as u16
    }
}<commit_msg>Refactor bits and add u64.<commit_after>pub trait Bits {
    const BITS: u32 = 0;
    type Signed;
    type Unsigned;

    fn bits(self, start: u32, end: u32) -> Self;
    fn bits_from(self, start: u32) -> Self;
    fn bit(self, offset: u32) -> Self;

    #[allow(clippy::wrong_self_convention)]
    fn is_bit_set(self, offset: u32) -> bool;
    fn replace_bits(self, start: u32, end: u32, value: Self) -> Self;
    fn replace_bit(self, offset: u32, value: bool) -> Self;
    fn sign_extend(self, bits: u32) -> Self;
}

impl Bits for u32 {
    const BITS: u32 = 32;
    type Signed = i32;
    type Unsigned = Self;

    #[inline(always)]
    fn bits(self, start: u32, end: u32) -> Self {
        (self >> start) & ((1 << (end - start + 1)) - 1)
    }

    #[inline(always)]
    fn bits_from(self, start: u32) -> Self {
        (self >> start) & 1
    }

    #[inline(always)]
    fn bit(self, offset: u32) -> Self {
        (self >> offset) & 1
    }

    #[inline(always)]
    fn is_bit_set(self, offset: u32) -> bool {
        self.bit(offset) != 0
    }

    #[inline(always)]
    fn replace_bits(self, start: u32, end: u32, value: Self) -> Self {
        (self & !(((1 << (end - start + 1)) - 1) << start))
            | ((value & ((1 << (end - start + 1)) - 1)) << start)
    }

    #[inline(always)]
    fn replace_bit(self, offset: u32, value: bool) -> Self {
        self.replace_bits(offset, offset, value as Self)
    }

    #[inline(always)]
    fn sign_extend(self, bits: u32) -> Self {
        (((self << (Self::BITS as Self - bits as Self)) as Self::Signed) >> (32 - bits)) as Self
    }
}

impl Bits for u16 {
    const BITS: u32 = 16;
    type Signed = i32;
    type Unsigned = Self;

    #[inline(always)]
    fn bits(self, start: u32, end: u32) -> Self {
        (self >> start) & ((1 << (end - start + 1)) - 1)
    }

    #[inline(always)]
    fn bits_from(self, start: u32) -> Self {
        (self >> start) & 1
    }

    #[inline(always)]
    fn bit(self, offset: u32) -> Self {
        (self >> offset) & 1
    }

    #[inline(always)]
    fn is_bit_set(self, offset: u32) -> bool {
        self.bit(offset) != 0
    }

    #[inline(always)]
    fn replace_bits(self, start: u32, end: u32, value: Self) -> Self {
        (self & !(((1 << (end - start + 1)) - 1) << start))
            | ((value & ((1 << (end - start + 1)) - 1)) << start)
    }

    #[inline(always)]
    fn replace_bit(self, offset: u32, value: bool) -> Self {
        self.replace_bits(offset, offset, value as Self)
    }

    #[inline(always)]
    fn sign_extend(self, bits: u32) -> Self {
        (((self << (Self::BITS as Self - bits as Self)) as Self::Signed) >> (32 - bits)) as Self
    }
}

impl Bits for u64 {
    const BITS: u32 = 64;
    type Signed = i64;
    type Unsigned = Self;

    #[inline(always)]
    fn bits(self, start: u32, end: u32) -> Self {
        (self >> start) & ((1 << (end - start + 1)) - 1)
    }

    #[inline(always)]
    fn bits_from(self, start: u32) -> Self {
        (self >> start) & 1
    }

    #[inline(always)]
    fn bit(self, offset: u32) -> Self {
        (self >> offset) & 1
    }

    #[inline(always)]
    fn is_bit_set(self, offset: u32) -> bool {
        self.bit(offset) != 0
    }

    #[inline(always)]
    fn replace_bits(self, start: u32, end: u32, value: Self) -> Self {
        (self & !(((1 << (end - start + 1)) - 1) << start))
            | ((value & ((1 << (end - start + 1)) - 1)) << start)
    }

    #[inline(always)]
    fn replace_bit(self, offset: u32, value: bool) -> Self {
        self.replace_bits(offset, offset, value as Self)
    }

    #[inline(always)]
    fn sign_extend(self, bits: u32) -> Self {
        (((self << (Self::BITS as Self - bits as Self)) as Self::Signed) >> (32 - bits)) as Self
    }
}
{'fraction_non_alphanumeric': 0.1832308190352865, 'fraction_numerical': 0.04030430560051797, 'mean_word_length': 2.19824016563147, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 92, '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': '7083241', 'n_tokens_mistral': 2394, 'n_tokens_neox': 2248, 'n_words': 637}