Пример #1
0
        private InternalTrieNode TransformExternal(ExternalTrieNode node)
        {
            var inter = new InternalTrieNode {
                Parent = node.Parent
            };

            if (node.InternalParent?.LeftChild == node)
            {
                node.InternalParent.LeftChild = inter;
            }
            else
            {
                if (node.InternalParent != null)
                {
                    node.InternalParent.RightChild = inter;
                }
            }

            if (node == Root)
            {
                Root = inter;
            }

            inter.LeftChild  = new ExternalTrieNode();
            inter.RightChild = new ExternalTrieNode();
            return(inter);
        }
Пример #2
0
        private ExternalTrieNode TransformInternal(InternalTrieNode internalTrieNode)
        {
            var ext = new ExternalTrieNode();

            if (internalTrieNode == Root)
            {
                Root = ext;
            }
            else
            {
                if (internalTrieNode.InternalParent.LeftChild == internalTrieNode)
                {
                    internalTrieNode.InternalParent.LeftChild = ext;
                }
                else
                {
                    internalTrieNode.InternalParent.RightChild = ext;
                }
                ext.Parent = internalTrieNode.Parent;
            }

            return(ext);
        }
Пример #3
0
        public void LoadTreeData()
        {
            var list = new List <string>();

            try
            {
                using (StreamReader sr = new StreamReader(_files.FileTreeData))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        list.Add(line);
                    }
                }
            }
            catch (Exception)
            {
                return;
            }

            if (list.Count == 0) //nic v subore nie je
            {
                return;
            }
            Root                 = null;
            MaxRecords           = Int32.Parse(list[0]);
            MaxRecordsInOverflow = Int32.Parse(list[1]);
            _workingBlock1       = new Block <T>(MaxRecords);
            _overflowBlock       = new Block <T>(MaxRecordsInOverflow);
            if (list[2] != "")
            {
                _freeBlocks.StringToList(';', list[2]);
            }
            if (list[3] != "")
            {
                _freeBlocksOverflow.StringToList(';', list[3]);
            }

            var stack = new Stack <InternalTrieNode>();

            for (int i = 4; i < list.Count; i++)
            {
                if (list[i][0] == 'I')
                {
                    var iNode = new InternalTrieNode();
                    if (Root == null)
                    {
                        Root = iNode;
                    }
                    else
                    {
                        CorrectInsertToTree(stack, iNode);
                    }
                    stack.Push(iNode);
                }
                else
                {
                    var eNode = new ExternalTrieNode();
                    eNode.LoadDataFromString(list[i]);
                    if (Root == null)
                    {
                        Root = eNode;
                    }
                    else
                    {
                        CorrectInsertToTree(stack, eNode);
                    }
                }
            }
        }