예제 #1
0
파일: BTreeRoot.cs 프로젝트: valmac/BTDB
 public void CreateOrUpdate(CreateOrUpdateCtx ctx)
 {
     ctx.TransactionId = _transactionId;
     if (ctx.Stack == null)
     {
         ctx.Stack = new List <NodeIdxPair>();
     }
     else
     {
         ctx.Stack.Clear();
     }
     if (_rootNode == null)
     {
         _rootNode = ctx.WholeKeyLen > BTreeLeafComp.MaxTotalLen
             ? BTreeLeaf.CreateFirst(ctx)
             : BTreeLeafComp.CreateFirst(ctx);
         _keyValueCount = 1;
         ctx.Stack.Add(new NodeIdxPair {
             Node = _rootNode, Idx = 0
         });
         ctx.KeyIndex = 0;
         ctx.Created  = true;
         return;
     }
     ctx.Depth = 0;
     _rootNode.CreateOrUpdate(ctx);
     if (ctx.Split)
     {
         _rootNode = new BTreeBranch(ctx.TransactionId, ctx.Node1, ctx.Node2);
         ctx.Stack.Insert(0, new NodeIdxPair {
             Node = _rootNode, Idx = ctx.SplitInRight ? 1 : 0
         });
     }
     else if (ctx.Update)
     {
         _rootNode = ctx.Node1;
     }
     if (ctx.Created)
     {
         _keyValueCount++;
     }
 }