@Test public void range() throws KitDBException { String head = "range0"; ZSet set = db.getzSet(); int num = 10 * 10000; try { FList<ZSet.Entry> entries = new FList<>(num); for (int i = 0; i < num; i++) { entries.add(new ZSet.Entry(i, ("hello world" + i).getBytes())); } set.add(head, entries); for (int i = 0; i < 100; i++) { List<ZSet.Entry> list = set.range(head, i * 100, (i + 1) * 100, 1000000); int j = i * 100; for (ZSet.Entry entry : list) { Assert.assertEquals(entry.getScore(), j++); } } int start = 2000; int limit = 100; List<ZSet.Entry> list = set.range(head, start, Integer.MAX_VALUE, limit); Assert.assertEquals(list.size(), limit); for (int i = 0; i < 100; i++) { Assert.assertEquals(list.get(i).getScore(), 2000 + i); } } finally { set.delete(head); } }
public List<Entry> range(String key, long start, long end, int limit) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); List<Entry> entries = new ArrayList<>(); MetaV metaV = getMeta(key_b); ZData zData = new ZData(key_b.length, key_b, metaV.getVersion(), start, "".getBytes()); byte[] seek = zData.getSeek(); byte[] head = zData.getHead(); int count = 0; try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { iterator.seek(seek); long index = 0; while (iterator.isValid() && index <= end && count < limit) { byte[] key_bs = iterator.key(); if (!BytesUtil.checkHead(head, key_bs)) break; ZData izData = ZDataD.build(key_bs).convertValue(); index = izData.getScore(); if (index > end) { break; } entries.add(new Entry(index, izData.value)); count++; iterator.next(); } } return entries; } }
ZSet extends RCollection { public List<Entry> range(String key, long start, long end, int limit) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); List<Entry> entries = new ArrayList<>(); MetaV metaV = getMeta(key_b); ZData zData = new ZData(key_b.length, key_b, metaV.getVersion(), start, "".getBytes()); byte[] seek = zData.getSeek(); byte[] head = zData.getHead(); int count = 0; try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { iterator.seek(seek); long index = 0; while (iterator.isValid() && index <= end && count < limit) { byte[] key_bs = iterator.key(); if (!BytesUtil.checkHead(head, key_bs)) break; ZData izData = ZDataD.build(key_bs).convertValue(); index = izData.getScore(); if (index > end) { break; } entries.add(new Entry(index, izData.value)); count++; iterator.next(); } } return entries; } } }
ZSet extends RCollection { public List<Entry> range(String key, long start, long end, int limit) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); List<Entry> entries = new ArrayList<>(); MetaV metaV = getMeta(key_b); ZData zData = new ZData(key_b.length, key_b, metaV.getVersion(), start, "".getBytes()); byte[] seek = zData.getSeek(); byte[] head = zData.getHead(); int count = 0; try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { iterator.seek(seek); long index = 0; while (iterator.isValid() && index <= end && count < limit) { byte[] key_bs = iterator.key(); if (!BytesUtil.checkHead(head, key_bs)) break; ZData izData = ZDataD.build(key_bs).convertValue(); index = izData.getScore(); if (index > end) { break; } entries.add(new Entry(index, izData.value)); count++; iterator.next(); } } return entries; } } protected  ZSet(DB db); }
ZSet extends RCollection { public List<Entry> range(String key, long start, long end, int limit) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); List<Entry> entries = new ArrayList<>(); MetaV metaV = getMeta(key_b); ZData zData = new ZData(key_b.length, key_b, metaV.getVersion(), start, "".getBytes()); byte[] seek = zData.getSeek(); byte[] head = zData.getHead(); int count = 0; try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { iterator.seek(seek); long index = 0; while (iterator.isValid() && index <= end && count < limit) { byte[] key_bs = iterator.key(); if (!BytesUtil.checkHead(head, key_bs)) break; ZData izData = ZDataD.build(key_bs).convertValue(); index = izData.getScore(); if (index > end) { break; } entries.add(new Entry(index, izData.value)); count++; iterator.next(); } } return entries; } } protected  ZSet(DB db); void add(String key, byte[] v, long score); void add(String key, List<Entry> entryList); void addMayTTL(String key, int ttl, byte[] v, long score); boolean contains(String key, byte[] value); List<Entry> range(String key, long start, long end, int limit); List<Entry> rangeDel(String key, long start, long end, int limit); @Override @SuppressWarnings("unchecked") RIterator<ZSet> iterator(String key); void remove(String key, byte[]... vs); List<Long> score(String key, byte[]... vs); Long score(String key, byte[] v); @Override void delete(String key); @Override KeyIterator getKeyIterator(); void deleteFast(String key); @Override int getTtl(String key); @Override void delTtl(String key); @Override void ttl(String key, int ttl); @Override boolean isExist(String key); @Override int size(String key); @Override Entry getEntry(RocksIterator iterator); }
ZSet extends RCollection { public List<Entry> range(String key, long start, long end, int limit) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); List<Entry> entries = new ArrayList<>(); MetaV metaV = getMeta(key_b); ZData zData = new ZData(key_b.length, key_b, metaV.getVersion(), start, "".getBytes()); byte[] seek = zData.getSeek(); byte[] head = zData.getHead(); int count = 0; try (final RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT)) { iterator.seek(seek); long index = 0; while (iterator.isValid() && index <= end && count < limit) { byte[] key_bs = iterator.key(); if (!BytesUtil.checkHead(head, key_bs)) break; ZData izData = ZDataD.build(key_bs).convertValue(); index = izData.getScore(); if (index > end) { break; } entries.add(new Entry(index, izData.value)); count++; iterator.next(); } } return entries; } } protected  ZSet(DB db); void add(String key, byte[] v, long score); void add(String key, List<Entry> entryList); void addMayTTL(String key, int ttl, byte[] v, long score); boolean contains(String key, byte[] value); List<Entry> range(String key, long start, long end, int limit); List<Entry> rangeDel(String key, long start, long end, int limit); @Override @SuppressWarnings("unchecked") RIterator<ZSet> iterator(String key); void remove(String key, byte[]... vs); List<Long> score(String key, byte[]... vs); Long score(String key, byte[] v); @Override void delete(String key); @Override KeyIterator getKeyIterator(); void deleteFast(String key); @Override int getTtl(String key); @Override void delTtl(String key); @Override void ttl(String key, int ttl); @Override boolean isExist(String key); @Override int size(String key); @Override Entry getEntry(RocksIterator iterator); static String HEAD; static byte[] HEAD_B; static byte[] HEAD_SCORE_B; static byte[] HEAD_V_B; }