For now, DODB::DataBase::Cached works only without indexes.

remotes/1719344442898712274/ramdb
Karchnu 2020-07-16 23:37:52 +02:00
parent ba9d2fb48c
commit 99b8b5e20b
2 changed files with 18 additions and 20 deletions

View File

@ -81,24 +81,23 @@ describe "DODB::DataBase::Cached" do
# Actual reversal is tested here.
db.to_a(reversed: true).should eq db.to_a.reverse
end
end
## it "respects the provided offsets if any" do
## db = DODB::SpecDataBase.new
##
## Ship.all_ships.each do |ship|
## db << ship
## end
##
## db.to_a(start_offset: 0, end_offset: 0)[0]?.should eq Ship.mutsuki
## db.to_a(start_offset: 1, end_offset: 1)[0]?.should eq Ship.kisaragi
## db.to_a(start_offset: 2, end_offset: 2)[0]?.should eq Ship.yayoi
##
## db.to_a(start_offset: 0, end_offset: 2).should eq [
## Ship.mutsuki, Ship.kisaragi, Ship.yayoi
## ]
## end
## end
it "respects the provided offsets if any" do
db = DODB::SpecDataBase.new
Ship.all_ships.each do |ship|
db << ship
end
db.to_a(start_offset: 0, end_offset: 0)[0]?.should eq Ship.mutsuki
db.to_a(start_offset: 1, end_offset: 1)[0]?.should eq Ship.kisaragi
db.to_a(start_offset: 2, end_offset: 2)[0]?.should eq Ship.yayoi
db.to_a(start_offset: 0, end_offset: 2).should eq [
Ship.mutsuki, Ship.kisaragi, Ship.yayoi
]
end
end
# describe "indices" do
# it "do basic indexing" do

View File

@ -91,7 +91,7 @@ class DODB::DataBase::Cached(V)
(reversed ? @data.reverse : @data).each do |index, v|
i += 1
next if start_offset > i
break unless end_offset.nil? || i < end_offset
break unless end_offset.nil? || i <= end_offset
yield v, index
end
@ -117,8 +117,7 @@ class DODB::DataBase::Cached(V)
def to_h(reversed : Bool = false, start_offset = 0, end_offset : Int32? = nil)
res = Hash(Int32, V).new
# (reversed ? @data.reverse : @data).each do |index, v|
@data.each do |index, v|
(reversed ? @data.reverse : @data).each do |index, v|
next if start_offset > index
break unless end_offset.nil? || index < end_offset