Версией конфигурации или просто версией будем называть число реконфигураций работающей системы с момента начала работы, изначально это ноль. Каждый узел будет хранить последнюю известную ему версию конфигурации, и версия конфигурации будет использоваться в токене.
This file contains hidden or 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
val mapper = jacksonObjectMapper() | |
.enable(SerializationFeature.INDENT_OUTPUT) | |
.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET) | |
.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT) | |
.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE) |
This file contains hidden or 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
package ru.ifmo.ctddev.igushkin.streamExamples; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Set; | |
import java.util.function.Function; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
import java.util.stream.Stream; |
This file contains hidden or 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
public <A, B, C> Map<B, List<Pair<A, C>>> invertMap(Map<A, Map<B, C>> input) { | |
return input.entrySet().stream() | |
.flatMap(kv -> kv.getValue().entrySet().stream().map(vs -> new Pair<>(kv.getKey(), vs))) | |
.collect(Collectors.groupingBy( | |
it -> it.getValue().getKey(), | |
Collectors.mapping( | |
it -> new Pair<>(it.getKey(), it.getValue().getValue()), | |
Collectors.toList() | |
)) | |
); |
This file contains hidden or 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
import kotlin.system.measureTimeMillis | |
/** | |
* Created by igushs on 2/2/16. | |
*/ | |
public operator fun <T> Sequence<T>.plus(otherGenerator: () -> Sequence<T>) = | |
object : Sequence<T> { | |
private val thisIterator: Iterator<T> by lazy { [email protected]() } | |
private val otherIterator: Iterator<T> by lazy { otherGenerator().iterator() } |
This file contains hidden or 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
import kotlin.system.measureTimeMillis | |
/** | |
* Created by igushs on 2/2/16. | |
*/ | |
public operator fun <T> Sequence<T>.plus(otherGenerator: () -> Sequence<T>) = | |
object : Sequence<T> { | |
private val thisIterator: Iterator<T> by lazy { [email protected]() } | |
private val otherIterator: Iterator<T> by lazy { otherGenerator().iterator() } |
This file contains hidden or 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
import kotlin.system.measureTimeMillis | |
/** | |
* Created by igushs on 2/2/16. | |
*/ | |
public operator fun <T> Sequence<T>.plus(otherGenerator: () -> Sequence<T>) = | |
object : Sequence<T> { | |
private val thisIterator: Iterator<T> by lazy { [email protected]() } | |
private val otherIterator: Iterator<T> by lazy { otherGenerator().iterator() } |
This file contains hidden or 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
private const val SOURCE_ID = 0 | |
private const val SINK_ID = 1 | |
class IntEmd<TItem>(val distance: ((TItem, TItem) -> Int)? = null) | |
: HistogramDistance<TItem, Int> { | |
/** Adds two [TNumeric] items. */ | |
infix fun Int.plus(other: Int) = this + other | |
/** Subtracts two [TNumeric] items. */ |
This is an implementation of Earth Mover's Distance for histograms in Kotlin.
It uses successive shortest path min-cost max-flow solution with SPFA inside and thus is quite fast.
How to use
This file contains hidden or 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
class Node<T>(val value: T, | |
val children: Map<T, Node<T>>) | |
fun <T> buildTree(initialState: T, childrenProducer: (T) -> Set<T>): Node<T> = Node( | |
initialState, | |
childrenProducer(initialState).associateBy({ it }, { buildTree(it, childrenProducer) }) | |
) | |
fun <T> List<T>.withoutItemAt(index: Int) = take(index) + drop(index + 1) |
OlderNewer