Skip to content

Commit

Permalink
Replace ChannelEnumerator by ListEnumerator.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralph Gasser committed Feb 5, 2024
1 parent 680e086 commit a567a1f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 31 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.vitrivr.engine.index.enumerate

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import org.vitrivr.engine.core.context.IndexContext
import org.vitrivr.engine.core.operators.ingest.Enumerator
import org.vitrivr.engine.core.operators.ingest.EnumeratorFactory
import org.vitrivr.engine.core.source.Source
import java.util.LinkedList

/**
* A [Enumerator] that allows a caller to explicitly prepare a list of [Source]s to enumerate.
*
* @author Ralph Gasser
* @version 1.0.0
*/
class ListEnumerator : EnumeratorFactory {

/**
* Creates a new [Enumerator] instance from this [ListEnumerator].
*
* @param context The [IndexContext] to use.
* @param parameters Optional set of parameters.
*/
override fun newOperator(context: IndexContext, parameters: Map<String, String>): Enumerator {
return Instance(context)
}

/**
* The [Enumerator] returned by this [FileSystemEnumerator].
*/
private class Instance(private val context: IndexContext) : Enumerator {

/** List of [Source]s that should be enumerated. */
private val list: LinkedList<Source> = LinkedList()

override fun toFlow(scope: CoroutineScope): Flow<Source> = flow {
for (s in this@Instance.list) {
emit(s)
}
}

/**
* Enqueues a new [Source].
*
* @param source [Source] to add.
*/
fun add(source: Source) {
this.list.add(source)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
org.vitrivr.engine.index.enumerate.FileSystemEnumerator
org.vitrivr.engine.index.enumerate.ApiEnumerator
org.vitrivr.engine.index.enumerate.ChannelEnumerator
org.vitrivr.engine.index.enumerate.ListEnumerator

0 comments on commit a567a1f

Please sign in to comment.