<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
"""A simple bitmask class."""

from bitarray import bitarray

try:
	bin
except NameError:
	_bin = lambda n: n>0 and (_bin(n>>1).lstrip('0')+str(n&1)) or "0"
	bin = lambda n: "0b%s" % _bin(n)


class BitMask(object):
	def __init__(self, value):
		value = value >= 0 and value or 0
		value = bin(value)[2:]
		self.array = bitarray(32)
		self.array.setall(False)
		self.array[-len(value):] = bitarray(value)
		self.array = self.array[::-1]
	
	def __repr__(self):
		return self.array.__repr__()<commit_msg>bitmask: Add __int__ and __setitem__ methods<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
"""A simple bitmask class."""

from bitarray import bitarray

try:
	bin
except NameError:
	_bin = lambda n: n>0 and (_bin(n>>1).lstrip('0')+str(n&1)) or "0"
	bin = lambda n: "0b%s" % _bin(n)


class BitMask(object):
	def __init__(self, value):
		value = value >= 0 and value or 0
		value = bin(value)[2:]
		self.array = bitarray(32)
		self.array.setall(False)
		self.array[-len(value):] = bitarray(value)
		self.array = self.array[::-1]
	
	def __int__(self):
		return int(self.array.to01(), 2)
	
	def __repr__(self):
		return self.array.__repr__()
	
	def __setitem__(self, key, value):
		self.array[key] = bool(value)
{'fraction_non_alphanumeric': 0.1786833855799373, 'fraction_numerical': 0.022727272727272728, 'mean_word_length': 4.128514056224899, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4778144', 'n_tokens_mistral': 535, 'n_tokens_neox': 496, 'n_words': 121}