@Override protected final void endReachedInner() { Pair<Integer, Record> pair1 = peek(0) ; Pair<Integer, Record> pair2 = peek(1) ; if ( pair1 == null || pair2 == null ) // Insufficient blocks to repack. return ; if ( debug ) System.out.printf("Rebalance: %s %s\n", pair1, pair2) ; Record newSplitPoint = rebalance(pair1.car(), pair1.cdr(), pair2.car(), pair2.cdr()) ; // Needed?? if ( newSplitPoint != null ) { if ( debug ) System.out.println("Reset split point: "+pair1.cdr()+" => "+newSplitPoint) ; pair1 = new Pair<>(pair1.car(), newSplitPoint) ; if ( debug ) System.out.printf(" %s %s\n", pair1, pair2) ; set(0, pair1) ; } }
@Override public boolean equals(Object other) { if ( this == other ) return true ; // If it's a pair of a different <A,B> then .equals // Pair<A,B>(null,null) is equal to Pair<C,D>(null ,null) // Type erasure makes this hard to check otherwise. // Use class X extends Pair<A,B> and implement .equals to do // instanceof then call super.equals. if( ! ( other instanceof Pair<?,?> ) ) return false ; Pair<?,?> p2 = (Pair<?,?>)other ; return Objects.equals(car(), p2.car()) && Objects.equals(cdr(), p2.cdr()) ; }
@Test public void libTxn_11() { Pair<Long, Long> p = Txn.calculateWrite(integer, () -> { integer.inc() ; return Pair.create(integer.value(), integer.get()) ; }) ; assertEquals(InitValue, p.getLeft().longValue()) ; assertEquals(InitValue+1, p.getRight().longValue()) ; assertEquals(InitValue+1, integer.get()) ; assertEquals(InitValue+1, integer.value()) ; } }
public static <L, R> Pair<L,R> create(L x, R y) { return new Pair<>(x,y) ; }
static Iterator<Pair<Integer, Record>> printIndexBlocks(Iterator<Pair<Integer, Record>> iter2, BPTreeNodeMgr bptNodeMgr) { divider() ; List<Pair<Integer, Record>> pairs = Iter.toList(iter2) ; System.out.printf(">>Packed index blocks\n") ; for ( Pair<Integer, Record> pair : pairs ) { System.out.printf(" %s\n", pair) ; BPTreeNode bpNode = bptNodeMgr.getRead(pair.car(), BPlusTreeParams.RootParent) ; bpNode.setIsLeaf(true) ; System.out.printf("BPTreeNode: %d\n", bpNode.getId()) ; System.out.println(bpNode) ; bptNodeMgr.release(bpNode) ; } System.out.printf("<<Packed index blocks\n") ; return pairs.iterator() ; }
private static void contains(ObjectFile f, String... contents) { Iterator<Pair<Long, ByteBuffer>> iter = f.all() ; for ( String s : contents ) { assertTrue(iter.hasNext()) ; Pair<Long, ByteBuffer> p = iter.next() ; String s2 = StrUtils.fromUTF8bytes(p.cdr().array()) ; assertEquals(s, s2) ; } assertFalse(iter.hasNext()) ; }
@Test public void libTxn_11() { Pair<Long, Long> p = Txn.calculateWrite(integer, () -> { integer.inc() ; return Pair.create(integer.value(), integer.get()) ; }) ; assertEquals(InitValue, p.getLeft().longValue()) ; assertEquals(InitValue+1, p.getRight().longValue()) ; assertEquals(InitValue+1, integer.get()) ; assertEquals(InitValue+1, integer.value()) ; } }
@Override public boolean equals(Object other) { if ( this == other ) return true ; // If it's a pair of a different <A,B> then .equals // Pair<A,B>(null,null) is equal to Pair<C,D>(null ,null) // Type erasure makes this hard to check otherwise. // Use class X extends Pair<A,B> and implement .equals to do // instanceof then call super.equals. if( ! ( other instanceof Pair<?,?> ) ) return false ; Pair<?,?> p2 = (Pair<?,?>)other ; return Objects.equals(car(), p2.car()) && Objects.equals(cdr(), p2.cdr()) ; }
public static <L, R> Pair<L,R> create(L x, R y) { return new Pair<L,R>(x,y) ; }
public Pair<Integer, String> findAfter(int index) { for (Pair<Integer, String> pair : this.starts) { if (pair.getLeft() > index) return pair; } return null; }
static Iterator<Pair<Integer, Record>> summarizeDataBlocks(Iterator<Pair<Integer, Record>> iter, RecordBufferPageMgr recordPageMgr) { divider() ; List<Pair<Integer, Record>> pairs = Iter.toList(iter) ; System.out.println("summarizeDataBlocks: " + pairs) ; for ( Pair<Integer, Record> pair : pairs ) { RecordBufferPage rbp = recordPageMgr.getRead(pair.car()) ; System.out.printf("%s -- RecordBufferPage[id=%d,link=%d] (%d) -> [%s]\n", pair, rbp.getId(), rbp.getLink(), rbp.getCount(), rbp.getRecordBuffer().getHigh()) ; recordPageMgr.release(rbp) ; } return pairs.iterator() ; }
private static void contains(ObjectFile f, String... contents) { Iterator<Pair<Long, ByteBuffer>> iter = f.all() ; for ( String s : contents ) { assertTrue(iter.hasNext()) ; Pair<Long, ByteBuffer> p = iter.next() ; String s2 = StrUtils.fromUTF8bytes(p.cdr().array()) ; assertEquals(s, s2) ; } assertFalse(iter.hasNext()) ; }
@Test public void libTxn_11() { Pair<Long, Long> p = Txn.calculateWrite(integer, () -> { integer.inc() ; return Pair.create(integer.value(), integer.get()) ; }) ; assertEquals(InitValue, p.getLeft().longValue()) ; assertEquals(InitValue+1, p.getRight().longValue()) ; assertEquals(InitValue+1, integer.get()) ; assertEquals(InitValue+1, integer.value()) ; } }
@Override protected final void endReachedInner() { Pair<Integer, Record> pair1 = peek(0) ; Pair<Integer, Record> pair2 = peek(1) ; if ( pair1 == null || pair2 == null ) // Insufficient blocks to repack. return ; if ( debug ) System.out.printf("Rebalance: %s %s\n", pair1, pair2) ; Record newSplitPoint = rebalance(pair1.car(), pair1.cdr(), pair2.car(), pair2.cdr()) ; // Needed?? if ( newSplitPoint != null ) { if ( debug ) System.out.println("Reset split point: " + pair1.cdr() + " => " + newSplitPoint) ; pair1 = new Pair<>(pair1.car(), newSplitPoint) ; if ( debug ) System.out.printf(" %s %s\n", pair1, pair2) ; set(0, pair1) ; } }
@Override public boolean equals(Object other) { if ( this == other ) return true ; // If it's a pair of a different <A,B> then .equals // Pair<A,B>(null,null) is equal to Pair<C,D>(null ,null) // Type erasure makes this hard to check otherwise. // Use class X extends Pair<A,B> and implement .equals to do // instanceof then call super.equals. if( ! ( other instanceof Pair<?,?> ) ) return false ; Pair<?,?> p2 = (Pair<?,?>)other ; return Lib.equal(car(), p2.car()) && Lib.equal(cdr(), p2.cdr()) ; }