<commit_before>import ljd.ast.nodes as nodes


def insert_table_record(constructor, key, value):
	array = constructor.array.contents
	records = constructor.records.contents

	if isinstance(key, nodes.MULTRES):
		assert len(records) == 0 \
			or isinstance(records[-1], nodes.TableRecord)

		records.append(value)
		return

	while isinstance(key, nodes.Constant)			\
				and key.type == key.T_INTEGER	\
				and key.value >= 0:
		if key.value > len(array):
			break

		record = nodes.ArrayRecord()
		record.value = value

		if key.value == len(array):
			array.append(record)
		else:
			array[key.value] = record

		return

	record = nodes.TableRecord()
	record.key = key
	record.value = value

	if len(records) == 0:
		records.append(record)<commit_msg>helpers: fix tables with indices starting with 1<commit_after>import ljd.ast.nodes as nodes


def insert_table_record(constructor, key, value):
	array = constructor.array.contents
	records = constructor.records.contents

	if isinstance(key, nodes.MULTRES):
		assert len(records) == 0 \
			or isinstance(records[-1], nodes.TableRecord)

		records.append(value)
		return

	while isinstance(key, nodes.Constant)			\
				and key.type == key.T_INTEGER	\
				and key.value >= 0:
		index = key.value
		
		if index == 1 and len(array) == 0:
			record = nodes.ArrayRecord()
			record.value = nodes.Primitive()
			record.value.type = nodes.Primitive.T_NIL
			
			array.append(record)
		
		if (index > len(array)):
			break

		record = nodes.ArrayRecord()
		record.value = value

		if len(array) == 0 or index == len(array):
			array.append(record)
		else:
			array[index] = record

		return

	record = nodes.TableRecord()
	record.key = key
	record.value = value

	if len(records) == 0:
		records.append(record)
{'fraction_non_alphanumeric': 0.12100456621004566, 'fraction_numerical': 0.00684931506849315, 'mean_word_length': 3.5297157622739017, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4695131', 'n_tokens_mistral': 659, 'n_tokens_neox': 565, 'n_words': 140}