org.helidb.util.bplus
Class PositionDependentNodeSizeStrategy

java.lang.Object
  extended by org.helidb.util.bplus.PositionDependentNodeSizeStrategy
All Implemented Interfaces:
NodeSizeStrategy

public class PositionDependentNodeSizeStrategy
extends Object
implements NodeSizeStrategy

This NodeSizeStrategy gives node sizes that depend on where in the file they are stored. It keeps a map of position - size pairs and a default node size for the positions not present in the map.

This is most commonly used to give the first node in the file a smaller size to be able to accommodate header information in the file without having the contents of the root node spill over into the next disk block.

Warning! Don't let node sizes vary too much! Two of the smallest nodes need to be able to accommodate all the records in one of the largest node +1. (This is a requirement when splitting nodes.)

Since:
1.0
Author:
Karl Gustafsson
In_jar:
helidb-core

Constructor Summary
PositionDependentNodeSizeStrategy(int defaultSize, Map<Long,Integer> nodeSizes)
           
 
Method Summary
 int getMaxNumberOfRecordsPerNode(int nodeHeaderSize, int recordSize, long pos)
          Given the supplied size of the node header and records, how many records will fit in a node?
 int getNodeSize(int nodeHeaderSize, int recordSize, long pos)
          Given the supplied size of the node header and records, how many bytes will a node occupy?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PositionDependentNodeSizeStrategy

public PositionDependentNodeSizeStrategy(int defaultSize,
                                         Map<Long,Integer> nodeSizes)
                                  throws IllegalArgumentException
Throws:
IllegalArgumentException
Method Detail

getMaxNumberOfRecordsPerNode

public int getMaxNumberOfRecordsPerNode(int nodeHeaderSize,
                                        int recordSize,
                                        long pos)
Description copied from interface: NodeSizeStrategy
Given the supplied size of the node header and records, how many records will fit in a node?

Specified by:
getMaxNumberOfRecordsPerNode in interface NodeSizeStrategy
Parameters:
nodeHeaderSize - The size of the node header.
recordSize - The size of a record.
pos - The position of the node in the file.
Returns:
The number of records that fit in a node.

getNodeSize

public int getNodeSize(int nodeHeaderSize,
                       int recordSize,
                       long pos)
Description copied from interface: NodeSizeStrategy
Given the supplied size of the node header and records, how many bytes will a node occupy?

Specified by:
getNodeSize in interface NodeSizeStrategy
Parameters:
nodeHeaderSize - The size of the node header.
recordSize - The size of a record.
pos - The position of the node in the file.
Returns:
The size of a node, in bytes.