@Override public void ensureNode(int nodeId) { long tmp = (long) nodeId * rowSizeInBytes; da.ensureCapacity(tmp + rowSizeInBytes); }
private void ensureTurnCostIndex(int nodeIndex) { turnCosts.ensureCapacity(((long) nodeIndex + 4) * turnCostsEntryBytes); }
private void ensureGeometry(long bytePos, int byteLength) { wayGeometry.ensureCapacity(bytePos + byteLength); }
/** * Determine next free edgeId and ensure byte capacity to store edge * <p> * * @return next free edgeId */ protected int nextEdgeId() { int nextEdge = edgeCount; edgeCount++; if (edgeCount < 0) throw new IllegalStateException("too many edges. new edge id would be negative. " + toString()); edges.ensureCapacity(((long) edgeCount + 1) * edgeEntryBytes); return nextEdge; }
@Override public SubnetworkStorage create(long byteCount) { da.create(2000); da.ensureCapacity(byteCount); return this; }
int getOrigEdgeCount(int edgeId) { edgeId -= maxEdgesCount; if (edgeId < 0) return 1; long tmp = (long) edgeId * 4; originalEdges.ensureCapacity(tmp + 4); return originalEdges.getInt(tmp); } }
protected int nextShortcutId() { int nextSC = shortcutCount; shortcutCount++; if (shortcutCount < 0) throw new IllegalStateException("too many shortcuts. new shortcut id would be negative. " + toString()); shortcuts.ensureCapacity(((long) shortcutCount + 1) * shortcutEntryBytes); return nextSC + baseGraph.edgeCount; }
void setOrigEdgeCount(int edgeId, int value) { edgeId -= maxEdgesCount; if (edgeId < 0) { // ignore setting as every normal edge has original edge count of 1 if (value != 1) throw new IllegalStateException("Trying to set original edge count for normal edge to a value = " + value + ", edge:" + (edgeId + maxEdgesCount) + ", max:" + maxEdgesCount + ", graph.max:" + prepareGraph.getEdges()); return; } long tmp = (long) edgeId * 4; originalEdges.ensureCapacity(tmp + 4); originalEdges.setInt(tmp, value); }
/** * Check if byte capacity of DataAcess nodes object is sufficient to include node index, else * extend byte capacity */ final void ensureNodeIndex(int nodeIndex) { if (!initialized) throw new AssertionError("The graph has not yet been initialized."); if (nodeIndex < nodeCount) return; long oldNodes = nodeCount; nodeCount = nodeIndex + 1; boolean capacityIncreased = nodes.ensureCapacity((long) nodeCount * nodeEntryBytes); if (capacityIncreased) { long newBytesCapacity = nodes.getCapacity(); initNodeRefs(oldNodes * nodeEntryBytes, newBytesCapacity); } }
/** * @return the byte pointer to the name */ public long put(String name) { if (name == null || name.isEmpty()) { return 0; } if (name.equals(lastName)) { return lastIndex; } byte[] bytes = getBytes(name); long oldPointer = bytePointer; names.ensureCapacity(bytePointer + 1 + bytes.length); byte[] sizeBytes = new byte[]{ (byte) bytes.length }; names.setBytes(bytePointer, sizeBytes, sizeBytes.length); bytePointer++; names.setBytes(bytePointer, bytes, bytes.length); bytePointer += bytes.length; lastName = name; lastIndex = oldPointer; return oldPointer; }
void _freeze() { long maxCapacity = ((long) getNodes()) * nodeCHEntryBytes; nodesCH.ensureCapacity(maxCapacity); long baseCapacity = baseGraph.nodes.getCapacity(); // copy normal edge refs into ch edge refs for (long pointer = N_CH_REF, basePointer = baseGraph.N_EDGE_REF; pointer < maxCapacity; pointer += nodeCHEntryBytes, basePointer += baseGraph.nodeEntryBytes) { if (basePointer >= baseCapacity) throw new IllegalStateException("Cannot copy edge refs into ch graph. " + "pointer:" + pointer + ", cap:" + maxCapacity + ", basePtr:" + basePointer + ", baseCap:" + baseCapacity); nodesCH.setInt(pointer, baseGraph.nodes.getInt(basePointer)); } }
@Override public int put(long key, int value) { if (key <= lastKey) { long oldValueIndex = binarySearch(keys, 0, getSize(), key); if (oldValueIndex < 0) { throw new IllegalStateException("Cannot insert keys lower than " + "the last key " + key + " < " + lastKey + ". Only updating supported"); } oldValueIndex *= 4; int oldValue = values.getInt(oldValueIndex); values.setInt(oldValueIndex, value); return oldValue; } values.ensureCapacity(size + 4); values.setInt(size, value); long doubleSize = size * 2; keys.ensureCapacity(doubleSize + 8); // store long => double of the orig size byte[] longBytes = bitUtil.fromLong(key); keys.setBytes(doubleSize, longBytes, 8); lastKey = key; size += 4; return -1; }
intIndex++; leafs++; dataAccess.ensureCapacity((long) (intIndex + len + 1) * 4); if (len == 1) { continue; dataAccess.ensureCapacity((long) (intIndex + 1) * 4); int beforeIntIndex = intIndex; intIndex = store(subEntry, beforeIntIndex);
@Override public DataAccess copyTo(DataAccess da) { copyHeader(da); da.ensureCapacity(getCapacity()); long cap = getCapacity(); // currently get/setBytes does not support copying more bytes then segmentSize int segSize = Math.min(da.getSegmentSize(), getSegmentSize()); byte[] bytes = new byte[segSize]; boolean externalIntBased = ((AbstractDataAccess) da).isIntBased(); for (long bytePos = 0; bytePos < cap; bytePos += segSize) { // read if (isIntBased()) { for (int offset = 0; offset < segSize; offset += 4) { bitUtil.fromInt(bytes, getInt(bytePos + offset), offset); } } else { getBytes(bytePos, bytes, segSize); } // write if (externalIntBased) { for (int offset = 0; offset < segSize; offset += 4) { da.setInt(bytePos + offset, bitUtil.toInt(bytes, offset)); } } else { da.setBytes(bytePos, bytes, segSize); } } return da; }
@Test public void testEnsureCapacity() { DataAccess da = createDataAccess(name); da.create(128); da.setInt(31 * 4, 200); assertEquals(200, da.getInt(31 * 4)); da.ensureCapacity(2 * 128); assertEquals(200, da.getInt(31 * 4)); // now it shouldn't fail da.setInt(32 * 4, 220); assertEquals(220, da.getInt(32 * 4)); da.close(); // ensure some bigger area da = createDataAccess(name); da.create(200 * 4); da.ensureCapacity(600 * 4); da.close(); }
@Test public void testSegments() { DataAccess da = createDataAccess(name); da.setSegmentSize(128); da.create(10); assertEquals(1, da.getSegments()); da.ensureCapacity(500); int olds = da.getSegments(); assertTrue(olds > 3); da.setInt(400, 321); da.flush(); da.close(); da = createDataAccess(name); assertTrue(da.loadExisting()); assertEquals(olds, da.getSegments()); assertEquals(321, da.getInt(400)); da.close(); }
@Override public synchronized boolean ensureCapacity( long bytes ) { return inner.ensureCapacity(bytes); }
@Override public void ensureNode(int nodeId) { long tmp = (long) nodeId * rowSizeInBytes; da.ensureCapacity(tmp + rowSizeInBytes); }
private int getOrigEdgeCount(int edgeId) { edgeId -= maxEdgesCount; if (edgeId < 0) return 1; long tmp = (long) edgeId * 4; originalEdges.ensureCapacity(tmp + 4); return originalEdges.getInt(tmp); }
protected int nextShortcutId() { int nextSC = shortcutCount; shortcutCount++; if (shortcutCount < 0) throw new IllegalStateException("too many shortcuts. new shortcut id would be negative. " + toString()); shortcuts.ensureCapacity(((long) shortcutCount + 1) * shortcutEntryBytes); return nextSC + baseGraph.edgeCount; }