Exemple #1
0
            public bool MoveNext()
            {
                if (IsBeforeList)
                {
                    levelNode    = List.Children.First;
                    current      = (levelNode != null) ? levelNode.Value : null;
                    IsBeforeList = false;
                    //StepInThisPass = true;
                    return(levelNode != null);
                }
                else if (levelNode == null)
                {
                    return(false);
                }

                if (sub == null)
                {
                    sub = new Enumerator(levelNode.Value);
                }
                if (sub.MoveNext())
                {
                    current = (MBlock)sub.Current;
                    return(true);
                }
                sub = null;

                levelNode = levelNode.Next;
                current   = (levelNode != null) ? levelNode.Value : null;
                return(levelNode != null);
            }
Exemple #2
0
        private MBlock InsertCompleteBlock(object asset, uint start, uint end)
        {
            MBlock      result;
            MBlock      query;
            FileAddress blockAddr = new FileAddress(start, end);

            //create new block
            result = new MBlock(new FileAddress(start, end), asset);

            //check if block falls within the bounds of an existing block
            query = Children.SingleOrDefault(x => x.Address.Start <= start && end <= x.Address.End);

            //If block doesn't fall within the bounds of another block
            if (query == null)
            {
                result.Parent = Self;
                //if no nodes, add to list
                if (Children.Count == 0)
                {
                    result.Self = Children.AddFirst(result);
                    return(result);
                }
                else // find a block to link to
                {
                    LinkedListNode <MBlock> curr;
                    LinkedListNode <MBlock> prev = null;
                    curr = Children.First;

                    while (curr != null)
                    {
                        if (start < curr.Value.Address.Start)
                        {
                            result.Self = Children.AddBefore(curr, result);
                            return(result);
                        }
                        prev = curr;
                        curr = curr.Next;
                    }
                    result.Self = Children.AddAfter(prev, result);
                    return(result);
                }
            }
            else //block is within another block's bounds
            {
                //if same reference
                if (query.Address == blockAddr)
                {
                    return(query);
                }
                else if (query.IsBounded)
                {
                    return(query.InsertCompleteBlock(asset, start, end));
                }
                else if (query.EndSet == false)
                {
                    query.Address = new FileAddress(query.Address.Start, start);
                    result.Parent = Self;
                    var node = Children.Find(query);
                    result.Self = Children.AddAfter(node, result);
                    return(result);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
        }
Exemple #3
0
 public Enumerator(MBlock list)
 {
     List = list;
     Reset();
 }