private static LinkedNode BuildList(byte[] primeData)
        {
            LinkedNode node = new LinkedNode(0x100, 1);

            node = node.Insert(new LinkedNode(0x101, 1));
            for (int i = 0; i < primeData.Length; i++)
            {
                if (primeData[i] != 0)
                {
                    node = node.Insert(new LinkedNode(i, primeData[i]));
                }
            }
            return(node);
        }
Example #2
0
 // TODO: This would be more efficient as a member of the other class
 // ie avoid the recursion
 public LinkedNode Insert(LinkedNode other)
 {
     // 'Next' should have a lower weight
     // we should return the lower weight
     if (other.Weight <= Weight)
     {
         // insert before
         if (Next != null)
         {
             Next.Prev  = other;
             other.Next = Next;
         }
         Next       = other;
         other.Prev = this;
         return(other);
     }
     else
     {
         if (Prev == null)
         {
             // Insert after
             other.Prev = null;
             Prev       = other;
             other.Next = this;
         }
         else
         {
             Prev.Insert(other);
         }
     }
     return(this);
 }
Example #3
0
        private static LinkedNode BuildList(byte[] primeData)
        {
            LinkedNode root;

            root = new LinkedNode(256, 1);
            root = root.Insert(new LinkedNode(257, 1));

            for (int i = 0; i < primeData.Length; i++)
            {
                if (primeData[i] != 0)
                {
                    root = root.Insert(new LinkedNode(i, primeData[i]));
                }
            }
            return(root);
        }
        private static LinkedNode BuildTree(LinkedNode tail)
        {
            LinkedNode current = tail;

            while (current != null)
            {
                LinkedNode child0 = current;
                LinkedNode child1 = current.Prev;
                if (child1 == null)
                {
                    break;
                }

                LinkedNode parent = new LinkedNode(0, child0.Weight + child1.Weight)
                {
                    Child0 = child0
                };
                child0.Parent = parent;
                child1.Parent = parent;

                current.Insert(parent);
                current = current.Prev.Prev;
            }
            return(current);
        }
        private static LinkedNode BuildTree(LinkedNode tail)
        {
            LinkedNode node = tail;

            while (node != null)
            {
                LinkedNode node2 = node;
                LinkedNode prev  = node.Prev;
                if (prev == null)
                {
                    return(node);
                }
                LinkedNode other = new LinkedNode(0, node2.Weight + prev.Weight)
                {
                    Child0 = node2
                };
                node2.Parent = other;
                prev.Parent  = other;
                node.Insert(other);
                node = node.Prev.Prev;
            }
            return(node);
        }
Example #6
0
        private static LinkedNode BuildList(byte[] primeData)
        {
            LinkedNode root;

            root = new LinkedNode(256, 1);
            root = root.Insert(new LinkedNode(257, 1));

            for(int i = 0; i < primeData.Length; i++)
            {
                if (primeData[i] != 0)
                    root = root.Insert(new LinkedNode(i, primeData[i]));
            }
            return root;
        }