Filter improvements

This commit is contained in:
Ali
2020-02-28 20:22:39 +04:00
parent 8341247b5d
commit 5e724b92ea
39 changed files with 5519 additions and 4384 deletions

View File

@@ -1501,7 +1501,10 @@ public final class SqliteValueBox: ValueBox {
public func filteredRange(_ table: ValueBoxTable, start: ValueBoxKey, end: ValueBoxKey, values: (ValueBoxKey, ReadBuffer) -> ValueBoxFilterResult, limit: Int) {
var currentStart = start
var acceptedCount = 0
while acceptedCount < limit {
while true {
if limit > 0 && acceptedCount >= limit {
break
}
var hadStop = false
var lastKey: ValueBoxKey?
self.range(table, start: currentStart, end: end, values: { key, value in
@@ -1530,6 +1533,41 @@ public final class SqliteValueBox: ValueBox {
}
}
public func filteredRange(_ table: ValueBoxTable, start: ValueBoxKey, end: ValueBoxKey, keys: (ValueBoxKey) -> ValueBoxFilterResult, limit: Int) {
var currentStart = start
var acceptedCount = 0
while true {
if limit > 0 && acceptedCount >= limit {
break
}
var hadStop = false
var lastKey: ValueBoxKey?
self.range(table, start: currentStart, end: end, keys: { key in
lastKey = key
let result = keys(key)
switch result {
case .accept:
acceptedCount += 1
return true
case .skip:
return true
case .stop:
hadStop = true
return false
}
return true
}, limit: limit)
if let lastKey = lastKey {
currentStart = lastKey
} else {
break
}
if hadStop {
break
}
}
}
public func range(_ table: ValueBoxTable, start: ValueBoxKey, end: ValueBoxKey, keys: (ValueBoxKey) -> Bool, limit: Int) {
precondition(self.queue.isCurrent())
if let _ = self.tables[table.id] {