@Test public void iterator() throws KitDBException { String head = "iterator0"; RSet set = db.getSet(); int num = 10 * 10000; try { Set<String> stringSet = new HashSet<>(); for (int i = 0; i < num; i++) { set.add(head, ("hello world" + i).getBytes()); stringSet.add(("hello world" + i)); } List<String> stringList = new ArrayList<>(); try (RIterator<RSet> iterator = set.iterator(head)) { while (iterator.hasNext()) { RSet.Entry er = iterator.next(); stringList.add(new String(er.getValue())); } } Assert.assertEquals(num, stringList.size()); Assert.assertTrue(stringSet.containsAll(stringList)); Assert.assertTrue(stringList.containsAll(stringSet)); } finally { set.delete(head); } }
@Override @SuppressWarnings("unchecked") public RIterator<RSet> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); if (metaV == null) { return null; } SData sData = new SData(key_b.length, key_b, metaV.getVersion(), "".getBytes()); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); iterator.seek(sData.getHead()); return new RIterator<>(iterator, this, sData.getHead()); } }
RSet extends RCollection { @Override @SuppressWarnings("unchecked") public RIterator<RSet> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); if (metaV == null) { return null; } SData sData = new SData(key_b.length, key_b, metaV.getVersion(), "".getBytes()); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); iterator.seek(sData.getHead()); return new RIterator<>(iterator, this, sData.getHead()); } } }
RSet extends RCollection { @Override @SuppressWarnings("unchecked") public RIterator<RSet> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); if (metaV == null) { return null; } SData sData = new SData(key_b.length, key_b, metaV.getVersion(), "".getBytes()); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); iterator.seek(sData.getHead()); return new RIterator<>(iterator, this, sData.getHead()); } } protected  RSet(DB db); }
RSet extends RCollection { @Override @SuppressWarnings("unchecked") public RIterator<RSet> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); if (metaV == null) { return null; } SData sData = new SData(key_b.length, key_b, metaV.getVersion(), "".getBytes()); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); iterator.seek(sData.getHead()); return new RIterator<>(iterator, this, sData.getHead()); } } protected  RSet(DB db); List<byte[]> pop(String key, int num); void remove(String key, byte[]... values); boolean contains(String key, byte[] value); void addMayTTL(String key, int ttl, byte[]... values); void add(String key, byte[]... values); @Override void delete(String key); @Override KeyIterator getKeyIterator(); void deleteFast(String key); @Override @SuppressWarnings("unchecked") RIterator<RSet> iterator(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); }
RSet extends RCollection { @Override @SuppressWarnings("unchecked") public RIterator<RSet> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); if (metaV == null) { return null; } SData sData = new SData(key_b.length, key_b, metaV.getVersion(), "".getBytes()); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); iterator.seek(sData.getHead()); return new RIterator<>(iterator, this, sData.getHead()); } } protected  RSet(DB db); List<byte[]> pop(String key, int num); void remove(String key, byte[]... values); boolean contains(String key, byte[] value); void addMayTTL(String key, int ttl, byte[]... values); void add(String key, byte[]... values); @Override void delete(String key); @Override KeyIterator getKeyIterator(); void deleteFast(String key); @Override @SuppressWarnings("unchecked") RIterator<RSet> iterator(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); final static String HEAD; final static byte[] HEAD_B; final static byte[] HEAD_V_B; }