@Test public void iterator() throws KitDBException { String head = "iterator0"; 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); FList<ZSet.Entry> entries_2 = new FList<>(num); try (RIterator<ZSet> iterator = set.iterator(head)) { while (iterator.hasNext()) { ZSet.Entry er = iterator.next(); entries_2.add(er); } } Assert.assertEquals(entries_2.size(), entries.size()); Map<Long, ZSet.Entry> map = entries.toMap(ZSet.Entry::getScore); for (ZSet.Entry entry : entries_2) { ZSet.Entry entry_1 = map.get(entry.getScore()); Assert.assertNotNull(entry_1); Assert.assertArrayEquals(entry_1.getValue(), entry.getValue()); } } finally { set.delete(head); } }
@Override @SuppressWarnings("unchecked") public RIterator<ZSet> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); SData sData = new SData(key_b.length, key_b, metaV.getVersion(), "".getBytes()); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); iterator.seek(sData.getHead()); RIterator<ZSet> rIterator = new RIterator<>(iterator, this, sData.getHead()); return rIterator; } }
ZSet extends RCollection { @Override @SuppressWarnings("unchecked") public RIterator<ZSet> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); SData sData = new SData(key_b.length, key_b, metaV.getVersion(), "".getBytes()); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); iterator.seek(sData.getHead()); RIterator<ZSet> rIterator = new RIterator<>(iterator, this, sData.getHead()); return rIterator; } } }
ZSet extends RCollection { @Override @SuppressWarnings("unchecked") public RIterator<ZSet> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); SData sData = new SData(key_b.length, key_b, metaV.getVersion(), "".getBytes()); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); iterator.seek(sData.getHead()); RIterator<ZSet> rIterator = new RIterator<>(iterator, this, sData.getHead()); return rIterator; } } protected  ZSet(DB db); }
ZSet extends RCollection { @Override @SuppressWarnings("unchecked") public RIterator<ZSet> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); SData sData = new SData(key_b.length, key_b, metaV.getVersion(), "".getBytes()); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); iterator.seek(sData.getHead()); RIterator<ZSet> rIterator = new RIterator<>(iterator, this, sData.getHead()); return rIterator; } } 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 { @Override @SuppressWarnings("unchecked") public RIterator<ZSet> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); SData sData = new SData(key_b.length, key_b, metaV.getVersion(), "".getBytes()); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); iterator.seek(sData.getHead()); RIterator<ZSet> rIterator = new RIterator<>(iterator, this, sData.getHead()); return rIterator; } } 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; }