Example #1
0
        private void RebuildTree()
        {
            var Nodes = new List <DICTEntry>();

            // Adapted from SPICA's code

            if (Entries.Count > 0)
            {
                Nodes.Add(new DICTEntry {
                    ReferenceBit = uint.MaxValue
                });
            }
            else
            {
                Nodes.Add(new DICTEntry());
            }

            int MaxLength = 0;

            foreach (var Value in Entries)
            {
                if (MaxLength < Value.Name.Length)
                {
                    MaxLength = Value.Name.Length;
                }
            }

            foreach (var Value in Entries)
            {
                var Node = new DICTEntry
                {
                    Name = Value.Name,
                    //EntryObject = Value
                };

                PatriciaTree.Insert(Nodes, Node, MaxLength);
            }


            // TODO: Bit of a hacky implementation here, but this "should work"
            // and at least I thankfully get this functionality, courtesy of SPICA

            // Nodes index 0 will be the root node, the others should line up with
            // the subsequent entries...
            RootEntry = Nodes[0];
            for (var entryIndex = 0; entryIndex < Entries.Count; entryIndex++)
            {
                var node  = Nodes[entryIndex + 1];  // +1 because index zero is the root
                var entry = Entries[entryIndex];
                if (node.Name != entry.Name)
                {
                    throw new InvalidOperationException("RebuildTree: Name mismatch in node");
                }

                entry.ReferenceBit   = node.ReferenceBit;
                entry.LeftNodeIndex  = node.LeftNodeIndex;
                entry.RightNodeIndex = node.RightNodeIndex;
            }
        }
Example #2
0
        private void RebuildTree()
        {
            Nodes.Clear();

            if (Names.Count > 0)
            {
                Nodes.Add(new H3DPatriciaTreeNode()
                {
                    ReferenceBit = uint.MaxValue
                });
            }
            else
            {
                Nodes.Add(new H3DPatriciaTreeNode());
            }

            int MaxLength = 0;

            foreach (string Name in Names)
            {
                if (MaxLength < Name.Length)
                {
                    MaxLength = Name.Length;
                }
            }

            foreach (string Name in Names)
            {
                PatriciaTree.Insert(Nodes, new H3DPatriciaTreeNode()
                {
                    Name = Name
                }, MaxLength);
            }

            TreeNeedsRebuild = false;
        }