-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for fulltext and started work on knn queries
- Loading branch information
Showing
7 changed files
with
112 additions
and
22 deletions.
There are no files selected for viewing
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
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
38 changes: 38 additions & 0 deletions
38
...vr-engine-core/src/main/kotlin/org/vitrivr/engine/core/util/knn/FixedSizePriorityQueue.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.vitrivr.engine.core.util.knn | ||
|
||
import java.util.* | ||
|
||
/** | ||
* Ordered List of fixed size, used for KNN operations | ||
*/ | ||
|
||
class FixedSizePriorityQueue<T>(private val maxSize: Int, comparator: Comparator<T>) : TreeSet<T>(comparator) { | ||
|
||
init { | ||
require(maxSize > 0) { "Maximum size must be greater than zero." } | ||
} | ||
|
||
private val elementsLeft: Int | ||
get() = this.maxSize - this.size | ||
|
||
override fun add(element: T): Boolean { | ||
if (elementsLeft > 0) { | ||
// queue isn't full => add element and decrement elementsLeft | ||
val added = super.add(element) | ||
return added | ||
} else { | ||
// there is already 1 or more elements => compare to the least | ||
val compared = super.comparator().compare(this.last(), element) | ||
if (compared > 0) { | ||
// new element is larger than the least in queue => pull the least and add new one to queue | ||
pollLast() | ||
super.add(element) | ||
return true | ||
} else { | ||
// new element is less than the least in queue => return false | ||
return false | ||
} | ||
} | ||
} | ||
|
||
} |
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
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
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
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