Skip to content

valantonini/PriorityQueue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PriorityQueue

Build Status

A C# priority queue

Items will need to implement the provided IPrioritizable interface which has 2 methods AddIndexUpdatedAction(Action indexUpdated) and RemoveIndexUpdatedAction(). Save the indexUpdated action to a field variable and call it whenever the indexed value is changed. A comparer class will also need to be provided.

e.g.

public class PrioritizableItem : IPrioritizable
{
  private Action _indexUpdated;
  private int _value;

  public int Value
  {
    get { return _value; }
    set
    {
      _indexUpdated();
      _value = value;
    }
  }

  public PrioritizableItem(int value)
  {
    _indexUpdated = () => { };
    Value = value;
  }

  public void AddIndexUpdatedAction(Action indexUpdated)
  {
    _indexUpdated = indexUpdated;
  }

  public void RemoveIndexUpdatedAction()
  {
    _indexUpdated = () => { };
  }
}

public class ComparePrioritizableItem : IComparer<PrioritizableItem>
{
  public int Compare(PrioritizableItem x, PrioritizableItem y)
  {
    if (x.Value > y.Value)
    {
      return 1;
    }
    if (x.Value < y.Value)
    {
      return -1;
    }
    return 0;
  }
}

About

A C# priority queue

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages