예제 #1
0
        private SortTreeNode Add(string strText, int nCount, object Tag)
        {
            SortTreeNode node = Add(ref strText);

            node.Count = nCount;
            node.Tag   = Tag;
            return(node);
        }
예제 #2
0
        public SortTreeNode Add(ref string str)
        {
            SortTreeNode node;

            if (Root == null)
            {
                Root = new SortTreeNode();
                node = Root;
            }
            else
            {
                node = Root;
                while (true)
                {
                    if (node.Text == str)
                    {
                        node.Count++;
                        return(node);
                    }
                    if (node.Text.CompareTo(str) > 0)
                    {                           // add the node at the small branch
                        if (node.Small == null)
                        {
                            node.Small        = new SortTreeNode();
                            node.Small.Parent = node;
                            node = node.Small;
                            break;
                        }
                        node = node.Small;
                    }
                    else
                    {                           // add the node at the great branch
                        if (node.Great == null)
                        {
                            node.Great        = new SortTreeNode();
                            node.Great.Parent = node;
                            node = node.Great;
                            break;
                        }
                        node = node.Great;
                    }
                }
            }
            node.Text = str;
            node.ID   = this.Count++;
            node.Count++;
            Modified = true;

            return(node);
        }
예제 #3
0
 public SortTreeNode Add(ref string str)
 {
     SortTreeNode root;
     if (this.Root == null)
     {
         this.Root = new SortTreeNode();
         root = this.Root;
     }
     else
     {
         root = this.Root;
         while (true)
         {
             if (root.Text == str)
             {
                 root.Count++;
                 return root;
             }
             if (root.Text.CompareTo((string) str) > 0)
             {
                 if (root.Small == null)
                 {
                     root.Small = new SortTreeNode();
                     root.Small.Parent = root;
                     root = root.Small;
                     break;
                 }
                 root = root.Small;
             }
             else
             {
                 if (root.Great == null)
                 {
                     root.Great = new SortTreeNode();
                     root.Great.Parent = root;
                     root = root.Great;
                     break;
                 }
                 root = root.Great;
             }
         }
     }
     root.Text = str;
     root.ID = this.Count++;
     root.Count++;
     this.Modified = true;
     return root;
 }
예제 #4
0
        bool OutNode(SortTreeNode node, StreamWriter writer, BitArray bits, ref int nCount)
        {
            if (node == null || bits.Get(node.ID) == true)
            {
                return(false);
            }
            string str = node.Text + '\t' + node.Count.ToString() + '\t';

            if (node.Tag != null)
            {
                str += node.Tag.ToString().Replace("\r\n", "\r\n\t\t");
            }
            writer.WriteLine(str.TrimEnd('\t'));

            bits.Set(node.ID, true);
            nCount--;

            return(true);
        }
예제 #5
0
        public void Save(string fileName, System.Text.Encoding code)
        {
            FileStream   stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
            StreamWriter writer = new StreamWriter(stream, code);

            BitArray     bitArray = new BitArray(this.Count, false);
            SortTreeNode node     = this.Root;
            int          nCount   = this.Count;

            while (nCount > 0)
            {
                if (node.Small != null && bitArray.Get(node.Small.ID) == false)
                {
                    node = node.Small;
                }
                else if (bitArray.Get(node.ID) == false)
                {
                    OutNode(node, writer, bitArray, ref nCount);
                }
                else if (node.Great != null && bitArray.Get(node.Great.ID) == false)
                {
                    node = node.Great;
                }
                else
                {
                    if (bitArray.Get(node.ID) == false)
                    {
                        OutNode(node, writer, bitArray, ref nCount);
                    }
                    node = node.Parent;
                }
            }
            writer.Close();
            stream.Close();

            Modified = false;
        }
예제 #6
0
        public void Open(string fileName, Encoding code, ListView list)
        {
            string str;
            FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            StreamReader reader = new StreamReader(stream, code);
            SortTreeNode node = null;
            int num = 0;
            ArrayList list2 = new ArrayList();
            while ((str = reader.ReadLine()) != null)
            {
                string[] strArray = str.Split(new char[] { '\t' });
                for (int i = 0; i < strArray.Length; i++)
                {
                    string s = strArray[i];
                    switch (i)
                    {
                        case 0:
                            if (s != "")
                            {
                                node = new SortTreeNode {
                                    Text = s
                                };
                                list2.Add(node);
                                num = 0;
                            }
                            break;

                        case 1:
                            try
                            {
                                if (s != "")
                                {
                                    node.Count = int.Parse(s);
                                }
                            }
                            catch (Exception exception)
                            {
                                MessageBox.Show(exception.Message);
                            }
                            break;

                        default:
                            if (num++ > 0)
                            {
                                node.Tag = node.Tag + "\r\n";
                            }
                            node.Tag = node.Tag + s;
                            break;
                    }
                }
            }
            reader.Close();
            stream.Close();
            Random random = new Random();
            while (list2.Count > 0)
            {
                int index = random.Next(list2.Count);
                node = (SortTreeNode) list2[index];
                list2.RemoveAt(index);
                node = this.Add(node.Text, node.Count, node.Tag);
                if (list != null)
                {
                    int num4 = node.ID + 1;
                    ListViewItem item = list.Items.Add(num4.ToString());
                    item.SubItems.Add(node.Text);
                    item.SubItems.Add(node.Count.ToString());
                    item.Tag = node;
                }
            }
        }
예제 #7
0
 public void Clear()
 {
     this.Root = null;
     this.Count = 0;
     this.Modified = false;
 }
예제 #8
0
 private bool OutNode(SortTreeNode node, StreamWriter writer, BitArray bits, ref int nCount)
 {
     if ((node == null) || bits.Get(node.ID))
     {
         return false;
     }
     string str = string.Concat(new object[] { node.Text, '\t', node.Count.ToString(), '\t' });
     if (node.Tag != null)
     {
         str = str + node.Tag.ToString().Replace("\r\n", "\r\n\t\t");
     }
     writer.WriteLine(str.TrimEnd(new char[] { '\t' }));
     bits.Set(node.ID, true);
     nCount--;
     return true;
 }
예제 #9
0
 public void Clear()
 {
     Root     = null;
     Count    = 0;
     Modified = false;
 }
예제 #10
0
        public void Open(string fileName, System.Text.Encoding code, ListView list)
        {
            FileStream   stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            StreamReader reader = new StreamReader(stream, code);

            SortTreeNode node      = null;
            int          nTagCount = 0;
            ArrayList    array     = new ArrayList();
            string       str;

            while ((str = reader.ReadLine()) != null)
            {
                string[] strCols = str.Split('\t');
                for (int n = 0; n < strCols.Length; n++)
                {
                    string strCol = strCols[n];
                    if (n == 0)
                    {
                        if (strCol != "")
                        {
                            node      = new SortTreeNode();
                            node.Text = strCol;
                            array.Add(node);
                            nTagCount = 0;
                        }
                    }
                    else if (n == 1)
                    {
                        try
                        {
                            if (strCol != "")
                            {
                                node.Count = int.Parse(strCol);
                            }
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                        }
                    }
                    else
                    {
                        if (nTagCount++ > 0)
                        {
                            node.Tag += "\r\n";
                        }
                        node.Tag += strCol;
                    }
                }
            }
            reader.Close();
            stream.Close();

            Random rand = new Random();

            while (array.Count > 0)
            {
                int nIndex = rand.Next(array.Count);
                node = (SortTreeNode)array[nIndex];
                array.RemoveAt(nIndex);
                node = this.Add(node.Text, node.Count, node.Tag);
                if (list != null)
                {
                    ListViewItem item = list.Items.Add((node.ID + 1).ToString());
                    item.SubItems.Add(node.Text);
                    item.SubItems.Add(node.Count.ToString());
                    item.Tag = node;
                }
            }
        }