/*======================================================================== Copyright (C) 2006 by Geir-Tore Lindsve, Torbjørn Meistad and Yngve Raudberget, hereby refered to as "the authors". Based on the CLab source code developed by Rune Møller Jensen. All rights reserved Permission is hereby granted, without written agreement and without license or royalty fees, to use, reproduce, prepare derivative works, distribute, and display this software and its documentation for NONCOMMERCIAL RESEARCH AND EDUCATIONAL PURPOSES, provided that (1) the above copyright notice and the following two paragraphs appear in all copies of the source code and (2) redistributions, including without limitation binaries, reproduce these notices in the supporting documentation. IN NO EVENT SHALL THE AUTHORS, OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. ========================================================================*/ using System; using System.Collections.Generic; using buddy_sharp; namespace CLab.BDD { /// ///An implementation when sorting a list of BDDs, based on their node count. /// ///Used in , when is set to cm_ascending. public class BDDComparer : IComparer { /// /// Initializes a new instance of the class. /// public BDDComparer() : base() { } /// /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. /// /// The first object to compare. /// The second object to compare. /// /// Value Condition Less than zero is less than y. Zero equals y. Greater than zero is greater than y. /// int IComparer.Compare(Bdd x, Bdd y) { Bdd bddX = (Bdd)x; Bdd bddY = (Bdd)y; if (bddX.Equals(null) & bddY.Equals(null)) return 0; else if (bddX.Equals(null) & !bddY.Equals(null)) return -1; else if (!bddX.Equals(null) & bddY.Equals(null)) return 1; else { if (Bdd.NodeCount(bddX) < Bdd.NodeCount(bddY)) return -1; else return 1; } } } }