Exemple #1
0
        public Tree LoadRecords()
        {
            Tree tree = new Tree();


            using (BinaryReader reader = new BinaryReader(File.Open(BasePath, FileMode.Open)))
            {
                reader.BaseStream.Position = 0;
                if (reader.ReadString() == NameBase)
                {
                    reader.BaseStream.Position = 25;

                    while (reader.BaseStream.Position != reader.BaseStream.Length)
                    {
                        char[]          Name       = reader.ReadChars(20);
                        ulong           MinOffset  = reader.ReadUInt64();
                        ulong           MaxOffset  = reader.ReadUInt64();
                        uint            DataLength = reader.ReadUInt32();
                        byte[]          Data       = reader.ReadBytes(8);
                        byte[]          Hash       = reader.ReadBytes(32);
                        ThreadSignature sig        = new ThreadSignature(Name, MinOffset, MaxOffset, DataLength, Data, Hash);
                        tree.Add(sig);
                    }
                }
                else
                {
                    return(null);
                }
            }
            return(tree);
        }
Exemple #2
0
 public Node(ThreadSignature signature, bool End)
 {
     if (ListSignatures == null)
     {
         ListSignatures = new List <ThreadSignature>();
         ListSignatures.Add(signature);
     }
     else
     {
         ListSignatures.Add(signature);
     }
 }
Exemple #3
0
        public void Add(ThreadSignature signature)
        {
            Node current = this;
            int  comparer;

            for (int i = 0; i < signature.Signature.Data.Length; i++)
            {
                comparer = signature.Signature.Data[i].CompareTo(current.Data);
                if (comparer == 0)
                {
                    if (i == signature.Signature.Data.Length - 1)
                    {
                        current.End   = true;
                        current.Equal = new Node(signature, current.End);
                        return;
                    }

                    if (current.Equal == null)
                    {
                        current.Equal = new Node(signature, signature.Signature.Data[i + 1]);
                    }
                    current = current.Equal;
                }
                else
                {
                    if (comparer < 0)
                    {
                        if (current.Left == null)
                        {
                            current.Left = new Node(signature, signature.Signature.Data[i]);
                        }
                        current = current.Left;
                        i--;
                    }
                    else
                    {
                        if (current.Right == null)
                        {
                            current.Right = new Node(signature, signature.Signature.Data[i]);
                        }
                        current = current.Right;
                        i--;
                    }

                    if (i == signature.Signature.Data.Length - 1)
                    {
                        current.End = true;
                        return;
                    }
                }
            }
        }
Exemple #4
0
 public void Add(ThreadSignature signature)
 {
     if (Root == null)
     {
         Root = new Node(signature, signature.Signature.Data[0]);
         Root.Add(signature);
     }
     else
     {
         Root.Add(signature);
     }
     Count++;
 }
Exemple #5
0
        public bool AddBase(ThreadSignature sign)
        {
            ulong count;

            using (BinaryReader reader = new BinaryReader(File.Open(BasePath, FileMode.Open)))
            {
                reader.BaseStream.Position = 0;
                if (reader.ReadString() == NameBase)
                {
                    reader.BaseStream.Position = 17;
                    count = reader.ReadUInt64();
                    count++;
                }
                else
                {
                    return(false);
                }
            }

            using (BinaryWriter writer = new BinaryWriter(File.Open(BasePath, FileMode.Open)))
            {
                writer.Seek(17, 0);
                writer.Write(count);
            }


            using (BinaryWriter writer = new BinaryWriter(File.Open(BasePath, FileMode.Append)))
            {
                writer.Write(sign.ThreadName);
                writer.Write(sign.SignatureFirstByteMinOffset);
                writer.Write(sign.SignatureFirstByteMaxOffset);
                writer.Write(sign.Signature.DataLength);
                writer.Write(sign.Signature.Data);
                writer.Write(sign.Signature.Hash);
                return(true);
            }
        }
Exemple #6
0
 public Node(ThreadSignature signature, byte data)
 {
     Data = data;
 }