public void dump() { System.out.printf("%06d:%06d min=%d max=%d%n", getStart(), getEnd(), getActiveMinProcId(), getActiveMaxProcId()); System.out.println("Update:"); for (int i = 0; i < updated.length; ++i) { for (int j = 0; j < BITS_PER_WORD; ++j) { System.out.print((updated[i] & (1L << j)) != 0 ? "1" : "0"); } System.out.println(" " + i); } System.out.println(); System.out.println("Delete:"); for (int i = 0; i < deleted.length; ++i) { for (int j = 0; j < BITS_PER_WORD; ++j) { System.out.print((deleted[i] & (1L << j)) != 0 ? "1" : "0"); } System.out.println(" " + i); } System.out.println(); }
public void dump() { System.out.printf("%06d:%06d min=%d max=%d%n", getStart(), getEnd(), getMinProcId(), getMaxProcId()); System.out.println("Update:"); for (int i = 0; i < updated.length; ++i) { for (int j = 0; j < BITS_PER_WORD; ++j) { System.out.print((updated[i] & (1L << j)) != 0 ? "1" : "0"); } System.out.println(" " + i); } System.out.println(); System.out.println("Delete:"); for (int i = 0; i < deleted.length; ++i) { for (int j = 0; j < BITS_PER_WORD; ++j) { System.out.print((deleted[i] & (1L << j)) != 0 ? "1" : "0"); } System.out.println(" " + i); } System.out.println(); }
public void merge(final BitSetNode rightNode) { int delta = (int)(rightNode.getEnd() - getEnd()) >> ADDRESS_BITS_PER_WORD; long[] newBitmap; int oldSize = updated.length; int newSize = (delta - rightNode.updated.length); int offset = oldSize + newSize; newBitmap = new long[oldSize + delta]; System.arraycopy(updated, 0, newBitmap, 0, oldSize); System.arraycopy(rightNode.updated, 0, newBitmap, offset, rightNode.updated.length); updated = newBitmap; newBitmap = new long[oldSize + delta]; System.arraycopy(deleted, 0, newBitmap, 0, oldSize); System.arraycopy(rightNode.deleted, 0, newBitmap, offset, rightNode.deleted.length); deleted = newBitmap; for (int i = 0; i < newSize; ++i) { updated[offset + i] = 0; deleted[offset + i] = partial ? 0 : WORD_MASK; } }
if ((procId - leftNode.getEnd()) <= (rightNode.getStart() - procId)) {
if ((procId - leftNode.getEnd()) <= (rightNode.getStart() - procId)) { return growNode(leftNode, procId);
public void grow(final long procId) { int delta, offset; if (procId < start) { // add to head long newStart = alignDown(procId); delta = (int)(start - newStart) >> ADDRESS_BITS_PER_WORD; offset = delta; start = newStart; } else { // Add to tail long newEnd = alignUp(procId + 1); delta = (int)(newEnd - getEnd()) >> ADDRESS_BITS_PER_WORD; offset = 0; } long[] newBitmap; int oldSize = updated.length; newBitmap = new long[oldSize + delta]; for (int i = 0; i < newBitmap.length; ++i) { newBitmap[i] = 0; } System.arraycopy(updated, 0, newBitmap, offset, oldSize); updated = newBitmap; newBitmap = new long[deleted.length + delta]; for (int i = 0; i < newBitmap.length; ++i) { newBitmap[i] = partial ? 0 : WORD_MASK; } System.arraycopy(deleted, 0, newBitmap, offset, oldSize); deleted = newBitmap; }
public void grow(final long procId) { int delta, offset; if (procId < start) { // add to head long newStart = alignDown(procId); delta = (int)(start - newStart) >> ADDRESS_BITS_PER_WORD; offset = delta; start = newStart; } else { // Add to tail long newEnd = alignUp(procId + 1); delta = (int)(newEnd - getEnd()) >> ADDRESS_BITS_PER_WORD; offset = 0; } long[] newBitmap; int oldSize = updated.length; newBitmap = new long[oldSize + delta]; for (int i = 0; i < newBitmap.length; ++i) { newBitmap[i] = 0; } System.arraycopy(updated, 0, newBitmap, offset, oldSize); updated = newBitmap; newBitmap = new long[deleted.length + delta]; for (int i = 0; i < newBitmap.length; ++i) { newBitmap[i] = partial ? 0 : WORD_MASK; } System.arraycopy(deleted, 0, newBitmap, offset, oldSize); deleted = newBitmap; }
public void merge(final BitSetNode rightNode) { int delta = (int)(rightNode.getEnd() - getEnd()) >> ADDRESS_BITS_PER_WORD; long[] newBitmap; int oldSize = updated.length; int newSize = (delta - rightNode.updated.length); int offset = oldSize + newSize; newBitmap = new long[oldSize + delta]; System.arraycopy(updated, 0, newBitmap, 0, oldSize); System.arraycopy(rightNode.updated, 0, newBitmap, offset, rightNode.updated.length); updated = newBitmap; newBitmap = new long[oldSize + delta]; System.arraycopy(deleted, 0, newBitmap, 0, oldSize); System.arraycopy(rightNode.deleted, 0, newBitmap, offset, rightNode.deleted.length); deleted = newBitmap; for (int i = 0; i < newSize; ++i) { updated[offset + i] = 0; deleted[offset + i] = partial ? 0 : WORD_MASK; } }
public long getMaxProcId() { long maxProcId = getEnd(); for (int i = deleted.length - 1; i >= 0; --i) { if (deleted[i] == 0) { return maxProcId; } if (deleted[i] != WORD_MASK) { for (int j = BITS_PER_WORD - 1; j >= 0; --j) { if ((deleted[i] & (1L << j)) == 0) { return maxProcId - (BITS_PER_WORD - 1 - j); } } } maxProcId -= BITS_PER_WORD; } return maxProcId; }
public void setDeletedIfSet(final ProcedureStoreTracker tracker) { BitSetNode trackerNode = null; for (BitSetNode node: map.values()) { final long minProcId = node.getStart(); final long maxProcId = node.getEnd(); for (long procId = minProcId; procId <= maxProcId; ++procId) { if (!node.isUpdated(procId)) continue; trackerNode = tracker.lookupClosestNode(trackerNode, procId); if (trackerNode == null || !trackerNode.contains(procId) || trackerNode.isUpdated(procId)) { // the procedure was removed or updated node.delete(procId); } } } }
public long getActiveMaxProcId() { long maxProcId = getEnd(); for (int i = deleted.length - 1; i >= 0; --i) { if (deleted[i] == 0) { return maxProcId; } if (deleted[i] != WORD_MASK) { for (int j = BITS_PER_WORD - 1; j >= 0; --j) { if ((deleted[i] & (1L << j)) == 0) { return maxProcId - (BITS_PER_WORD - 1 - j); } } } maxProcId -= BITS_PER_WORD; } return maxProcId; }
public boolean contains(final long procId) { return start <= procId && procId <= getEnd(); }
public boolean contains(final long procId) { return start <= procId && procId <= getEnd(); }
@Override public String toString() { return "BitSetNode(" + getStart() + "-" + getEnd() + ")"; }
@Override public String toString() { return "BitSetNode(" + getStart() + "-" + getEnd() + ")"; }
public boolean canMerge(final BitSetNode rightNode) { // Can just compare 'starts' since boundaries are aligned to multiples of BITS_PER_WORD. assert start < rightNode.start; return (rightNode.getEnd() - start) < MAX_NODE_SIZE; }