Skip to content

Commit

Permalink
refactor iterator with crystal-0.20.1 or higher
Browse files Browse the repository at this point in the history
  • Loading branch information
maiha committed Dec 26, 2016
1 parent 7ec5bbd commit e5c2a83
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -2,7 +2,7 @@

RocksDB client for [Crystal](http://crystal-lang.org/).

- crystal: 0.20.0
- crystal: 0.20.3 (at least 0.20.1 needed)


## Supported API
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Expand Up @@ -4,6 +4,6 @@ version: 0.4.0
authors:
- maiha <maiha@wota.jp>

crystal: 0.20.0
crystal: 0.20.3

license: MIT
2 changes: 1 addition & 1 deletion spec/commands/iteration_spec.cr
Expand Up @@ -34,7 +34,7 @@ describe "Iterations" do
it "#new_iterator" do
db = RocksDB::DB.new(path)
iter = db.new_iterator
iter.should be_a(RocksDB::Iterator)
iter.should be_a(RocksDB::StringIterator)
iter.close
db.close
end
Expand Down
2 changes: 1 addition & 1 deletion spec/iterator_spec.cr
Expand Up @@ -6,7 +6,7 @@ describe "Iterator" do
it "work" do
db = RocksDB::DB.new(path)
3.times{|i| db.put("k#{i}", i) }
iter = RocksDB::Iterator.new(db)
iter = RocksDB::StringIterator.new(db)

iter.valid?.should be_false

Expand Down
2 changes: 1 addition & 1 deletion src/rocksdb/commands/iteration.cr
Expand Up @@ -2,7 +2,7 @@ module RocksDB::Commands
include Api

def new_iterator
Iterator.new(self)
StringIterator.new(self)
end

def each(&block)
Expand Down
16 changes: 3 additions & 13 deletions src/rocksdb/iterator.cr
@@ -1,17 +1,9 @@
#abstract class RocksDB::Iterator(T)
class RocksDB::Iterator
abstract class RocksDB::Iterator(T)
include Api
include RawMemory(LibRocksDB::RocksdbIteratorT)

# protected abstract def zero : T
# protected abstract def underlying(ptr, size) : T
protected def zero
""
end

protected def underlying(ptr, size) : String
String.new(ptr, size)
end
protected abstract def zero : T
protected abstract def underlying(ptr, size) : T

def initialize(@db : DB, r_opts : ReadOptions? = nil)
opts = (r_opts || @db.r_opts).not_nil!
Expand Down Expand Up @@ -73,7 +65,6 @@ class RocksDB::Iterator

end

{% if flag?(:fixed_issue3635) %}
module RocksDB
class StringIterator < Iterator(String)
protected def zero
Expand All @@ -85,4 +76,3 @@ module RocksDB
end
end
end
{% end %}

0 comments on commit e5c2a83

Please sign in to comment.