예제 #1
0
        private void JoinNodesAtIndex(int index)
        {
            ExtentListNode node     = list.ValueAt(index);
            ExtentListNode?prevNode = null;
            ExtentListNode?nextNode = null;

            if (index - 1 >= 0)
            {
                prevNode = list.ValueAt(index - 1);
            }
            if (index + 1 < list.Count)
            {
                nextNode = list.ValueAt(index + 1);
            }

            //if any node is length 0, remove it
            if (prevNode != null && prevNode.Value.Length == 0)
            {
                Remove(prevNode.Value);
                return;
            }
            if (nextNode != null && nextNode.Value.Length == 0)
            {
                Remove(nextNode.Value);
                return;
            }

            //see if we can join all three nodes together
            if (prevNode != null && nextNode != null &&
                node.Member == prevNode.Value.Member && node.Member == nextNode.Value.Member)
            {
                int totalSize = prevNode.Value.Length + node.Length + nextNode.Value.Length;
                //if any node is a file-backed node
                list.RemoveRangeAt(index - 1, 3);
                Add(prevNode.Value.Start, totalSize, node.Member);
                return;
            }

            //see if we can join previous node to middle node
            if (prevNode != null && node.Member == prevNode.Value.Member)
            {
                int totalSize = prevNode.Value.Length + node.Length;
                list.RemoveRangeAt(index - 1, 2);
                Add(prevNode.Value.Start, totalSize, prevNode.Value.Member);
                return;
            }

            //see if we can join next node to middle node
            if (nextNode != null && node.Member == nextNode.Value.Member)
            {
                int totalSize = node.Length + nextNode.Value.Length;
                list.RemoveRangeAt(index, 2);
                Add(node.Start, totalSize, node.Member);
                return;
            }
        }
예제 #2
0
 private void Remove(ExtentListNode node)
 {
     list.Remove(node.Start);
 }