Example #1
0
 public void Reset(int value, int weight)
 {
     this.value  = value;
     this.weight = weight;
     next        = null;
     previous    = null;
     parent      = null;
     child       = null;
 }
Example #2
0
 public void InsertAfter(HuffmanItem item, HuffmanItem newItem)
 {
     newItem.Next     = item.Next;
     newItem.Previous = item;
     if (item.Next != null)
     {
         item.Next.Previous = newItem;
     }
     else if (item == tail)
     {
         tail = newItem;
     }
     item.Next = newItem;
 }
Example #3
0
 public void InsertBefore(HuffmanItem item, HuffmanItem newItem)
 {
     newItem.Next     = item;
     newItem.Previous = item.Previous;
     if (item.Previous != null)
     {
         item.Previous.Next = newItem;
     }
     else if (item == head)
     {
         head = newItem;
     }
     item.Previous = newItem;
 }
Example #4
0
 public void Remove(HuffmanItem item)
 {
     if (item == tail)
     {
         tail = item.Previous;
     }
     if (item == head)
     {
         head = item.Next;
     }
     if (item.Previous != null)
     {
         item.Previous.Next = item.Next;
     }
     if (item.Next != null)
     {
         item.Next.Previous = item.Previous;
     }
     item.Next = item.Previous = null;
 }
Example #5
0
        HuffmanItem GetNewItem(int value, int weight)
        {
            HuffmanItem item;

            if (usedItemCount < itemCount)
            {
                item = itemArray[usedItemCount++];
            }
            else if (itemCount < itemArray.Length)
            {
                item = itemArray[itemCount++] = new HuffmanItem();
                usedItemCount++;
            }
            else
            {
                throw new Exception("No more items");
            }

            item.Reset(value, weight);

            return(item);
        }
Example #6
0
            public void InsertWeighted(HuffmanItem item)
            {
                HuffmanItem current;

                // If tail is null then head is null too
                if (tail == null)
                {
                    tail = head = item;
                    return;
                }

                current = tail;

                while (current != null && current.Weight < item.Weight)
                {
                    current = current.Previous;
                }

                if (current != null)
                {
                    item.Previous         = current;
                    item.Next             = current.Next;
                    current.Next.Previous = item;
                    current.Next          = item;

                    if (item.Next == null)
                    {
                        tail = item;
                    }
                }
                else
                {
                    item.Previous    = null;
                    item.Next        = head;
                    current.Previous = item;
                }
            }
Example #7
0
 public void Clear()
 {
     head = null;
     tail = null;
 }
Example #8
0
 void Reset()
 {
     root = null;
     itemList.Clear();
     usedItemCount = 0;
 }
Example #9
0
 public void Reset(int value, int weight)
 {
     this.value = value;
     this.weight = weight;
     next = null;
     previous = null;
     parent = null;
     child = null;
 }
Example #10
0
            public void InsertWeighted(HuffmanItem item)
            {
                HuffmanItem current;

                // If tail is null then head is null too
                if (tail == null)
                {
                    tail = head = item;
                    return;
                }

                current = tail;

                while (current != null && current.Weight < item.Weight)
                    current = current.Previous;

                if (current != null)
                {
                    item.Previous = current;
                    item.Next = current.Next;
                    current.Next.Previous = item;
                    current.Next = item;

                    if (item.Next == null)
                        tail = item;
                }
                else
                {
                    item.Previous = null;
                    item.Next = head;
                    current.Previous = item;
                }
            }
Example #11
0
 public void Remove(HuffmanItem item)
 {
     if (item == tail)
         tail = item.Previous;
     if (item == head)
         head = item.Next;
     if (item.Previous != null)
         item.Previous.Next = item.Next;
     if (item.Next != null)
         item.Next.Previous = item.Previous;
     item.Next = item.Previous = null;
 }
Example #12
0
 public void InsertBefore(HuffmanItem item, HuffmanItem newItem)
 {
     newItem.Next = item;
     newItem.Previous = item.Previous;
     if (item.Previous != null)
         item.Previous.Next = newItem;
     else if (item == head)
         head = newItem;
     item.Previous = newItem;
 }
Example #13
0
 public void InsertAfter(HuffmanItem item, HuffmanItem newItem)
 {
     newItem.Next = item.Next;
     newItem.Previous = item;
     if (item.Next != null)
         item.Next.Previous = newItem;
     else if (item == tail)
         tail = newItem;
     item.Next = newItem;
 }
Example #14
0
 public void Clear()
 {
     head = null;
     tail = null;
 }
Example #15
0
 void Reset()
 {
     root = null;
     itemList.Clear();
     usedItemCount = 0;
 }
Example #16
0
        HuffmanItem GetNewItem(int value, int weight)
        {
            HuffmanItem item;

            if (usedItemCount < itemCount)
                item = itemArray[usedItemCount++];
            else if (itemCount < itemArray.Length)
            {
                item = itemArray[itemCount++] = new HuffmanItem();
                usedItemCount++;
            }
            else
                throw new Exception("No more items");

            item.Reset(value, weight);

            return item;
        }