byte[] VariableKeyLengthSerialize(TreeNode <K, V> node) { using (var m = new MemoryStream()) { // 4 bytes uint parent id m.Write(LittleEndianByteOrder.GetBytes((uint)node.ParentId), 0, 4); // Followed by 4 bytes of how many entries m.Write(LittleEndianByteOrder.GetBytes((uint)node.EntriesCount), 0, 4); // Followed by 4 bytes of how manu child references m.Write(LittleEndianByteOrder.GetBytes((uint)node.ChildrenNodeCount), 0, 4); // Write entries.. for (var i = 0; i < node.EntriesCount; i++) { // Write entry var entry = node.GetEntry(i); var key = this.keySerializer.Serialize(entry.Item1); var value = this.valueSerializer.Serialize(entry.Item2); m.Write(LittleEndianByteOrder.GetBytes((int)key.Length), 0, 4); m.Write(key, 0, key.Length); m.Write(value, 0, value.Length); } // Write child refs.. var childrenIds = node.ChildrenIds; for (var i = 0; i < node.ChildrenNodeCount; i++) { m.Write(LittleEndianByteOrder.GetBytes((uint)childrenIds[i]), 0, 4); } return(m.ToArray()); } }
// // Private Methods // TreeNode <K, V> CreateFirstRoot() { // Write down the id of first node into the first block recordStorage.Create(LittleEndianByteOrder.GetBytes((uint)2)); // Return a new node, this node should has id of 2 return(Create(null, null)); }
void AppendUInt32ToContent(IBlock block, uint value) { var contentLength = block.GetHeader(kBlockContentLength); if ((contentLength % 4) != 0) { throw new DataMisalignedException("Block content length not %4: " + contentLength); } block.Write(src: LittleEndianByteOrder.GetBytes(value), srcOffset: 0, dstOffset: (int)contentLength, count: 4); }
public TreeNode <K, V> CreateNewRoot(K key, V value, uint leftNodeId, uint rightNodeId) { // Create new node as normal var node = Create(new Tuple <K, V>[] { new Tuple <K, V> (key, value) }, new uint[] { leftNodeId, rightNodeId }); // Make it the root node this.rootNode = node; recordStorage.Update(1u, LittleEndianByteOrder.GetBytes(node.Id)); // Then return it return(this.rootNode); }
public void MakeRoot(TreeNode <K, V> node) { this.rootNode = node; recordStorage.Update(1u, LittleEndianByteOrder.GetBytes(node.Id)); }
public static void WriteBuffer(int value, byte[] buffer, int bufferOffset) { Buffer.BlockCopy(LittleEndianByteOrder.GetBytes((int)value), 0, buffer, bufferOffset, 4); }
public byte[] Serialize(long value) { return(LittleEndianByteOrder.GetBytes(value)); }