<commit_before># This file is part of NIT ( http://www.nitlanguage.org ).
#
# Copyright 2008 <NAME> <<EMAIL>>
#
# This file is free software, which comes along with NIT.  This software is
# distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without  even  the implied warranty of  MERCHANTABILITY or  FITNESS FOR A
# PARTICULAR PURPOSE.  You can modify it is you want,  provided this header
# is kept unaltered, and a notification of the changes is added.
# You  are  allowed  to  redistribute it and sell it, alone or is a part of
# another product.

class DummyArray
	super Set[Int]
	private var capacity: Int
	redef var length: Int
	private var keys: NativeArray[Int]
	private var values: NativeArray[Int]

	redef fun add(value: Int)
	do
		assert full: _length < (_capacity-1)
		var l = _length
		_values[l] = value
		_keys[value] = l
		_length = l + 1
	end

	redef fun remove(value: Int)
	do
		assert not is_empty
		var l = _length
		if l > 1 then
			var last = _values[l - 1]
			var pos = _keys[value]
			_keys[last] = pos
			_values[pos] = last
		end
		_length = l - 1
	end

	redef fun has(value: Int): Bool
	do
		assert value < _capacity
		var pos = _keys[value]
		if pos < _length then
			return _values[pos] == value
		end
		return false
	end

	redef fun first: Int
	do
		assert _length > 0
		return _values[0]
	end

	redef fun is_empty: Bool
	do
		return not (_length > 0)
	end

	redef fun clear
	do
		_length = 0
	end

	redef fun iterator: DummyIterator
	do
		return new DummyIterator(self)
	end

	private fun value_at(pos: Int): Int
	do
		return _values[pos]
	end

	init(capacity: Int)
	do
		_capacity = capacity
		_keys = new NativeArray[Int](capacity)
		_values = new NativeArray[Int](capacity)
	end
end

class DummyIterator
	super Iterator[Int]
	private var array: DummyArray
	private var pos: Int

	redef fun item: Int
	do
		assert is_ok
		return _array.value_at(_pos)
	end

	redef fun is_ok: Bool
	do
		return _pos < _array.length
	end

	redef fun next do _pos = _pos + 1 end

	init(array: DummyArray)
	do
		_pos = 0
		_array = array
	end
end
<commit_msg>lib/dummy_array: fixes old inits<commit_after># This file is part of NIT ( http://www.nitlanguage.org ).
#
# Copyright 2008 <NAME> <<EMAIL>>
#
# This file is free software, which comes along with NIT.  This software is
# distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without  even  the implied warranty of  MERCHANTABILITY or  FITNESS FOR A
# PARTICULAR PURPOSE.  You can modify it is you want,  provided this header
# is kept unaltered, and a notification of the changes is added.
# You  are  allowed  to  redistribute it and sell it, alone or is a part of
# another product.

class DummyArray
	super Set[Int]
	private var capacity: Int
	redef var length: Int
	private var keys: NativeArray[Int]
	private var values: NativeArray[Int]

	redef fun add(value: Int)
	do
		assert full: _length < (_capacity-1)
		var l = _length
		_values[l] = value
		_keys[value] = l
		_length = l + 1
	end

	redef fun remove(value: Int)
	do
		assert not is_empty
		var l = _length
		if l > 1 then
			var last = _values[l - 1]
			var pos = _keys[value]
			_keys[last] = pos
			_values[pos] = last
		end
		_length = l - 1
	end

	redef fun has(value: Int): Bool
	do
		assert value < _capacity
		var pos = _keys[value]
		if pos < _length then
			return _values[pos] == value
		end
		return false
	end

	redef fun first: Int
	do
		assert _length > 0
		return _values[0]
	end

	redef fun is_empty: Bool
	do
		return not (_length > 0)
	end

	redef fun clear
	do
		_length = 0
	end

	redef fun iterator: DummyIterator
	do
		return new DummyIterator(self)
	end

	private fun value_at(pos: Int): Int
	do
		return _values[pos]
	end

	init(capacity: Int) is old_style_init do
		_capacity = capacity
		_keys = new NativeArray[Int](capacity)
		_values = new NativeArray[Int](capacity)
	end
end

class DummyIterator
	super Iterator[Int]
	private var array: DummyArray
	private var pos: Int

	redef fun item: Int
	do
		assert is_ok
		return _array.value_at(_pos)
	end

	redef fun is_ok: Bool
	do
		return _pos < _array.length
	end

	redef fun next do _pos = _pos + 1 end

	init(array: DummyArray) is old_style_init do
		_pos = 0
		_array = array
	end
end

{'fraction_non_alphanumeric': 0.07016717683070403, 'fraction_numerical': 0.007063809748057453, 'mean_word_length': 3.303951367781155, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4397485', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1477, 'n_words': 587}