<commit_before># -*- coding: utf-8 -*-

class BitMask(object):
	"""
	Base BitMask class
	"""
	
	def __init__(self, value, flags={}):
		self._values = dict(zip(flags.keys(), flags.values()))
		if isinstance(value, dict):
			value = sum(self._values.keys())
		elif not isinstance(value, int):
			from ..structures import StructureError
			raise StructureError("BitMask value must be an int or a dict (got %r instead)" % (type(value)))
		self._bitmask = value
		self._flags = flags
	
	def __repr__(self):
		return '<%s: 0x%X>' % (self.__class__.__name__, self._bitmask)
	
	def __getitem__(self, key):
		assert isinstance(key, int) and key >= 0, "key must be a positive integer"
		return self._bitmask & key == key
	
	def __setitem__(self, key, value):
		assert isinstance(key, int) and key >= 0, "key must be a positive integer"
		bit = 1 << key-1
	
	def __int__(self):
		return self._bitmask
	
	def _get_values(self):
		ret = []
		for k, v in self._flags.items():
			if self[k]:
				ret.append(v)
		return ret


class BitFlags(BitMask):
	"""
	v = BitFlags(5, {0x1: "race", 0x2: "sex", 0x4: "alive"}) #  v.race is True, v.sex is False, v.alive is True
	v = BitFlags(5) # v[0] is True, v[1] is False, v[2] is True
	"""
	<commit_msg>structures/bitflags: Add and/xor/or to BitMask class<commit_after># -*- coding: utf-8 -*-

class BitMask(object):
	"""
	Base BitMask class
	"""
	
	def __init__(self, value, flags={}):
		self._values = dict(zip(flags.keys(), flags.values()))
		if isinstance(value, dict):
			value = sum(self._values.keys())
		elif not isinstance(value, int):
			from ..structures import StructureError
			raise StructureError("BitMask value must be an int or a dict (got %r instead)" % (type(value)))
		self._bitmask = value
		self._flags = flags
	
	def __repr__(self):
		return '<%s: 0x%X>' % (self.__class__.__name__, self._bitmask)
	
	def __getitem__(self, key):
		assert isinstance(key, int) and key >= 0, "key must be a positive integer"
		return self._bitmask & key == key
	
	def __setitem__(self, key, value):
		assert isinstance(key, int) and key >= 0, "key must be a positive integer"
		bit = 1 << key-1
	
	def __int__(self):
		return self._bitmask
	
	def __and__(self, other):
		return self._bitmask.__and__(other)
	
	def __xor__(self, other):
		return self._bitmask.__xor__(other)
	
	def __or__(self, other):
		return self._bitmask.__or__(other)
	
	def _get_values(self):
		ret = []
		for k, v in self._flags.items():
			if self[k]:
				ret.append(v)
		return ret


class BitFlags(BitMask):
	"""
	v = BitFlags(5, {0x1: "race", 0x2: "sex", 0x4: "alive"}) #  v.race is True, v.sex is False, v.alive is True
	v = BitFlags(5) # v[0] is True, v[1] is False, v[2] is True
	"""
	
{'fraction_non_alphanumeric': 0.15219005196733482, 'fraction_numerical': 0.012620638455827766, 'mean_word_length': 3.736379613356766, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2094924', 'n_tokens_mistral': 1062, 'n_tokens_neox': 947, 'n_words': 296}