The data of Point is encoded in a block KD-tree structure described with three index files：
The data structure of .kdd file as below:
LeafNodeData describes the informations of leaf nodes, You can see there is only leaf node data in .kdd file and the default maximum number of point in each LeafNodeData is 512. let's see the details about LeafNodeData.
Count describes the number of point in a LeafNodeData.
DocIds describes a set of document IDs which a point in a LeafNodeData belongs to.
PointValues describes a set of point values, each point value is split into two parts: CommonPrefixes and BlockPackedValues.
CommonPrefixes describes a set of common prefixes with each dimension.
Value describes the common prefix value with byte and Length means the length of common prefix value.
BlockPackedValues describes the suffix of point value. BlockPackedValues has two types of data structure according to the suffix. Due to the length of this article, it is not appropriate to extend the introduction.
The data structure of .kdi file as below:
PackedIndexValue describes the informations of all inner nodes. inner node has four types according to the position in KD-tree and its sub node type.
Root node is a inner node and it belongs to RightNodeHasNotLeafChild.
LeftLeafBlockFP describes a pointer where the position of the leftmost leaf node of current inner node in .kdd file is.
Code describes the metadata about inner node, such as spilt dimension or bytes per dimension(How many bytes each value in each dimension takes).
In the stage of constructing a KD-tree, the set of points in a inner node will be split into two sub nodes according to SpiltValue
LeftNumBytes describes the total size of one inner node's sub tree.
LeftNumBytes, Code and SplitValue describes the same meaning as above.
RightLeafBlockFP describes a pointer where the position of the right leaf node of current inner node in .kdd file is.
Code, SplitValue and RightLeafBlockFP describe the same meaning as above.
Code, SplitValue and LeftNumBytes describe the same meaning as above.
Inner node in a KD-tree would be stored in .kid file as blow:
Leaf node in a KD-tree would be stored in .kdd file as blow:
As above said, LeftNumBytes describes the total size of one inner node's sub tree, it makes a reader can skip to the position of inner node's right node in .kid file and its left node is just in the next position.
With LeftLeafBlockFP and RightLeafBlockFP, leaf Node can be positioned in .kdd file.
The data structure of .kdm file as below:
-1 is a fix padding value, In the stage of reading .kdm file, it as a mark means all the Fields has been readed.
In the stage of reading index file, KdiFileLength and KddFileLength used to validate .kdi and .kdd files, such as truncated file or file too long.
FieldNumber uniquely represents a Field.
NumDataDims describes how many dimensions we are storing at the leaf (data) nodes.
NumIndexDims describes how many dimensions we are indexing in the internal nodes.
CountPerLeaf describes the maximum number of point in each leaf node.
BytesPerDim describes the number of bytes per dimension.
NumLeaves describes the number of leaf node.
MinPackedValue describes minimum value for each dimension and MaxPackedValue describes maximum value for each dimension values.
PointCount describes the total number of indexed points across all documents.
DocCount describes the total number of documents that have indexed at least one point.
Length describes the size of PackedIndexValue in Fig.4.
DataStartFP describes a pointer where the beginning position of current field data in .kdd file is.
IndexStartFP describes a pointer where the beginning position of current field data in .kdi file is.