sorting keys - fix

This commit is contained in:
Jaremy Creechley 2023-08-28 21:32:28 -07:00
parent 1b5609b5b8
commit 8ab9eee443
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 11 additions and 3 deletions

View File

@ -24,8 +24,8 @@ type
proc `=destroy`*(x: var DataBufferHolder) = proc `=destroy`*(x: var DataBufferHolder) =
## copy pointer implementation ## copy pointer implementation
if x.buf != nil: if x.buf != nil:
when isMainModule or true: # when isMainModule or true:
echo "buffer: FREE: ", repr x.buf.pointer # echo "buffer: FREE: ", repr x.buf.pointer
deallocShared(x.buf) deallocShared(x.buf)
proc len*(a: DataBuffer): int = a[].size proc len*(a: DataBuffer): int = a[].size

View File

@ -1,6 +1,7 @@
import std/tables import std/tables
import std/sequtils import std/sequtils
import std/strutils import std/strutils
import std/algorithm
import pkg/chronos import pkg/chronos
import pkg/questionable import pkg/questionable
@ -91,11 +92,14 @@ method put*(
proc keyIterator(self: MemoryDatastore, queryKey: string): iterator: KeyBuffer {.gcsafe.} = proc keyIterator(self: MemoryDatastore, queryKey: string): iterator: KeyBuffer {.gcsafe.} =
return iterator(): KeyBuffer {.closure.} = return iterator(): KeyBuffer {.closure.} =
let keys = self.store.keys().toSeq() var keys = self.store.keys().toSeq()
keys.sort(proc (x, y: KeyBuffer): int = cmp(x.toString, y.toString))
for key in keys: for key in keys:
if key.toString().startsWith(queryKey): if key.toString().startsWith(queryKey):
yield key yield key
import pretty
method query*( method query*(
self: MemoryDatastore, self: MemoryDatastore,
query: Query, query: Query,
@ -108,10 +112,14 @@ method query*(
var var
iter = QueryIter.new() iter = QueryIter.new()
echo "queryKey: ", queryKey
proc next(): Future[?!QueryResponse] {.async.} = proc next(): Future[?!QueryResponse] {.async.} =
let let
kb = walker() kb = walker()
print "query: ", kb.toString
if finished(walker): if finished(walker):
iter.finished = true iter.finished = true
return success (Key.none, EmptyBytes) return success (Key.none, EmptyBytes)