public void swap(int first, int second)
    {
        long[] firstSegment = array[segment(first)];
        int firstOffset = offset(first);

        long[] secondSegment = array[segment(second)];
        int secondOffset = offset(second);

        long tmp = firstSegment[firstOffset];
        firstSegment[firstOffset] = secondSegment[secondOffset];
        secondSegment[secondOffset] = tmp;
    }
@Test
    public void testSwap()
    {
        AdaptiveLongBigArray array = new AdaptiveLongBigArray();
        // swap within a segment
        array.ensureCapacity(10);
        array.set(1, 0xDEADBEAF);
        assertEquals(array.get(1), 0xDEADBEAF);
        array.set(9, 0xBEAFDEAD);
        assertEquals(array.get(9), 0xBEAFDEAD);
        array.swap(1, 9);
        assertEquals(array.get(1), 0xBEAFDEAD);
        assertEquals(array.get(9), 0xDEADBEAF);
        // swap between segments
        array.ensureCapacity(MAX_SEGMENT_LENGTH + 1);
        array.set(1, 0xDEADBEAF);
        assertEquals(array.get(1), 0xDEADBEAF);
        array.set(MAX_SEGMENT_LENGTH + 9, 0xBEAFDEAD);
        assertEquals(array.get(MAX_SEGMENT_LENGTH + 9), 0xBEAFDEAD);
        array.swap(1, MAX_SEGMENT_LENGTH + 9);
        assertEquals(array.get(1), 0xBEAFDEAD);
        assertEquals(array.get(MAX_SEGMENT_LENGTH + 9), 0xDEADBEAF);
    }