Trims the node to save storage: shrinks overallocations
()
| 753 | * Trims the node to save storage: shrinks overallocations |
| 754 | * */ |
| 755 | public synchronized long trim() { |
| 756 | AdjacentNodes adjacentNodesOld = this.adjacentNodes; |
| 757 | int newSize = 0; |
| 758 | int until = adjacentNodesOld.offsetLengths(); |
| 759 | for (int offsetPos = 0; 2 * offsetPos < until; offsetPos++) { |
| 760 | int length = blockLength(adjacentNodesOld, offsetPos); |
| 761 | newSize += length; |
| 762 | } |
| 763 | Object[] nodesWithEdgePropertiesNew = new Object[newSize]; |
| 764 | AdjacentNodes res = new AdjacentNodes(nodesWithEdgePropertiesNew, new byte[until]); |
| 765 | |
| 766 | int off = 0; |
| 767 | for(int offsetPos = 0; 2*offsetPos < until; offsetPos++){ |
| 768 | int start = startIndex(adjacentNodesOld, offsetPos); |
| 769 | int length = blockLength(adjacentNodesOld, offsetPos); |
| 770 | System.arraycopy(adjacentNodesOld.nodesWithEdgeProperties, start, nodesWithEdgePropertiesNew, off, length); |
| 771 | res = res.setOffset(2 * offsetPos, off); |
| 772 | res = res.setOffset(2 * offsetPos + 1, length); |
| 773 | off += length; |
| 774 | } |
| 775 | int oldSize = adjacentNodesOld.nodesWithEdgeProperties.length; |
| 776 | this.adjacentNodes = res; |
| 777 | |
| 778 | return (long) newSize + (((long) oldSize) << 32); |
| 779 | } |
| 780 | |
| 781 | public final boolean isDirty() { |
| 782 | return dirty; |