View Logg.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
View TopSort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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>>() |