You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix temporary collections API and come up with a new one (like from Java API but better?).
Hooks. A part of abstract algorithms works like (or precisely are) dynamic algorithms. It means there is an input data that is changing and the output should be changed along. It also means that there should be an API to simplify representation of such relationship.
Suggestion is that there should be a Hook interface which declares API for hooking on changes viewers. In that case all the algorithms can be represented as a simple object which state depends on its arguments and, hence, can be called "views". For example,
/** * @param C type that is representing data change * @param I type of intermediate data representation*/interfaceHook<C, I> {
funhookOn(callback:I.(change: C) ->Unit)
}
interfaceView<E> {
val value:E
}
// ...sealedinterfaceListChange<E> {
data classAssign<E>(valindex:Int, valoldElement:E, valnewElement:E): ListChange<E>
data classInsert<E>(valindex:Int, valnewElement:E): ListChange<E>
data classRemove<E>(valindex:Int, valoldElement:E): ListChange<E>
}
interfaceMutableListHook<E>: MutableList<E>, Hook<ListChange<E>, List<E>>
classMutableListHookImpl<E>(privatevallist:MutableList<E>): MutableList<E> by list, MutableListHook<E> {
privateval hooks = mutableListOf<List<E>.(ListChange<E>) ->Unit>()
overridefunhookOn(callback:List<E>.(change: ListChange<E>) ->Unit) { hooks.add(callback) }
privatefuntrigger(change:ListChange<E>) { hooks.forEach { list.it(change) } }
overridefunadd(element:E): Boolean {
trigger(ListChange.Insert(list.size, element))
return list.add(element)
}
// ...
}
// ...classDynamicMaximumValueView<E>(hook:MutableListHook<E>, comparator:Comparator<E>): View<E> {
privateval heap =MaxHeap(hook, comparator)
init {
hook.hookOn {
when (it) {
isListChange.Assign-> {
heap.remove(it.oldElement)
heap.add(it.newElement)
}
isListChange.Insert-> {
heap.add(it.newElement)
}
isListChange.Remove-> {
heap.remove(it.oldElement)
}
}
}
}
overrideval value:E get() = heap.head
}
Fix temporary collections API and come up with a new one (like from Java API but better?).
Hooks. A part of abstract algorithms works like (or precisely are) dynamic algorithms. It means there is an input data that is changing and the output should be changed along. It also means that there should be an API to simplify representation of such relationship.
Suggestion is that there should be a
Hookinterface which declares API for hooking on changes viewers. In that case all the algorithms can be represented as a simple object which state depends on its arguments and, hence, can be called "views". For example,