mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-02 21:53:05 +00:00
add memory (test) ds
This commit is contained in:
parent
985697b1bb
commit
a7f6794f7e
@ -1,5 +1,8 @@
|
||||
# import std/atomics
|
||||
import threading/smartptrs
|
||||
import std/hashes
|
||||
|
||||
export hashes
|
||||
|
||||
type
|
||||
DataBufferHolder* = object
|
||||
@ -29,6 +32,16 @@ proc len*(a: DataBuffer): int = a[].size
|
||||
|
||||
proc isNil*(a: DataBuffer): bool = smartptrs.isNil(a)
|
||||
|
||||
proc hash*(a: DataBuffer): Hash =
|
||||
a[].buf.toOpenArray(0, a[].size-1).hash()
|
||||
|
||||
proc `==`*(a, b: DataBuffer): bool =
|
||||
if a.isNil and b.isNil: return true
|
||||
elif a.isNil or b.isNil: return false
|
||||
elif a[].size != b[].size: return false
|
||||
elif a[].buf == b[].buf: return true
|
||||
else: a.hash() == b.hash()
|
||||
|
||||
proc new*(tp: typedesc[DataBuffer], size: int = 0): DataBuffer =
|
||||
## allocate new buffer with given size
|
||||
newSharedPtr(DataBufferHolder(
|
||||
|
||||
@ -49,12 +49,18 @@ method delete*(
|
||||
|
||||
return success()
|
||||
|
||||
import pretty
|
||||
|
||||
method get*(
|
||||
self: MemoryDatastore,
|
||||
key: Key
|
||||
): Future[?!seq[byte]] {.async.} =
|
||||
|
||||
let dk = KeyBuffer.new(key)
|
||||
echo "getting: ", key
|
||||
for k, v in self.store.pairs():
|
||||
print "get: ", k.toString()
|
||||
|
||||
if self.store.hasKey(dk):
|
||||
let res = self.store[dk]
|
||||
return success res.toSeq(byte)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user