@Test public void iterator() throws Exception { String head = "iterator0"; RList list = db.getList(); int num = 100 * 10000; try { for (int i = 0; i < num; i++) { list.add(head, ("hello" + i).getBytes()); } long startTime = System.currentTimeMillis(); try (RIterator<RList> iterator = list.iterator(head)) { while (iterator.hasNext()) { RList.Entry er = iterator.next(); Long index = er.getIndex(); byte[] value = er.getValue(); } } long endTime = System.currentTimeMillis(); long startTime2 = System.currentTimeMillis(); for (int i = 0; i < num; i++) { list.get(head, i); } long endTime2 = System.currentTimeMillis(); Thread.sleep(2000); } finally { list.delete(head); } }
@Override @SuppressWarnings("unchecked") public RIterator<RList> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); if (metaV == null) { return null; } ValueK valueK_seek = new ValueK(key_b.length, key_b, metaV.getVersion(), metaV.left); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); ValueKD valueKD = valueK_seek.convertValueBytes(); iterator.seek(valueKD.toBytes()); RIterator<RList> rIterator = new RIterator<>(iterator, this, valueKD.toHeadBytes()); return rIterator; } }
RList extends RCollection { @Override @SuppressWarnings("unchecked") public RIterator<RList> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); if (metaV == null) { return null; } ValueK valueK_seek = new ValueK(key_b.length, key_b, metaV.getVersion(), metaV.left); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); ValueKD valueKD = valueK_seek.convertValueBytes(); iterator.seek(valueKD.toBytes()); RIterator<RList> rIterator = new RIterator<>(iterator, this, valueKD.toHeadBytes()); return rIterator; } } }
RList extends RCollection { @Override @SuppressWarnings("unchecked") public RIterator<RList> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); if (metaV == null) { return null; } ValueK valueK_seek = new ValueK(key_b.length, key_b, metaV.getVersion(), metaV.left); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); ValueKD valueKD = valueK_seek.convertValueBytes(); iterator.seek(valueKD.toBytes()); RIterator<RList> rIterator = new RIterator<>(iterator, this, valueKD.toHeadBytes()); return rIterator; } } protected  RList(DB db); }
RList extends RCollection { @Override @SuppressWarnings("unchecked") public RIterator<RList> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); if (metaV == null) { return null; } ValueK valueK_seek = new ValueK(key_b.length, key_b, metaV.getVersion(), metaV.left); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); ValueKD valueKD = valueK_seek.convertValueBytes(); iterator.seek(valueKD.toBytes()); RIterator<RList> rIterator = new RIterator<>(iterator, this, valueKD.toHeadBytes()); return rIterator; } } protected  RList(DB db); void add(String key, byte[] v); void addAll(String key, List<byte[]> vs); void addAllMayTTL(String key, List<byte[]> vs, int ttl); void set(String key, long i, byte[] v); byte[] get(String key, long i); List<byte[]> get(String key, List<Long> is); Long left(String key); Long right(String key); int size(String key); void deleteFast(String key); void delete(String key); boolean isExist(String key); List<byte[]> range(String key, long start, long end); @Override @SuppressWarnings("unchecked") RIterator<RList> iterator(String key); Entry getEntry(RocksIterator iterator); List<byte[]> blpop(String key, int num); List<byte[]> brpop(String key, int num); @Override KeyIterator getKeyIterator(); void ttl(String key, int ttl); void delTtl(String key); int getTtl(String key); void addMayTTL(String key, byte[] v, int ttl); }
RList extends RCollection { @Override @SuppressWarnings("unchecked") public RIterator<RList> iterator(String key) throws KitDBException { try (CloseLock ignored = checkClose()) { byte[] key_b = getKey(key); MetaV metaV = getMeta(key_b); if (metaV == null) { return null; } ValueK valueK_seek = new ValueK(key_b.length, key_b, metaV.getVersion(), metaV.left); RocksIterator iterator = newIterator(SstColumnFamily.DEFAULT); ValueKD valueKD = valueK_seek.convertValueBytes(); iterator.seek(valueKD.toBytes()); RIterator<RList> rIterator = new RIterator<>(iterator, this, valueKD.toHeadBytes()); return rIterator; } } protected  RList(DB db); void add(String key, byte[] v); void addAll(String key, List<byte[]> vs); void addAllMayTTL(String key, List<byte[]> vs, int ttl); void set(String key, long i, byte[] v); byte[] get(String key, long i); List<byte[]> get(String key, List<Long> is); Long left(String key); Long right(String key); int size(String key); void deleteFast(String key); void delete(String key); boolean isExist(String key); List<byte[]> range(String key, long start, long end); @Override @SuppressWarnings("unchecked") RIterator<RList> iterator(String key); Entry getEntry(RocksIterator iterator); List<byte[]> blpop(String key, int num); List<byte[]> brpop(String key, int num); @Override KeyIterator getKeyIterator(); void ttl(String key, int ttl); void delTtl(String key); int getTtl(String key); void addMayTTL(String key, byte[] v, int ttl); final static String HEAD; final static byte[] HEAD_VALUE_B; final static byte[] HEAD_B; }