Comments (5)
Ah but then that'll also require changing next() and prev() too, not sure if worth it.
I was comparing the iterator interface to https://github.com/marcopompili/lua-leveldb#iterator-example
from luvel.
How about not changing next() prev() and read() but providing additional functions?
Something like:
read_key() and read_value() - return only key or value.
next_pos() and prev_pos() - move cursor position without returning anything.
next_key() and next_value() - move cursor position and return only key or value.
is_valid() - checks if current cursor position is valid.
upd:
Oh, and also, if you like this idea, don't you mind if I try to do this?
from luvel.
I think that will make it a bit confusing and add too much noise onto the list of functions.
Another option is to make next(), prev() etc all lower level and expose a __pairs
in the iterator as well. Perhaps also take options from db:iterator
so it's easy to do things like:
for k, v in pairs(db:iterator({
start = "key1",
stop = "key99"
})) do
print(k, v)
end
Then we can give more lower level flexibility from the methods but users can still use the __pairs
for clean lua code.
from luvel.
Yeah, that sounds much better.
But there is problem in that particular example. What if there is no "key99" in the database, but there is a key following next to it? How can we understand that we need to stop iteration and return nil? Check all received keys by lexicographic order?
Oh, sure, we can just use seek() to get that next key and iterate all keys before it!
So then maybe just keep iterator low-level for flexibility and make slice() function, so we can do something like this:
for k, v in db:slice(start, stop) do
-- do something here
end
Where start and stop are optional arguments.
Upd: but I forgot about readoptions... Should we provide them here?
Do we need db.__pairs
then?
Upd2: Oh, and crazy idea. Maybe we make db.__call
method in addition to db.__pairs
, so we can iterate all db by pairs(db)
or iterate only slice by pairs(db(start, stop))
:
-- iterate all db
for k, v in pairs(db) do
-- do something here
end
-- iterate only slice
for k, v in pairs(db(start, stop)) do
-- do something here
end
Upd3: or even
-- provide readoptions as table into __call metamethod
for k, v in pairs(db{readoptions here}) do
-- do something here
end
-- same, but without pairs()
for k, v in db{readoptions here} do
-- do something here
end
from luvel.
I got the idea of start/stop from plyvel a leveldb wrapper for python.
Currently my brain is just not working and I don't know how to approach this. To be honest I jumped on this project without any real leveldb experience beforehand.
I'll give it a thinking when I feel like it. But feel free to keep posting comments.
from luvel.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from luvel.