@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()) ; }
@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 void dumpNodeTable(NodeTable nodeTable, Set<NodeTable> dumpedNodeTables) { if ( dumpedNodeTables.contains(nodeTable) ) return ; Iterator<Pair<NodeId, Node>> iter = nodeTable.all() ; for ( ; iter.hasNext() ; ) { Pair<NodeId, Node> pair = iter.next() ; NodeId nid = pair.car() ; Node n = pair.cdr(); String x = NodeFmtLib.displayStr(n) ; System.out.printf("%016X %s\n", nid.getId(), x) ; } dumpedNodeTables.add(nodeTable) ; }
@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()) ; }
@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 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 int hashCode() { return hashCodeObject(car()) ^ hashCodeObject(cdr())<<1 ; }
/** Play the patches (range is inclusive at both ends) */ private void playPatches(long firstPatchVer, long lastPatchVer) { Pair<Version, Node> p = play(datasourceId, target, dLink, firstPatchVer, lastPatchVer); Version patchLastVersion = p.car(); Node patchLastIdNode = p.cdr(); setLocalState(patchLastVersion, patchLastIdNode); }
@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 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 int hashCode() { return hashCodeObject(car()) ^ hashCodeObject(cdr())<<1 ; }
@Override public int hashCode() { return hashCodeObject(car()) ^ hashCodeObject(cdr())<<1 ; }
private Iterator<Pair<NodeId, Node>> all2() { Iterator<Pair<Long, ByteBuffer>> objs = objects.all() ; Function<Pair<Long, ByteBuffer>, Pair<NodeId, Node>> transform = item -> { NodeId id = NodeId.create(item.car().longValue()); ByteBuffer bb = item.cdr(); Node n = NodeLib.decode(bb); return new Pair<>(id, n); }; return Iter.map(objs, transform) ; }
private static Iterator<Pair<NodeId, Node>> all(ObjectFile objFile) { Iterator<Pair<Long, ByteBuffer>> objs = objFile.all() ; Function<Pair<Long, ByteBuffer>, Pair<NodeId, Node>> transform = item -> { NodeId id = NodeId.create(item.car().longValue()); ByteBuffer bb = item.cdr(); Node n = NodeLib.decode(bb); return new Pair<>(id, n); }; return Iter.map(objs, transform) ; }
private static Iterator<Pair<NodeId, Node>> all(ObjectFile objFile) { Iterator<Pair<Long, ByteBuffer>> objs = objFile.all() ; Function<Pair<Long, ByteBuffer>, Pair<NodeId, Node>> transform = item -> { NodeId id = NodeId.create(item.car().longValue()); ByteBuffer bb = item.cdr(); Node n = NodeLib.decode(bb); return new Pair<>(id, n); }; return Iter.map(objs, transform) ; }
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()) ; }
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()) ; }
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()) ; }
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()) ; }
public static void dump(OutputStream w, ObjectFile objFile) { // Better to hack the indexes? Iterator<Pair<NodeId, Node>> iter = all(objFile) ; long count = 0 ; try (IndentedWriter iw = new IndentedWriter(w)) { if ( ! iter.hasNext() ) { iw.println("No nodes in the .dat file"); return ; } for ( ; iter.hasNext() ; ) { Pair<NodeId, Node> pair = iter.next() ; iw.print(pair.car().toString()) ; iw.print(" : ") ; // iw.print(pair.cdr()) ; Node n = pair.cdr() ; String $ = stringForNode(n) ; iw.print($) ; iw.println() ; count++ ; } iw.println() ; iw.printf("Total: " + count) ; iw.println() ; iw.flush() ; } }