Exemple #1
0
        private SLEntry[] EnumerateAndAdd(BID blockId, int currentDepth)
        {
            if (currentDepth == 1)
            {
                var subnodeBlock = subnodeBlockLoader.LoadNode(blockId);

                var intermediateKeys = entriesFromIntermediateSubnodeBlockExtractor.Extract(subnodeBlock);

                var allLeafKeys = new List <SLEntry>();

                foreach (var key in intermediateKeys)
                {
                    var leafKeys = EnumerateAndAdd(key.SLBlockId, currentDepth - 1);

                    allLeafKeys.AddRange(leafKeys);
                }

                return(allLeafKeys.ToArray());
            }
            else
            {
                var subnodeBlock = subnodeBlockLoader.LoadNode(blockId);

                return(entriesFromLeafSubnodeBlockExtractor.Extract(subnodeBlock));
            }
        }
Exemple #2
0
        private BID[] EnumerateAndAdd(BID blockId, int currentDepth)
        {
            if (currentDepth == 2)
            {
                var blockEntry = GetDataBlockEntry(blockId).Value;

                var internalDataBlock = internalDataBlockLoader.LoadNode(blockEntry);

                var intermediateKeys = blockIdsFromInternalDataBlockExtractor.Extract(internalDataBlock);

                var allLeafKeys = new List <BID>();

                foreach (var key in intermediateKeys)
                {
                    var leafKeys = EnumerateAndAdd(key, currentDepth - 1);

                    allLeafKeys.AddRange(leafKeys);
                }

                return(allLeafKeys.ToArray());
            }

            if (currentDepth == 1)
            {
                var blockEntry = GetDataBlockEntry(blockId).Value;

                var internalDataBlock = internalDataBlockLoader.LoadNode(blockEntry);

                return(blockIdsFromInternalDataBlockExtractor.Extract(internalDataBlock));
            }

            return(new[] { blockId });
        }
Exemple #3
0
        public Maybe <TLeafEntry> Find(TEntryKey key, TNodeReference rootNodeReference)
        {
            var node = nodeLoader.LoadNode(rootNodeReference);

            var level = nodeLevelFromNodeExtractor.Extract(node);

            if (level == 0)
            {
                var leafEntries = leafEntriesFromNodeExtractor.Extract(node);

                foreach (var entry in leafEntries)
                {
                    var leafKey = entryKeyFromLeafEntryExtractor.Extract(entry);

                    if (leafKey.CompareTo(key) == 0)
                    {
                        return(Maybe <TLeafEntry> .OfValue(entry));
                    }
                }

                return(Maybe <TLeafEntry> .NoValue());
            }

            var intermediateEntries = intermediateEntriesFromNodeExtractor.Extract(node);

            for (var i = 0; i < intermediateEntries.Length; i++)
            {
                var intermediateKey = entryKeyFromIntermediateEntryExtractor.Extract(intermediateEntries[i]);

                if (intermediateKey.CompareTo(key) == 0 || (intermediateKey.CompareTo(key) > 0 && i == 0))
                {
                    var nodeReference = nodeReferenceFromIntermediateEntryExtractor.Extract(intermediateEntries[i]);

                    return(Find(key, nodeReference));
                }

                if (intermediateKey.CompareTo(key) > 0)
                {
                    var nodeReference = nodeReferenceFromIntermediateEntryExtractor.Extract(intermediateEntries[i - 1]);

                    return(Find(key, nodeReference));
                }
            }

            var lastIntermediateEntry =
                intermediateEntries[intermediateEntries.Length - 1];

            var nodeReferenceFromLastIntermediateEntry =
                nodeReferenceFromIntermediateEntryExtractor.Extract(lastIntermediateEntry);

            return(Find(key, nodeReferenceFromLastIntermediateEntry));
        }