/** * @throws IOException */ private void writeNodeToDisk( NodeEntry<T>[] node, DataOutputStream output ) throws IOException { // write how many entries in the node are not-null output.writeInt( lastNotNull( node ) + 1 ); for ( int i = 0; i < bigM; i++ ) { if ( node[i] != null ) { writeBboxToDisk( output, node[i].bbox ); if ( node[i].entryValue != null ) { output.writeLong( (Long) node[i].entryValue ); } else { output.writeLong( Long.MIN_VALUE ); } if ( node[i].next != null ) { writeNodeToDisk( node[i].next, output ); } } } }
@SuppressWarnings("unchecked") private void insertNode( float[] insertBox, T object, NodeEntry<T>[] entries ) { List<TraceCell<T>> trace = new ArrayList<TraceCell<T>>(); NodeEntry<T>[] leafNode = chooseLeaf( insertBox, entries, trace ); NodeEntry<T> newEntry = new NodeEntry<T>(); newEntry.bbox = insertBox; newEntry.entryValue = object; newEntry.next = null; int index = lastNotNull( leafNode ); leafNode[index + 1] = newEntry; if ( leafNode[bigM] != null ) { int splitIndex = split( leafNode, insertBox, object ); NodeEntry<T>[] addedNode = new NodeEntry[bigM + 1]; Arrays.fill( addedNode, null ); System.arraycopy( leafNode, splitIndex + 1, addedNode, 0, bigM - splitIndex ); Arrays.fill( leafNode, splitIndex + 1, bigM + 1, null ); adjustTree( leafNode, addedNode, trace, trace.size() - 1 ); } else { adjustTree( leafNode, null, trace, trace.size() - 1 ); } }
int nLeftEntries = lastNotNull( leftEntries ); parent[parentIndex].bbox = mbb( copyBoxesFromRange( leftEntries, 0, nLeftEntries + 1 ) ); parent[parentIndex].next = leftEntries; int nRightEntries = lastNotNull( rightEntries ); newEntry.bbox = mbb( copyBoxesFromRange( rightEntries, 0, nRightEntries + 1 ) ); newEntry.next = rightEntries;