Skip to content

Instantly share code, notes, and snippets.

View sabirove's full-sized avatar

Evgenii Sabirov sabirove

  • Saint-Petersburg, Russia
View GitHub Profile
/**
* Topological sort of a dependency graph.
*/
object TopSort {
fun <T : Any> parentsFirst(objects: Set<T>, isFirstChildOfSecond: (T, T) -> Boolean): List<T> =
childrenFirst(objects, isFirstChildOfSecond).reversed()
fun <T : Any> childrenFirst(objects: Set<T>, isFirstChildOfSecond: (T, T) -> Boolean): List<T> {
val childToParents = HashMap<T, MutableList<T>>()
// dependencies:
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api/1.7.30
/**
* Wrapper over slf4j [Logger] providing Kotlin functional-style API with inline call optimization:
* lambda parameter is inlined by the Kotlin compiler while actual method invocations should
* eventually be removed by the branch predictor whenever corresponding logging level is not
* active so there's no performance hit from inactive logging statements whatsoever.
*
* Note: "Logg" because it's short and avoids all kinds of namespace conflicts.