Esempio n. 1
0
        internal long GenerateHashOffset(uint xBlock, TreeLevel xTree)
        {
            if (xBlock >= 0x4AF768)
            {
                return(Constants.STFSEnd);
            }
            try
            {
                uint result  = GenerateHashBlock(xBlock, xTree);
                long xReturn = BlockToOffset(result);
                switch (xTree)
                {
                case TreeLevel.L0:
                    xReturn += (0x18 * (xBlock % BlockLevel[0]));
                    break;

                case TreeLevel.L1:
                    xReturn += (0x18 * ((xBlock / BlockLevel[0]) % BlockLevel[0]));
                    break;

                case TreeLevel.L2:
                    xReturn += (0x18 * ((xBlock / BlockLevel[1]) % BlockLevel[0]));
                    break;
                }
                return(xReturn);
            }
            catch { throw STFSExcepts.General; }
        }
Esempio n. 2
0
        public bool IsEvenOddTree(TreeNode root)
        {
            if (root == null)
            {
                return(false);
            }

            Queue <TreeLevel> queue             = new Queue <TreeLevel>();
            TreeLevel         rootTreeLevel     = new TreeLevel(root, 0);
            TreeLevel         previousTreeLevel = rootTreeLevel;

            queue.Enqueue(new TreeLevel(root, 0));
            while (queue.Count != 0)
            {
                TreeLevel treeLevel = queue.Dequeue();
                if (treeLevel.Node.left != null)
                {
                    queue.Enqueue(new TreeLevel(treeLevel.Node.left, treeLevel.Level + 1));
                }
                if (treeLevel.Node.right != null)
                {
                    queue.Enqueue(new TreeLevel(treeLevel.Node.right, treeLevel.Level + 1));
                }
                //Even odd value check
                if (treeLevel.Level % 2 == 0 && treeLevel.Node.val % 2 == 0)
                {
                    return(false);
                }
                else if (treeLevel.Level % 2 == 1 && treeLevel.Node.val % 2 == 1)
                {
                    return(false);
                }


                //Check for increasing or decreasing
                if (treeLevel.Level > 0 && treeLevel.Level == previousTreeLevel.Level)
                {
                    //even Asceniding
                    if (treeLevel.Level % 2 == 0 && treeLevel.Node.val <= previousTreeLevel.Node.val)
                    {
                        return(false);
                    }
                    else if (treeLevel.Level % 2 == 1 && treeLevel.Node.val >= previousTreeLevel.Node.val) // Odd descending
                    {
                        return(false);
                    }
                }

                previousTreeLevel = treeLevel;
            }

            return(true);
        }
Esempio n. 3
0
        internal uint GenerateHashBlock(uint xBlock, TreeLevel xTree)
        {
            if (xBlock >= 0x4AF768)
            {
                return(Constants.STFSEnd);
            }
            try
            {
                switch (xTree)
                {
                case TreeLevel.L0:
                {
                    // Get Base Level 0 Table
                    uint num = (xBlock / BlockLevel[0]) * SpaceBetween[0];
                    // Adjusts the result for Level 1 table count
                    if (xBlock >= BlockLevel[0])
                    {
                        num += (((xBlock / BlockLevel[1]) + 1) << Shift);
                        // Adjusts for the Level 2 table
                        if (xBlock >= BlockLevel[1])
                        {
                            num += (uint)(1 << Shift);
                        }
                    }
                    return(num);
                }

                case TreeLevel.L1:
                {
                    // Grab the number of Table 1 blocks
                    if (xBlock < BlockLevel[1])
                    {
                        return(xSpaceBetween[0]);
                    }
                    else
                    {
                        return((uint)((SpaceBetween[1] * (xBlock / BlockLevel[1])) + (1 << Shift)));
                    }
                }

                // Only one Level 2 table
                case TreeLevel.L2:
                    return(SpaceBetween[1]);

                default:
                    return(Constants.STFSEnd);
                }
            }
            catch { throw STFSExcepts.General; }
        }
Esempio n. 4
0
        public void Apply()
        {
            if (string.IsNullOrEmpty(name.Text))
            {
                Dialog.ShowMsg("内容不能为空");
                return;
            }

            TreeLevel lv = TreeLevel.File;

            switch (levels.SelectedIndex)
            {
            case 0: lv = TreeLevel.File; break;

            case 1: lv = TreeLevel.Database; break;

            case 2: lv = TreeLevel.Table; break;
            }

            KeyValue <string, string> key = dbtype.SelectedItem as KeyValue <string, string>;

            CurNode = new TreeList
            {
                CONN_STRING = connstr.Text,
                LEVEL       = (!IsEdit && vm.SelectedNode == null) ? TreeLevel.File : lv,
                NODE_NAME   = name.Text,
                SqlType     = string.IsNullOrEmpty(connstr.Text) ? null : key.Key
            };

            if (vm.SelectedNode != null)
            {
                if (!IsEdit)
                {
                    Insert(vm.TreeSource, vm.SelectedNode, CurNode);
                }
                else
                {
                    Update(vm.TreeSource, vm.SelectedNode, CurNode);
                }
            }
            else
            {
                vm.TreeSource.Add(CurNode);
            }
        }
        public IList <IList <int> > LevelOrder(TreeNode root)
        {
            IList <IList <int> > result = new List <IList <int> >();

            if (root == null)
            {
                return(result);
            }
            Queue <TreeLevel> queue = new Queue <TreeLevel>();

            List <int> currentLevelList = new List <int>();
            int        currentLevel     = 0;

            queue.Enqueue(new TreeLevel(root, currentLevel));
            while (queue.Count > 0)
            {
                TreeLevel nodeWithLevel = queue.Dequeue();
                if (nodeWithLevel.Level == currentLevel)
                {
                    currentLevelList.Add(nodeWithLevel.Node.val);
                }
                else
                {
                    result.Add(currentLevelList);
                    currentLevelList = new List <int>();
                    currentLevelList.Add(nodeWithLevel.Node.val);
                    currentLevel = nodeWithLevel.Level;
                }
                if (nodeWithLevel.Node.left != null)
                {
                    queue.Enqueue(new TreeLevel(nodeWithLevel.Node.left, nodeWithLevel.Level + 1));
                }
                if (nodeWithLevel.Node.right != null)
                {
                    queue.Enqueue(new TreeLevel(nodeWithLevel.Node.right, nodeWithLevel.Level + 1));
                }
            }
            result.Add(currentLevelList);
            return(result);
        }
Esempio n. 6
0
 internal long GenerateBaseOffset(uint xBlock, TreeLevel xTree)
 {
     try { return(BlockToOffset(GenerateHashBlock(xBlock, xTree))); }
     catch { throw STFSExcepts.General; }
 }
 BlockRecord GetRecord(uint xBlock, TreeLevel xLevel)
 {
     if (xLevel == TreeLevel.LT)
         return xSTFSStruct.TopRecord;
     BlockRecord current = xSTFSStruct.TopRecord;
     bool canswitch = (xSTFSStruct.ThisType == STFSType.Type1);
     if (xSTFSStruct.xBlockCount > Constants.BlockLevel[1])
     {
         // Grab base position
         xIO.Position = (xSTFSStruct.GenerateHashOffset(xBlock, TreeLevel.L2) + 0x14);
         if (canswitch)
             xIO.Position += (current.Index << 0xC);
         current = new BlockRecord(xIO.ReadUInt32()); // Read new flag
         if (xLevel == TreeLevel.L2)
         {
             // return if needed
             current.ThisBlock = xBlock;
             current.ThisLevel = TreeLevel.L2;
             return current;
         }
     }
     else if (xLevel == TreeLevel.L2)
         return xSTFSStruct.TopRecord;
     // Follows same procedure
     if (xSTFSStruct.xBlockCount > Constants.BlockLevel[0])
     {
         xIO.Position = (xSTFSStruct.GenerateHashOffset(xBlock, TreeLevel.L1)) + 0x14;
         if (canswitch)
             xIO.Position += (current.Index << 0xC);
         current = new BlockRecord(xIO.ReadUInt32());
         if (xLevel == TreeLevel.L1)
         {
             current.ThisBlock = xBlock;
             current.ThisLevel = TreeLevel.L1;
             return current;
         }
     }
     else if (xLevel == TreeLevel.L1)
         return xSTFSStruct.TopRecord;
     xIO.Position = (xSTFSStruct.GenerateHashOffset(xBlock, TreeLevel.L0)) + 0x14;
     if (canswitch)
         xIO.Position += (current.Index << 0xC);
     current = new BlockRecord(xIO.ReadUInt32());
     current.ThisBlock = xBlock;
     current.ThisLevel = TreeLevel.L0;
     return current;
 }
 /// <summary>
 /// Generates a hash offset via block
 /// </summary>
 /// <param name="xBlock"></param>
 /// <param name="xTree"></param>
 /// <returns></returns>
 internal long GenerateHashOffset(uint xBlock, TreeLevel xTree)
 {
     long xReturn = xSTFSStruct.GenerateHashOffset(xBlock, xTree);
     if (xSTFSStruct.ThisType == STFSType.Type1) // Grabs the one up level block record for shifting
         xReturn += (GetRecord(xBlock, (TreeLevel)((byte)xTree + 1)).Index << 0xC);
     return xReturn;
 }
        internal long GenerateHashOffset(uint xBlock, TreeLevel xTree)
        {
            if (xBlock >= 0x4AF768)
                return Constants.STFSEnd;
            try
            {
                uint result = GenerateHashBlock(xBlock, xTree);
                long xReturn = BlockToOffset(result);
                switch (xTree)
                {
                    case TreeLevel.L0:
                        xReturn += (0x18 * (xBlock % BlockLevel[0]));
                        break;

                    case TreeLevel.L1:
                        xReturn += (0x18 * ((xBlock / BlockLevel[0]) % BlockLevel[0]));
                        break;

                    case TreeLevel.L2:
                        xReturn += (0x18 * ((xBlock / BlockLevel[1]) % BlockLevel[0]));
                        break;
                }
                return xReturn;
            }
            catch { throw STFSExcepts.General; }
        }
        internal uint GenerateHashBlock(uint xBlock, TreeLevel xTree)
        {
            if (xBlock >= 0x4AF768)
                return Constants.STFSEnd;
            try
            {
                switch (xTree)
                {
                    case TreeLevel.L0:
                        {
                            // Get Base Level 0 Table
                            uint num = (xBlock / BlockLevel[0]) * SpaceBetween[0];
                            // Adjusts the result for Level 1 table count
                            if (xBlock >= BlockLevel[0])
                            {
                                num += (((xBlock / BlockLevel[1]) + 1) << Shift);
                                // Adjusts for the Level 2 table
                                if (xBlock >= BlockLevel[1])
                                    num += (uint)(1 << Shift);
                            }
                            return num;
                        }
                    case TreeLevel.L1:
                        {
                            // Grab the number of Table 1 blocks
                            if (xBlock < BlockLevel[1])
                                return xSpaceBetween[0];
                            else
                                return (uint)((SpaceBetween[1] * (xBlock / BlockLevel[1])) + (1 << Shift));
                        }

                    // Only one Level 2 table
                    case TreeLevel.L2:
                        return SpaceBetween[1];

                    default:
                        return Constants.STFSEnd;
                }
            }
            catch { throw STFSExcepts.General; }
        }
 internal long GenerateBaseOffset(uint xBlock, TreeLevel xTree)
 {
     try { return BlockToOffset(GenerateHashBlock(xBlock, xTree)); }
     catch { throw STFSExcepts.General; }
 }
 private void setLevelOfRow(TreeLevel i_level, int i_grid_row_index)
 {
     m_fg.Rows[i_grid_row_index].IsNode = true;
     m_fg.Rows[i_grid_row_index].Node.Level = (int) i_level;
 }