@Test public void contains() { db.run(tr -> { tr.set(rsSubspace.pack(new byte[]{(byte)0x10}), new byte[]{(byte)0x66}); tr.set(rsSubspace.pack(new byte[]{(byte)0x77}), new byte[]{(byte)0x88}); tr.set(rsSubspace.pack(new byte[]{(byte)0x88}), new byte[]{(byte)0x99}); tr.set(rsSubspace.pack(new byte[]{(byte)0x99}), new byte[]{(byte)0x99,(byte)0x00}); return null; }); assertFalse(rs.contains(db, new byte[]{(byte) 0x05}).join(), "Key \\x05 inside when shouldn't be"); assertTrue(rs.contains(db, new byte[]{(byte) 0x10}).join(), "Key \\x10 outside when shouldn't be"); assertTrue(rs.contains(db, new byte[]{(byte) 0x10, (byte) 0x66}).join(), "Key \\x10\\x66 outside when shouldn't be"); assertTrue(rs.contains(db, new byte[]{(byte) 0x55}).join(), "Key \\x55 outside when shouldn't be"); assertFalse(rs.contains(db, new byte[]{(byte) 0x66}).join(), "Key \\x66 inside when shouldn't be"); assertFalse(rs.contains(db, new byte[]{(byte) 0x66, (byte) 0x00}).join(), "Key \\x66\\x00 inside when shouldn't be"); assertFalse(rs.contains(db, new byte[]{(byte) 0x70, (byte) 0x00}).join(), "Key \\x70\\x00 inside when shouldn't be"); assertTrue(rs.contains(db, new byte[]{(byte) 0x77}).join(), "Key \\x77 outside when shouldn't be"); assertTrue(rs.contains(db, new byte[]{(byte) 0x77, (byte) 0x00}).join(), "Key \\x77\\x00 outside when shouldn't be"); assertTrue(rs.contains(db, new byte[]{(byte) 0x79, (byte) 0x00}).join(), "Key \\x79\\x00 outside when shouldn't be"); assertTrue(rs.contains(db, new byte[]{(byte) 0x88}).join(), "Key \\x88 outside when shouldn't be"); assertTrue(rs.contains(db, new byte[]{(byte) 0x99}).join(), "Key \\x99 outside when shouldn't be"); assertFalse(rs.contains(db, new byte[]{(byte) 0x99, (byte) 0x00}).join(), "Key \\x99\\x00 inside when shouldn't be"); assertFalse(rs.contains(db, new byte[]{(byte) 0xaa}).join(), "Key \\xaa inside when shouldn't be"); }
@Nonnull public CompletableFuture<Boolean> contains(@Nonnull TransactionContext tc, @Nonnull byte[] key) { checkKey(key); return tc.runAsync(tr -> { byte[] frobnicated = subspace.pack(key); tr.addReadConflictKey(frobnicated); AsyncIterator<KeyValue> iterator = tr.snapshot().getRange(subspace.range().begin, keyAfter(frobnicated), 1, true).iterator(); return iterator.onHasNext().thenApply(hasNext -> { if (!hasNext) { return false; } else { byte[] endRange = iterator.next().getValue(); return ByteArrayUtil.compareUnsigned(key, endRange) < 0; } }); }); }
RangeSet { @Nonnull public CompletableFuture<Boolean> contains(@Nonnull TransactionContext tc, @Nonnull byte[] key) { checkKey(key); return tc.runAsync(tr -> { byte[] frobnicated = subspace.pack(key); tr.addReadConflictKey(frobnicated); AsyncIterator<KeyValue> iterator = tr.snapshot().getRange(subspace.range().begin, keyAfter(frobnicated), 1, true).iterator(); return iterator.onHasNext().thenApply(hasNext -> { if (!hasNext) { return false; } else { byte[] endRange = iterator.next().getValue(); return ByteArrayUtil.compareUnsigned(key, endRange) < 0; } }); }); } }
RangeSet { @Nonnull public CompletableFuture<Boolean> contains(@Nonnull TransactionContext tc, @Nonnull byte[] key) { checkKey(key); return tc.runAsync(tr -> { byte[] frobnicated = subspace.pack(key); tr.addReadConflictKey(frobnicated); AsyncIterator<KeyValue> iterator = tr.snapshot().getRange(subspace.range().begin, keyAfter(frobnicated), 1, true).iterator(); return iterator.onHasNext().thenApply(hasNext -> { if (!hasNext) { return false; } else { byte[] endRange = iterator.next().getValue(); return ByteArrayUtil.compareUnsigned(key, endRange) < 0; } }); }); } RangeSet(@Nonnull Subspace subspace); }
RangeSet { @Nonnull public CompletableFuture<Boolean> contains(@Nonnull TransactionContext tc, @Nonnull byte[] key) { checkKey(key); return tc.runAsync(tr -> { byte[] frobnicated = subspace.pack(key); tr.addReadConflictKey(frobnicated); AsyncIterator<KeyValue> iterator = tr.snapshot().getRange(subspace.range().begin, keyAfter(frobnicated), 1, true).iterator(); return iterator.onHasNext().thenApply(hasNext -> { if (!hasNext) { return false; } else { byte[] endRange = iterator.next().getValue(); return ByteArrayUtil.compareUnsigned(key, endRange) < 0; } }); }); } RangeSet(@Nonnull Subspace subspace); @Nonnull CompletableFuture<Boolean> contains(@Nonnull TransactionContext tc, @Nonnull byte[] key); @Nonnull CompletableFuture<Boolean> insertRange(@Nonnull TransactionContext tc, @Nonnull Range r); @Nonnull CompletableFuture<Boolean> insertRange(@Nonnull TransactionContext tc, @Nonnull Range r, boolean requireEmpty); @Nonnull CompletableFuture<Boolean> insertRange(@Nonnull TransactionContext tc, @Nullable byte[] begin, @Nullable byte[] end); @Nonnull CompletableFuture<Boolean> insertRange(@Nonnull TransactionContext tc, @Nullable byte[] begin, @Nullable byte[] end, boolean requireEmpty); @Nonnull CompletableFuture<List<Range>> missingRanges(@Nonnull ReadTransactionContext tc); @Nonnull AsyncIterable<Range> missingRanges(@Nonnull ReadTransaction tr); @Nonnull CompletableFuture<List<Range>> missingRanges(@Nonnull ReadTransactionContext tc, @Nonnull Range superRange); @Nonnull AsyncIterable<Range> missingRanges(@Nonnull ReadTransaction tr, @Nonnull Range superRange); @Nonnull CompletableFuture<List<Range>> missingRanges(@Nonnull ReadTransactionContext tc, @Nullable byte[] begin, @Nullable byte[] end); @Nonnull AsyncIterable<Range> missingRanges(@Nonnull ReadTransaction tr, @Nullable byte[] begin, @Nullable byte[] end); @Nonnull CompletableFuture<List<Range>> missingRanges(@Nonnull ReadTransactionContext tc, @Nullable byte[] begin, @Nullable byte[] end, int limit); @Nonnull AsyncIterable<Range> missingRanges(@Nonnull ReadTransaction tr, @Nullable byte[] begin, @Nullable byte[] end, int limit); @Nonnull CompletableFuture<Void> clear(@Nonnull TransactionContext tc); @Nonnull CompletableFuture<String> rep(@Nonnull ReadTransactionContext tc); }
RangeSet { @Nonnull public CompletableFuture<Boolean> contains(@Nonnull TransactionContext tc, @Nonnull byte[] key) { checkKey(key); return tc.runAsync(tr -> { byte[] frobnicated = subspace.pack(key); tr.addReadConflictKey(frobnicated); AsyncIterator<KeyValue> iterator = tr.snapshot().getRange(subspace.range().begin, keyAfter(frobnicated), 1, true).iterator(); return iterator.onHasNext().thenApply(hasNext -> { if (!hasNext) { return false; } else { byte[] endRange = iterator.next().getValue(); return ByteArrayUtil.compareUnsigned(key, endRange) < 0; } }); }); } RangeSet(@Nonnull Subspace subspace); @Nonnull CompletableFuture<Boolean> contains(@Nonnull TransactionContext tc, @Nonnull byte[] key); @Nonnull CompletableFuture<Boolean> insertRange(@Nonnull TransactionContext tc, @Nonnull Range r); @Nonnull CompletableFuture<Boolean> insertRange(@Nonnull TransactionContext tc, @Nonnull Range r, boolean requireEmpty); @Nonnull CompletableFuture<Boolean> insertRange(@Nonnull TransactionContext tc, @Nullable byte[] begin, @Nullable byte[] end); @Nonnull CompletableFuture<Boolean> insertRange(@Nonnull TransactionContext tc, @Nullable byte[] begin, @Nullable byte[] end, boolean requireEmpty); @Nonnull CompletableFuture<List<Range>> missingRanges(@Nonnull ReadTransactionContext tc); @Nonnull AsyncIterable<Range> missingRanges(@Nonnull ReadTransaction tr); @Nonnull CompletableFuture<List<Range>> missingRanges(@Nonnull ReadTransactionContext tc, @Nonnull Range superRange); @Nonnull AsyncIterable<Range> missingRanges(@Nonnull ReadTransaction tr, @Nonnull Range superRange); @Nonnull CompletableFuture<List<Range>> missingRanges(@Nonnull ReadTransactionContext tc, @Nullable byte[] begin, @Nullable byte[] end); @Nonnull AsyncIterable<Range> missingRanges(@Nonnull ReadTransaction tr, @Nullable byte[] begin, @Nullable byte[] end); @Nonnull CompletableFuture<List<Range>> missingRanges(@Nonnull ReadTransactionContext tc, @Nullable byte[] begin, @Nullable byte[] end, int limit); @Nonnull AsyncIterable<Range> missingRanges(@Nonnull ReadTransaction tr, @Nullable byte[] begin, @Nullable byte[] end, int limit); @Nonnull CompletableFuture<Void> clear(@Nonnull TransactionContext tc); @Nonnull CompletableFuture<String> rep(@Nonnull ReadTransactionContext tc); static final int UNLIMITED; }