@Override
    public int cardinality(long lowerKey, long lowerValue, long upperKey, long upperValue) {
        NavigableMap<Long, BitSet> subMap = rangeBitSetMap.subMap(lowerKey, true, upperKey, true);
        MutableInt v = new MutableInt(0);
        subMap.forEach((key, bitset) -> {
            if (key == lowerKey || key == upperKey) {
                BitSet temp = (BitSet) bitset.clone();
                // Trim the bitset index which < lowerValue
                if (key == lowerKey) {
                    temp.clear(0, (int) Math.max(0, lowerValue));
                }
                // Trim the bitset index which > upperValue
                if (key == upperKey) {
                    temp.clear((int) Math.min(upperValue + 1, temp.length()), temp.length());
                }
                v.add(temp.cardinality());
            } else {
                v.add(bitset.cardinality());
            }
        });
        return v.intValue();
    }
@Test
    public void testCardinality() {
        OpenLongPairRangeSet<LongPair> set = new OpenLongPairRangeSet<>(consumer);
        int v = set.cardinality(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
        assertEquals(v, 0 );
        set.addOpenClosed(1, 0, 1, 20);
        set.addOpenClosed(1, 30, 1, 90);
        set.addOpenClosed(2, 0, 3, 30);
        v = set.cardinality(1, 0, 1, 100);
        assertEquals(v, 80);
        v = set.cardinality(1, 11, 1, 100);
        assertEquals(v, 70);
        v = set.cardinality(1, 0, 1, 90);
        assertEquals(v, 80);
        v = set.cardinality(1, 0, 1, 80);
        assertEquals(v, 70);
        v = set.cardinality(1, 0, 3, 30);
        assertEquals(v, 80 + 31);
    }