public long maxSetBit() {
        ThreadSafeBitSetSegments segments = this.segments.get();

        int segmentIdx = segments.numSegments() - 1;

        for(;segmentIdx >= 0; segmentIdx--) {
            AtomicLongArray segment = segments.getSegment(segmentIdx);
            for(int longIdx=segment.length() - 1; longIdx >= 0; longIdx--) {
                long l = segment.get(longIdx);
                if(l != 0)
                    return (segmentIdx << log2SegmentSize) + (longIdx * 64) + (63 - Long.numberOfLeadingZeros(l));
            }
        }

        return -1;
    }
@Test
    public void testMaxSetBit() {
        ThreadSafeBitSet set1 = new ThreadSafeBitSet();

        set1.set(100);
        Assert.assertEquals(100, set1.maxSetBit());

        set1.set(100000);
        Assert.assertEquals(100000, set1.maxSetBit());

        set1.set(1000000);
        Assert.assertEquals(1000000, set1.maxSetBit());

        set1.clearAll();
        set1.set(555555);
        Assert.assertEquals(555555, set1.maxSetBit());
    }