public <T extends Comparable<T>> NavigableSet<T> items(int numberOfItems,
                                                           LongPairSet.LongPairFunction<T> longPairConverter) {
        NavigableSet<T> items = new TreeSet<>();
        lock.readLock().lock();
        try {
            for (Map.Entry<Long, RoaringBitmap> entry : map.entrySet()) {
                Iterator<Integer> iterator = entry.getValue().stream().iterator();
                while (iterator.hasNext() && items.size() < numberOfItems) {
                    items.add(longPairConverter.apply(entry.getKey(), iterator.next()));
                }
                if (items.size() == numberOfItems) {
                    break;
                }
            }
        } finally {
            lock.readLock().unlock();
        }
        return items;
    }
@Test
    public void testItems() {
        ConcurrentBitmapSortedLongPairSet set = new ConcurrentBitmapSortedLongPairSet();
        Set<ConcurrentLongPairSet.LongPair> items = set.items(10, ConcurrentLongPairSet.LongPair::new);
        assertEquals(items.size(), 0);
        for (int i = 0; i < 100; i++) {
            set.add(1, i);
            set.add(2, i);
            set.add(5, i);
        }
        for (int i = 0; i < 100; i++) {
            set.add(1, i + 1000);
            set.add(2, i + 1000);
            set.add(5, i + 1000);
        }

        for (int i = 0; i < 100; i++) {
            set.add(1, i + 500);
            set.add(2, i + 500);
            set.add(5, i + 500);
        }
        assertEquals(set.size(), 900);
        assertFalse(set.isEmpty());
        items = set.items(10, ConcurrentLongPairSet.LongPair::new);
        assertEquals(items.size(), 10);
        ConcurrentLongPairSet.LongPair last = null;
        for (ConcurrentLongPairSet.LongPair item : items) {
            if (last != null) {
                assertTrue(item.compareTo(last) > 0);
            }
            last = item;
        }

        items = set.items(900, ConcurrentLongPairSet.LongPair::new);
        assertEquals(items.size(), 900);
        last = null;
        for (ConcurrentLongPairSet.LongPair item : items) {
            if (last != null) {
                assertTrue(item.compareTo(last) > 0);
            }
            last = item;
        }

        items = set.items(1000, ConcurrentLongPairSet.LongPair::new);
        assertEquals(items.size(), 900);
    }