var map = new HashMap[String, Int]
map["ten"] = 10
map["two"] = 2
map["one"] = 1
var map_cmp = map.to_map_comparator(default_comparator)
var a = ["ten", "one", "two"]
map_cmp.sort(a)
assert a == ["one", "two", "ten"]
map_cmp = map.to_map_comparator(alpha_comparator)
map_cmp.sort(a)
assert a == ["one", "ten", "two"]
core :: MapComparator :: comparator
The comparator used to compare valuescore :: MapComparator :: comparator=
The comparator used to compare valuescore :: MapComparator :: defaultinit
core $ MapComparator :: SELF
Type of this instance, automatically specialized in every classcore :: Comparator :: bubble_sort
Bubble-sortarray
between from
and to
indices
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: MapComparator :: comparator
The comparator used to compare valuescore :: MapComparator :: comparator=
The comparator used to compare valuescore :: MapComparator :: defaultinit
core :: Object :: defaultinit
core :: Comparator :: defaultinit
core :: Comparator :: insertion_sort
Insertion-sortarray
between from
and to
indices
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Comparator :: merge_sort
Merge-sortarray
between from
and to
indices
core :: Object :: output_class_name
Display class name on stdout (debug only).core :: Comparator :: quick_sort
Quick-sortarray
between from
and to
indices
# A comparator that compares things with their values in a map.
#
# ~~~
# var map = new HashMap[String, Int]
# map["ten"] = 10
# map["two"] = 2
# map["one"] = 1
#
# var map_cmp = map.to_map_comparator(default_comparator)
# var a = ["ten", "one", "two"]
# map_cmp.sort(a)
# assert a == ["one", "two", "ten"]
# map_cmp = map.to_map_comparator(alpha_comparator)
# map_cmp.sort(a)
# assert a == ["one", "ten", "two"]
# ~~~
class MapComparator[K,V]
super Comparator
# What is compared are the keys of the values
redef type COMPARED: K
# The map that associates compared elements to the value used to compare them
var map: MapRead[K,V]
# The comparator used to compare values
var comparator: Comparator
redef fun compare(a,b) do return comparator.compare(map[a], map[b])
end
lib/core/collection/sorter.nit:306,1--335,3