Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
BlockSplitterMiddle.cs
1using System;
2
4{
5 internal class BlockSplitterMiddle : BlockSplitter
6 {
7 public int MiddlePos;
8
9 public BlockSplitterMiddle(int PayloadSize)
10 : base()
11 {
12 this.MiddlePos = PayloadSize / 2 + ObjectBTreeFile.BlockHeaderSize; // Instead of median value, select the value residing in the middle of the block. These are not the same, since object values might be of different sizes.
13 }
14
15 public override void NextBlock(uint BlockLink, byte[] Block, int Pos, int Len, uint ChildSize)
16 {
17 int c = 4 + Len;
18
19 if (!(this.ParentObject is null))
20 {
21 if (this.RightSizeSubtree < uint.MaxValue)
22 {
23 this.RightSizeSubtree++;
24
25 this.RightSizeSubtree += ChildSize;
26 if (this.RightSizeSubtree < ChildSize)
27 this.RightSizeSubtree = uint.MaxValue;
28 }
29
30 Array.Copy(BitConverter.GetBytes(BlockLink), 0, RightBlock, RightPos, 4);
31 this.RightPos += 4;
32 Array.Copy(Block, Pos, RightBlock, RightPos, Len);
33 this.RightPos += Len;
34 this.TotPos += c;
35 }
36 else if (this.TotPos + c <= this.MiddlePos)
37 {
38 if (this.LeftSizeSubtree < uint.MaxValue)
39 {
40 this.LeftSizeSubtree++;
41
42 this.LeftSizeSubtree += ChildSize;
43 if (this.LeftSizeSubtree < ChildSize)
44 this.LeftSizeSubtree = uint.MaxValue;
45 }
46
47 Array.Copy(BitConverter.GetBytes(BlockLink), 0, LeftBlock, LeftPos, 4);
48 this.LeftPos += 4;
49 Array.Copy(Block, Pos, LeftBlock, LeftPos, Len);
50 this.LeftPos += Len;
51 this.TotPos += c;
52 }
53 else
54 {
55 this.LeftLastBlockIndex = BlockLink;
56 this.LeftSizeSubtree += ChildSize;
57 if (this.LeftSizeSubtree < ChildSize)
58 this.LeftSizeSubtree = uint.MaxValue;
59
60 this.ParentObject = new byte[Len];
61 Array.Copy(Block, Pos, this.ParentObject, 0, Len);
62 }
63 }
64
65 }
66}