Compare a and b.

Returns:

  • -1 if a < b
  • 0 if a = b
  • 1 if a > b

Property definitions

core $ Comparator :: compare
	# Compare `a` and `b`.
	#
	# Returns:
	#
	# * -1 if a < b
	# * 0  if a = b
	# * 1  if a > b
	fun compare(a: COMPARED, b: COMPARED): Int is abstract
lib/core/collection/sorter.nit:27,2--34,55

core $ MapComparator :: compare
	redef fun compare(a,b) do return comparator.compare(map[a], map[b])
lib/core/collection/sorter.nit:334,2--68

core $ DefaultComparator :: compare
	# Return a <=> b
	redef fun compare(a, b) do return a <=> b
lib/core/collection/sorter.nit:342,2--343,42

core $ DefaultReverseComparator :: compare
	# Returns `b <=> a`.
	redef fun compare(a, b) do return b <=> a
lib/core/collection/sorter.nit:355,2--356,42

core $ CachedAlphaComparator :: compare
	redef fun compare(a, b) do
		return do_to_s(a) <=> do_to_s(b)
	end
lib/core/text/abstract_text.nit:2491,2--2493,4

core $ AlphaComparator :: compare
	redef fun compare(a, b) do
		if a == b then return 0
		if a == null then return -1
		if b == null then return 1
		return a.to_s <=> b.to_s
	end
lib/core/text/abstract_text.nit:2499,2--2504,4

ai $ NodeComparator :: compare
	redef fun compare(a,b) do return a.score <=> b.score
lib/ai/search.nit:611,2--53

counter $ CounterComparator :: compare
	redef fun compare(a,b) do return self.counter.map[a] <=> self.counter.map[b]
lib/counter/counter.nit:345,2--77

event_queue $ EventComparator :: compare
	redef fun compare(a, b) do return a.start <=> b.start
lib/event_queue/event_queue.nit:382,2--54

functional $ ComparatorWith :: compare
        redef fun compare(a,b)
        do
                var x = f.call(a)
                var y = f.call(b)
                if x < y then return -1
                if x > y then return 1
                return 0
        end
lib/functional/iter_extras.nit:400,9--407,11

gamnit $ DrawOrderComparator :: compare
	# Require: `a isa SpriteContext and b isa SpriteContext`
	redef fun compare(a, b)
	do return a.as(SpriteContext).draw_order <=> b.as(SpriteContext).draw_order
lib/gamnit/flat/flat_core.nit:1763,2--1765,76

geometry $ PointXCompare :: compare
	redef fun compare(a,b) do
		if a.x == b.x then
			if a.y == b.y then return 0
			if a.y > b.y then return - 1
			return 1
		else
			if a.x > b.x then return -1
			return 1
		end
	end
lib/geometry/polygon.nit:296,2--305,4

nitc $ MClassDefSorter :: compare
	redef fun compare(a, b)
	do
		var ca = a.mclass
		var cb = b.mclass
		if ca != cb then return mmodule.flatten_mclass_hierarchy.compare(ca, cb)
		return mmodule.model.mclassdef_hierarchy.compare(a, b)
	end
src/model/model.nit:390,2--396,4

nitc $ MPropDefSorter :: compare
	redef fun compare(pa, pb)
	do
		var a = pa.mclassdef
		var b = pb.mclassdef
		return mmodule.mclassdef_sorter.compare(a, b)
	end
src/model/model.nit:404,2--409,4

nitc $ MEntityNameSorter :: compare
	# Returns `a.name <=> b.name`.
	redef fun compare(a, b) do return a.name <=> b.name
src/model/model_base.nit:155,2--156,52

nitc $ CatalogScoreSorter :: compare
	redef fun compare(a, b) do
		if not catalog.mpackages_stats.has_key(a) then return 1
		if not catalog.mpackages_stats.has_key(b) then return -1
		var astats = catalog.mpackages_stats[a]
		var bstats = catalog.mpackages_stats[b]
		return bstats.score <=> astats.score
	end
src/catalog/catalog.nit:632,2--638,4

nitc $ CatalogTagsSorter :: compare
	redef fun compare(a, b) do return a <=> b
src/catalog/catalog.nit:647,2--42

nitc $ ScoreComparator :: compare
	redef fun compare(o1, o2) do return o1.score <=> o2.score
src/model/model_index.nit:559,2--58

nitc $ LinexComparator :: compare
	redef fun compare(a,b) do
		var ma = mini(a)
		var mb = mini(b)
		if ma == null then
			if mb == null then return 0 else return -1
		else if mb == null then
			return 1
		end
		var order = ma.model.mmodule_importation_hierarchy
		return order.compare(ma, mb)
	end
src/model/model_viz.nit:101,2--111,4

nitc $ BadConceptionComparator :: compare
	redef fun compare(a,b) do
		var test = a.array_badconception.length <=> b.array_badconception.length
		if test == 0 then
			return a.score <=> b.score
		end
		return a.array_badconception.length <=> b.array_badconception.length
	end
src/metrics/codesmells_metrics.nit:435,2--441,4

geometry $ CounterClockWiseSort :: compare
	redef fun compare(a,b) do
		if a.x == b.x and a.y == b.y then return 0
		if a.x - center.x >= 0.0 and b.x - center.x < 0.0 then return -1
		if a.x - center.x < 0.0 and b.x - center.x >= 0.0 then return 1
		if a.x - center.x == 0.0 and b.x - center.x == 0.0 then
			if a.y - center.y >= 0.0 or b.y - center.y >= 0.0 then
				if a.y > b.y then return -1
				return 1
			end
			if b.y > a.y then return -1
			return 1
		end

		var det = (a.x - center.x) * (b.y - center.y) - (b.x - center.x) * (a.y - center.y)
		if det > 0.0 then return 1
		if det < 0.0 then return -1

		var d1 = (a.x - center.x) * (a.x - center.x) + (a.y - center.y) * (a.y - center.y)
		var d2 = (b.x - center.x) * (b.x - center.x) + (b.y - center.y) * (b.y - center.y)
		if d1 > d2 then return -1
		return 1
	end
lib/geometry/polygon.nit:340,2--361,4

geometry $ ClockWiseSort :: compare
	redef fun compare(a,b) do
		if a.x == b.x and a.y == b.y then return 0
		if a.x - center.x >= 0.0 and b.x - center.x < 0.0 then return 1
		if a.x - center.x < 0.0 and b.x - center.x >= 0.0 then return -1
		if a.x - center.x == 0.0 and b.x - center.x == 0 then
			if a.y - center.y >= 0.0 or b.y - center.y >= 0.0 then
				if a.y > b.y then return 1
				return -1
			end
			if b.y > a.y then return 1
			return -1
		end

		var det = (a.x - center.x) * (b.y - center.y) - (b.x - center.x) * (a.y - center.y)
		if det > 0.0 then return -1
		if det < 0.0 then return 1

		var d1 = (a.x - center.x) * (a.x - center.x) + (a.y - center.y) * (a.y - center.y)
		var d2 = (b.x - center.x) * (b.x - center.x) + (b.y - center.y) * (b.y - center.y)
		if d1 > d2 then return 1
		return -1
	end
lib/geometry/polygon.nit:368,2--389,4

vsm $ IndexMatchSorter :: compare
	redef fun compare(a, b) do
		return b.similarity <=> a.similarity
	end
lib/vsm/vsm.nit:397,2--399,4

nitc $ MatchComparators :: compare
	# Compare with each comparator
	#
	# Return the compare value of the first one to return anything else than 0.
	redef fun compare(o1, o2) do
		for comparator in comparators do
			var c = comparator.compare(o1, o2)
			if c != 0 then return c
		end
		return 0
	end
src/model/model_index.nit:572,2--581,4

nitc $ MEntityComparator :: compare
	# See `MEntity::compare_mentity`
	redef fun compare(o1, o2) do
		return o1.mentity.mentity_kind_rank <=> o2.mentity.mentity_kind_rank
	end
src/model/model_index.nit:591,2--594,4

nitc $ VisibilityComparator :: compare
	redef fun compare(o1, o2) do return o2.mentity.visibility <=> o1.mentity.visibility
src/model/model_index.nit:603,2--84

nitc $ NameComparator :: compare
	redef fun compare(o1, o2) do return o1.mentity.name <=> o2.mentity.name
src/model/model_index.nit:612,2--72

nitc $ NameLengthComparator :: compare
	redef fun compare(o1, o2) do return o1.mentity.name.length <=> o2.mentity.name.length
src/model/model_index.nit:619,2--86

nitc $ FullNameComparator :: compare
	redef fun compare(o1, o2) do return o1.mentity.full_name <=> o2.mentity.full_name
src/model/model_index.nit:628,2--82

nitc $ FullNameLengthComparator :: compare
	redef fun compare(o1, o2) do return o1.mentity.full_name.length <=> o2.mentity.full_name.length
src/model/model_index.nit:635,2--96

poset $ POSet :: compare
	# Compare two elements in an arbitrary total order.
	#
	# This function is mainly used to sort elements of the set in an coherent way.
	#
	# ~~~~
	# var pos = new POSet[String]
	# pos.add_chain(["A", "B", "C", "D", "E"])
	# pos.add_chain(["A", "X", "C", "Y", "E"])
	# var a = ["X", "C", "E", "A", "D"]
	# pos.sort(a)
	# assert a == ["E", "D", "C", "X", "A"]
	# ~~~~
	#
	# POSet are not necessarily total orders because some distinct elements may be incomparable (neither greater or smaller).
	# Therefore this method relies on arbitrary linear extension.
	# This linear extension is a lawful total order (transitive, anti-symmetric, reflexive, and total), so can be used to compare the elements.
	#
	# The abstract behavior of the method is thus the following:
	#
	# ~~~~nitish
	# if a == b then return 0
	# if has_edge(b, a) then return -1
	# if has_edge(a, b) then return 1
	# return -1 or 1 # according to the linear extension.
	# ~~~~
	#
	# Note that the linear extension is stable, unless a new node or a new edge is added.
	redef fun compare(a, b)
	do
		var ae = self.elements[a]
		var be = self.elements[b]
		var res = ae.tos.length <=> be.tos.length
		if res != 0 then return res
		return elements[a].count <=> elements[b].count
	end
lib/poset/poset.nit:288,2--322,4