![JAR search and dependency download from the Maven repository](/logo.png)
org.mapdb.Pump.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mapdb Show documentation
Show all versions of mapdb Show documentation
MapDB provides concurrent Maps, Sets and Queues backed by disk storage or off-heap memory. It is a fast, scalable and easy to use embedded Java database.
package org.mapdb
import org.eclipse.collections.impl.list.mutable.primitive.LongArrayList
import org.mapdb.BTreeMapJava.*
import org.mapdb.serializer.GroupSerializer
import java.util.*
/**
* Data streaming
*/
object Pump{
abstract class Sink{
//TODO make protected
internal var rootRecidRecid:Long? = null
internal var counter = 0L
abstract fun put(e:E)
abstract fun create():R
fun putAll(i:Iterable){
putAll(i.iterator())
}
fun putAll(i:Iterator){
while(i.hasNext())
put(i.next())
}
}
fun treeMap(
store:Store,
keySerializer:GroupSerializer,
valueSerializer:GroupSerializer,
comparator:Comparator = keySerializer,
leafNodeSize:Int = CC.BTREEMAP_MAX_NODE_SIZE*3/4,
dirNodeSize:Int = CC.BTREEMAP_MAX_NODE_SIZE*3/4,
hasValues:Boolean=true,
valueInline:Boolean = true
): Sink,Unit>{
var prevKey:K? = null
class DirData {
var leftEdge = LEFT
var keys = ArrayList()
var child = LongArrayList()
var nextDirLink = 0L
}
return object: Sink,Unit>(){
val dirStack = LinkedList()
val keys = ArrayList()
val values = ArrayList()
var leftEdgeLeaf = LEFT
var nextLeafLink = 0L
val nodeSer = NodeSerializer(keySerializer, comparator,
if(valueInline)valueSerializer else Serializer.RECID)
fun nodeValues():Any {
return if(!hasValues) keys.size
else if(valueInline){
//values stored in node
valueSerializer.valueArrayFromArray(values!!.toArray())
} else {
//each value in separate record
values!!.map{store.put(it, valueSerializer)}.toLongArray()
}
}
override fun put(e: Pair) {
if(prevKey!=null && comparator.compare(prevKey, e.first)>=0){
throw DBException.NotSorted()
}
prevKey = e.first
counter++
keys.add(e.first)
values.add(e.second)
if(keys.size
© 2015 - 2025 Weber Informatics LLC | Privacy Policy