Add item to the first available slot and return its index

Property definitions

gamnit $ GroupedArray :: add
	# Add `item` to the first available slot and return its index
	fun add(item: E): Int
	do
		length += 1

		if available.not_empty then
			# starts & ends can't be empty

			var i = available.take
			items[i] = item

			if i == starts.first - 1 then
				# slot 0 free, 1 taken
				starts.first -= 1
			else if i == 0 then
				# slot 0 and more free
				starts.unshift 0
				ends.unshift 1
			else if starts.length >= 2 and ends.first + 1 == starts[1] then
				# merge 2 chunks
				ends.remove_at 0
				starts.remove_at 1
			else
				# at end of first chunk
				ends.first += 1
			end
			return i
		end

		items.add item
		if ends.is_empty then
			starts.add 0
			ends.add 1
		else ends.last += 1
		return ends.last - 1
	end
lib/gamnit/flat/flat_core.nit:1563,2--1598,4

gamnit $ GroupedSprites :: add
	redef fun add(item)
	do
		var index = super
		item.context_index = index
		return index
	end
lib/gamnit/flat/flat_core.nit:1722,2--1727,4