private long selectByIndex(final long index)
	{
		assert this.borderIndex <= index && index < this.maxNum : "idx: " + index + " i: "
			+ borderIndex + " max: " + maxNum;

		final long borderElement = replace.containsKey(borderIndex) ? this.replace.get(borderIndex)
				: borderIndex;
		final long drawnElement = replace.containsKey(index) ? this.replace.get(index) : index;

		final long result = drawnElement;
		if (borderIndex == index) // Special case: i = j
		{
			assert borderElement == drawnElement;

			if (borderElement != borderIndex)
			{
				replace.remove(borderElement);
				replace.remove(borderIndex);
			}
		}
		else
		{
			createReplacePointer(index, borderElement);

			if (borderElement != borderIndex) // Cases 2 and 4
			{
				replace.remove(borderIndex);
			}

			if (drawnElement != index) // Cases 3 and 4
			{
				replace.remove(drawnElement);
			}
		}

		++this.borderIndex;

		return result;
	}