Exemplo n.º 1
0
        public byte[] NodeToBytes(IndirectNode indirectNode)
        {
            var bb = new byte[_options.BlockSize];

            for (var i = 0; i < _options.ReferencesPerIndirectNode; i++)
            {
                var blockNumber = indirectNode[i];
                if (blockNumber == 0) break;
                BitConverter.GetBytes(blockNumber).CopyTo(bb, i * _options.BlockReferenceSize);
            }

            return bb;
        }
Exemplo n.º 2
0
 public void PersistIndirectNode(IndirectNode indirectNode)
 {
     _blockManipulator.WriteBlock(indirectNode.BlockNumber, _blockParser.NodeToBytes(indirectNode));
 }
Exemplo n.º 3
0
 private IEnumerable<byte[]> Blocks(IndirectNode indirectNode, int recursion)
 {
     foreach (var blockNumber in indirectNode.UsedBlockNumbers())
     {
         if (recursion == 0) yield return _blockManipulator.ReadBlock(blockNumber);
         else foreach (var bytes in Blocks(ReadIndirectNode(blockNumber), recursion - 1)) yield return bytes;
     }
 }
Exemplo n.º 4
0
 private IndirectNode CreateIndirectNode()
 {
     var newNodeNumber = _blockAllocation.Allocate();
     var indirectNode = new IndirectNode(new long[_options.ReferencesPerIndirectNode]) { BlockNumber = newNodeNumber };
     _persistence.PersistIndirectNode(indirectNode);
     return indirectNode;
 }
Exemplo n.º 5
0
        /*private void ReplaceInIndirectNode(IndirectNode indirectNode, long toBeReplaced, long toReplace, int recursion)
        {
            for (var i = 0; i < indirectNode.UsedBlockNumbers().Count(); i++)
            {
                var blockNumber = indirectNode[i];

                if (recursion == 0)
                {
                    // TODO: inspect this: is it needed??
                    if (blockNumber != toBeReplaced) continue;

                    indirectNode[i] = toReplace;
                    _persistence.PersistIndirectNode(indirectNode);
                    return;
                }

                ReplaceInIndirectNode(ReadIndirectNode(blockNumber), toBeReplaced, toReplace, recursion - 1);
            }
        }*/
        private void AddFromIndirectNode(IndirectNode indirectNode, List<IIndexNode> l, int recursion)
        {
            foreach (var blockNumber in indirectNode.UsedBlockNumbers())
            {
                if (recursion == 0) l.Add(ReadIndexNode(blockNumber));
                else AddFromIndirectNode(ReadIndirectNode(blockNumber), l, recursion - 1);
            }
        }