Exemple #1
0
 public InteriorNode(IGistConfig <TKey, TValue> config, IGistIndexRecords <TKey> records)
     : base(config, null)
 {
     Records        = records;
     Block          = config.Blocks.AllocateBlock(GetBytes());
     Block.UserData = this;
 }
Exemple #2
0
 public static int CreateRoot(IGistConfig <TKey, TValue> config, KeyValuePair <TKey, TValue> record)
 {
     return(new LeafNode <TKey, TValue>(
                config,
                config.Ext.CreateLeafRecords(new[] { record }))
            .Block.BlockId);
 }
Exemple #3
0
 public static int CreateRoot(IGistConfig <TKey, TValue> config, IList <KeyValuePair <TKey, int> > records)
 {
     return(new InteriorNode <TKey, TValue>(
                config,
                config.Ext.CreateIndexRecords(records)
                )
            .Block.BlockId);
 }
Exemple #4
0
        public static INode <TKey, TValue> GetNode(IGistConfig <TKey, TValue> config, int blockId)
        {
            var block = config.Blocks.GetBlock(blockId);

            if (block.UserData != null)
            {
                return((INode <TKey, TValue>)block.UserData);
            }

            INode <TKey, TValue> node = null;

            using (var stream = new MemoryStream(block.Data, false))
            {
                using (var reader = new BinaryReader(stream))
                {
                    var header = ReadBlockHeader(reader);
                    if ((header.Flags & NodeFlags.IsLeafNode) == NodeFlags.IsLeafNode)
                    {
                        node = new LeafNode <TKey, TValue>(
                            config,
                            block,
                            config.Ext.CreateLeafRecords(reader)
                            );
                    }
                    else if ((header.Flags & NodeFlags.IsInteriorNode) == NodeFlags.IsInteriorNode)
                    {
                        node = new InteriorNode <TKey, TValue>(
                            config,
                            block,
                            config.Ext.CreateIndexRecords(reader)
                            );
                    }
                }
            }
            if (node == null)
            {
                throw new ApplicationException("Bad block header");
            }
            block.UserData = node;
            return(node);
        }
Exemple #5
0
 public LeafNode(IGistConfig <TKey, TValue> config, IBlock block, IGistLeafRecords <TKey, TValue> records)
     : base(config, block)
 {
     Records = records;
 }
Exemple #6
0
 public LeafNode(IGistConfig <TKey, TValue> config, IGistLeafRecords <TKey, TValue> records)
     : base(config, null)
 {
     Records = records;
     Block   = config.Blocks.AllocateBlock(GetBytes());
 }
Exemple #7
0
 public InteriorNode(IGistConfig <TKey, TValue> config, IBlock block, IGistIndexRecords <TKey> records)
     : base(config, block)
 {
     Records = records;
 }
Exemple #8
0
 protected Node(IGistConfig <TKey, TValue> config, IBlock block)
 {
     Config = config;
     Block  = block;
 }
Exemple #9
0
 public Gist(IBlockReference blockReference, IGistConfig <TKey, TValue> config)
 {
     BlockReference = blockReference;
     Config         = config;
 }