<commit_before>#
# file: estd.py
#
# author: Copyright (C) 2017 <NAME> http://www.distortec.com http://www.freddiechopin.info
#
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
# distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

import gdb
import gdb.printing

########################################################################################################################
# GenericIntrusiveListIterator class
########################################################################################################################

class GenericIntrusiveListIterator:
	'Generic iterator for intrusive list'

	def __init__(self, begin, end, nodeValidator, nodePointer, u):
		self.end = end
		self.nodeValidator = nodeValidator
		self.nodePointer = nodePointer
		self.u = u
		self.index = 0
		self.iterator = begin

	def __iter__(self):
		return self

	def __next__(self):
		if self.iterator == self.end:
			raise StopIteration
		if self.nodeValidator(self.iterator.dereference()) == False:
			raise StopIteration
		index = self.index
		sizeType = gdb.lookup_type('size_t')
		offset = gdb.parse_and_eval('static_cast<%s>(0)->*%s' % (self.u.pointer(), self.nodePointer)).address.cast(sizeType)
		pointer = (self.iterator.cast(sizeType) - offset).cast(self.u.pointer())
		element = pointer.dereference()
		self.index += 1
		self.iterator = self.iterator['nextNode_']
		return ('[%d]' % index, element)

########################################################################################################################
# ContiguousRange class<commit_msg>Calculate node's offset in GenericIntrusiveListIterator constructor<commit_after>#
# file: estd.py
#
# author: Copyright (C) 2017 <NAME> http://www.distortec.com http://www.freddiechopin.info
#
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
# distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

import gdb
import gdb.printing

########################################################################################################################
# GenericIntrusiveListIterator class
########################################################################################################################

class GenericIntrusiveListIterator:
	'Generic iterator for intrusive list'

	def __init__(self, begin, end, nodeValidator, nodePointer, u):
		self.end = end
		self.nodeValidator = nodeValidator
		self.u = u
		sizeType = gdb.lookup_type('size_t')
		self.offset = gdb.parse_and_eval('static_cast<%s>(0)->*%s' % (u.pointer(), nodePointer)).address.cast(sizeType)
		self.index = 0
		self.iterator = begin

	def __iter__(self):
		return self

	def __next__(self):
		if self.iterator == self.end:
			raise StopIteration
		if self.nodeValidator(self.iterator.dereference()) == False:
			raise StopIteration
		index = self.index
		sizeType = gdb.lookup_type('size_t')
		pointer = (self.iterator.cast(sizeType) - self.offset).cast(self.u.pointer())
		element = pointer.dereference()
		self.index += 1
		self.iterator = self.iterator['nextNode_']
		return ('[%d]' % index, element)

########################################################################################################################
# ContiguousRange class
{'fraction_non_alphanumeric': 0.3103957471943296, 'fraction_numerical': 0.006497341996455995, 'mean_word_length': 5.801204819277109, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2861630', 'n_tokens_mistral': 999, 'n_tokens_neox': 895, 'n_words': 234}