Colorize a collection of buckets using a poset and a conflict graph

Two elements cannot have the same color if they both appear in the same bucket The use of a POSet hierarchy optimize the coloring Buckets elements are colored using linearization order starting

Introduced properties

private var _poset: POSet[H]

nitc :: POSetBucketsColorer :: _poset

fun colorize(buckets: Map[H, Set[E]]): Map[E, Int]

nitc :: POSetBucketsColorer :: colorize

Colorize buckets using the POSet and conflict graph
private fun colors: HashMap[E, Int]

nitc :: POSetBucketsColorer :: colors

private fun colors=(colors: HashMap[E, Int])

nitc :: POSetBucketsColorer :: colors=

private fun conflicts: Map[H, Set[H]]

nitc :: POSetBucketsColorer :: conflicts

private fun conflicts=(conflicts: Map[H, Set[H]])

nitc :: POSetBucketsColorer :: conflicts=

init defaultinit(poset: POSet[H], conflicts: Map[H, Set[H]])

nitc :: POSetBucketsColorer :: defaultinit

private fun is_color_free(color: Int, holder: H, buckets: Map[H, Set[E]]): Bool

nitc :: POSetBucketsColorer :: is_color_free

Check if the color is free for this holder
private fun max_color(holder: H, buckets: Map[H, Set[E]]): Int

nitc :: POSetBucketsColorer :: max_color

Return the max color used by a class
private fun min_color(others: Collection[H], buckets: Map[H, Set[E]]): Int

nitc :: POSetBucketsColorer :: min_color

Get the next available color considering used colors by other buckets
private fun poset: POSet[H]

nitc :: POSetBucketsColorer :: poset

private fun poset=(poset: POSet[H])

nitc :: POSetBucketsColorer :: poset=

Redefined properties

redef type SELF: POSetBucketsColorer[H, E]

nitc $ POSetBucketsColorer :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _poset: POSet[H]

nitc :: POSetBucketsColorer :: _poset

protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun colorize(buckets: Map[H, Set[E]]): Map[E, Int]

nitc :: POSetBucketsColorer :: colorize

Colorize buckets using the POSet and conflict graph
private fun colors: HashMap[E, Int]

nitc :: POSetBucketsColorer :: colors

private fun colors=(colors: HashMap[E, Int])

nitc :: POSetBucketsColorer :: colors=

private fun conflicts: Map[H, Set[H]]

nitc :: POSetBucketsColorer :: conflicts

private fun conflicts=(conflicts: Map[H, Set[H]])

nitc :: POSetBucketsColorer :: conflicts=

init defaultinit(poset: POSet[H], conflicts: Map[H, Set[H]])

nitc :: POSetBucketsColorer :: defaultinit

fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
private fun is_color_free(color: Int, holder: H, buckets: Map[H, Set[E]]): Bool

nitc :: POSetBucketsColorer :: is_color_free

Check if the color is free for this holder
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
private fun max_color(holder: H, buckets: Map[H, Set[E]]): Int

nitc :: POSetBucketsColorer :: max_color

Return the max color used by a class
private fun min_color(others: Collection[H], buckets: Map[H, Set[E]]): Int

nitc :: POSetBucketsColorer :: min_color

Get the next available color considering used colors by other buckets
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
private fun poset: POSet[H]

nitc :: POSetBucketsColorer :: poset

private fun poset=(poset: POSet[H])

nitc :: POSetBucketsColorer :: poset=

fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram nitc::POSetBucketsColorer POSetBucketsColorer core::Object Object nitc::POSetBucketsColorer->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

nitc $ POSetBucketsColorer
# Colorize a collection of buckets using a poset and a conflict graph
# Two elements cannot have the same color if they both appear in the same bucket
# The use of a POSet hierarchy optimize the coloring
# Buckets elements are colored using linearization order starting
class POSetBucketsColorer[H: Object, E: Object]
	private var colors = new HashMap[E, Int]
	private var poset: POSet[H]
	private var conflicts: Map[H, Set[H]]

	# Colorize buckets using the POSet and conflict graph
	fun colorize(buckets: Map[H, Set[E]]): Map[E, Int] do
		colors.clear
		for h in poset.linearize(buckets.keys) do
			var color = min_color(poset[h].direct_greaters, buckets)
			for bucket in buckets[h] do
				if colors.has_key(bucket) then continue
				while not is_color_free(color, h, buckets) do color += 1
				colors[bucket] = color
				color += 1
			end
		end
		return colors
	end

	# Get the next available color considering used colors by other buckets
	private fun min_color(others: Collection[H], buckets: Map[H, Set[E]]): Int do
		var min = -1
		for holder in others do
			var color = max_color(holder, buckets)
			if color > min then min = color
		end
		return min + 1
	end

	# Return the max color used by a class
	private fun max_color(holder: H, buckets: Map[H, Set[E]]): Int do
		var max = -1
		for bucket in buckets[holder] do
			if not colors.has_key(bucket) then continue
			var color = colors[bucket]
			if color > max then max = color
		end
		return max
	end

	# Check if the color is free for this holder
	private fun is_color_free(color: Int, holder: H, buckets: Map[H, Set[E]]): Bool do
		if not conflicts.has_key(holder) then return true
		for conflict in conflicts[holder] do
			for bucket in buckets[conflict] do
				if not colors.has_key(bucket) then continue
				if colors[bucket] == color then return false
			end
		end
		return true
	end
end
src/compiler/coloring.nit:514,1--570,3