@Override public long skip(long n) { if (n > length - position) n = length - position; position += n; updateCurrent(); return n; }
/** Returns the label bit stream. * * <p>This method takes care of creating the bit stream from the right source—the byte array, * the stream of multiple byte arrays or the label file itself. * * @return the label bit stream. */ protected InputBitStream newInputBitStream() throws FileNotFoundException { return byteArray != null ? new InputBitStream(byteArray) : labelStream != null ? new InputBitStream(new FastMultiByteArrayInputStream(labelStream)) : new InputBitStream(basename + LABELS_EXTENSION); }
/** Returns an iterator over the successors of a given node. * * @param x a node. * @return an iterator over the successors of the node. */ @Override public LazyIntIterator successors(final int x) { // We just call successors(int, InputBitStream, int[][], int[], int[]) with // a newly created input bit stream and null elsewhere. if (x < 0 || x >= n) throw new IllegalArgumentException("Node index out of range: " + x); if (offsetType <= 0) throw new UnsupportedOperationException("Random access to successor lists is not possible with sequential or offline graphs"); final InputBitStream ibs = isMemory ? new InputBitStream(graphMemory) : new InputBitStream(isMapped ? mappedGraphStream.copy() : new FastMultiByteArrayInputStream(graphStream), 0); return successors(x, ibs, null, null); }
/** Creates a new bit stream to read the graph from, based on the data of the host instance. * * @return a newly-created bit stream to read the graph from. * @throws FileNotFoundException if the graph is read from a file, but the file does not exist. */ private InputBitStream createInputBitStream() throws FileNotFoundException { if (offsetType == -1) return new InputBitStream(new FileInputStream(basename + GRAPH_EXTENSION), STD_BUFFER_SIZE); else if (isMemory) return new InputBitStream(graphMemory); else if (isMapped) return new InputBitStream(mappedGraphStream.copy()); else return new InputBitStream(new FastMultiByteArrayInputStream(graphStream), 0); }
@Override public int read() { if (length == position) return -1; final int disp = (int)(position++ & SLICE_MASK); if (disp == 0) updateCurrent(); return current[disp] & 0xFF; }
@Override public BVGraph copy() { final BVGraph result = new BVGraph(); result.basename = basename; result.n = n; result.m = m; result.isMemory = isMemory; result.isMapped = isMapped; result.graphMemory = graphMemory; result.graphStream = graphStream != null ? new FastMultiByteArrayInputStream(graphStream) : null; result.mappedGraphStream = mappedGraphStream != null ? mappedGraphStream.copy() : null; result.offsets = offsets; result.maxRefCount = maxRefCount; result.windowSize = windowSize; result.minIntervalLength = minIntervalLength; result.offsetType = offsetType; result.zetaK = zetaK; result.outdegreeCoding = outdegreeCoding; result.blockCoding = blockCoding; result.residualCoding = residualCoding; result.referenceCoding = referenceCoding; result.blockCountCoding = blockCountCoding; result.offsetCoding = offsetCoding; result.flags = flags; result.outdegreeIbs = offsetType <= 0 ? null : isMemory ? new InputBitStream(graphMemory): new InputBitStream(isMapped ? mappedGraphStream.copy() : new FastMultiByteArrayInputStream(graphStream), 0); return result; }
@Override public void position(final long newPosition) { position = Math.min(newPosition, length); updateCurrent(); }
isMemory = true; else graphStream = new FastMultiByteArrayInputStream(fis, fis.getChannel().size()); if (offsetType >= 0) outdegreeIbs = isMemory ? new InputBitStream(graphMemory): new InputBitStream(isMapped ? mappedGraphStream.copy() : new FastMultiByteArrayInputStream(graphStream), 0);
@Override public int read(final byte[] b, int offset, final int length) { final long remaining = this.length - position; if (remaining == 0) return length == 0 ? 0 : -1; int n = (int)Math.min(length, remaining); final int m = n; for(;;) { final int disp = (int)(position & SLICE_MASK); if (disp == 0) updateCurrent(); final int res = Math.min(n, current.length - disp); System.arraycopy(current, disp, b, offset, res); n -= res; position += res; if (n == 0) return m; offset += res; } }
final long size = fis.getChannel().size(); if (size <= Integer.MAX_VALUE) byteArray = BinIO.loadBytes(basename + LABELS_EXTENSION); else labelStream = new FastMultiByteArrayInputStream(fis, size);
successors(x - ref, isMemory ? new InputBitStream(graphMemory) : new InputBitStream(isMapped ? mappedGraphStream.copy() : new FastMultiByteArrayInputStream(graphStream), 0), null, null) );