Skip to content

Commit

Permalink
Create README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Pretasoc authored Jan 23, 2018
1 parent d0a904b commit 39bbae0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# phirSOFT.TopologicalComparison

A library for weaker orderings.

[![Build status](https://ci.appveyor.com/api/projects/status/k3w3e4rbo5ascn78/branch/master?svg=true)](https://ci.appveyor.com/project/phirSOFT/phirsoft-topologicalcomparison/branch/master)

## Introduction

Sometimes we cant compare all instances of a type with each other. In this case the usual sorting algoritms can't sort a collection of such instances.
The Topological comparison aims at this problem by providing an algorithm that can sort such instances topologically. That means there might be more than one correct ordering. To give an example.
We can etablish a partial ordetring on the `ISet<T>` type by ordering differenct sets, if they are subsets of each other. This could be implemented as the following:

``` c#
public class TopologicalSetComparer<T> : ITopologicalComparer<ISet<T>>
{
public int Compare(ISet<T> x, ISet<T> y)
{
var xLessy = x.IsSubsetOf(y);
var yLessx = y.IsSubsetOf(x);

if(xLessy && yLessx)
return 0;
return xLessy ? -1 : 1;
}

public bool CanCompare(ISet<T> x, ISet<T> y)
{
return x.IsSubsetOf(y) || y.IsSubsetOf(x);
}

}
```

0 comments on commit 39bbae0

Please sign in to comment.