Skip to content

Introduces interfaces and basic classes for topoligic comparable types. Topologic comparable types can have multiple sorted enumerations.

License

Notifications You must be signed in to change notification settings

phirSOFT/phirSOFT.TopologicalComparison

Repository files navigation

phirSOFT.TopologicalComparison

A library for weaker orderings.

Build status

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:

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);
  }

}

About

Introduces interfaces and basic classes for topoligic comparable types. Topologic comparable types can have multiple sorted enumerations.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages