remotes/1719344442898712274/ramdb
Karchnu 2020-07-16 20:04:13 +02:00
parent 370e0eca99
commit ba9d2fb48c
1 changed files with 20 additions and 17 deletions

View File

@ -3,20 +3,20 @@ require "json"
require "./dodb.cr" require "./dodb.cr"
#class Hash(K,V) class Hash(K,V)
# def reverse def reverse
# rev = Array(Tuple(K,V)).new rev = Array(Tuple(K,V)).new
# keys = Array(K).new keys = Array(K).new
# each_key do |k| each_key do |k|
# keys << k keys << k
# end end
# keys.reverse.each do |k| keys.reverse.each do |k|
# rev << {k, self.[k]} rev << {k, self.[k]}
# end end
#
# rev rev
# end end
#end end
class DODB::DataBase::Cached(V) class DODB::DataBase::Cached(V)
@indexers = [] of Indexer(V) @indexers = [] of Indexer(V)
@ -88,8 +88,7 @@ class DODB::DataBase::Cached(V)
# Can be useful for making dumps or to restore a database, however. # Can be useful for making dumps or to restore a database, however.
def each_with_index(reversed : Bool = false, start_offset = 0, end_offset : Int32? = nil) def each_with_index(reversed : Bool = false, start_offset = 0, end_offset : Int32? = nil)
i = -1 # do not trust key to be the right index i = -1 # do not trust key to be the right index
#(reversed ? @data.reverse : @data).each do |index, v| (reversed ? @data.reverse : @data).each do |index, v|
@data.each do |index, v|
i += 1 i += 1
next if start_offset > i next if start_offset > i
break unless end_offset.nil? || i < end_offset break unless end_offset.nil? || i < end_offset
@ -108,7 +107,11 @@ class DODB::DataBase::Cached(V)
end end
def to_a(reversed : Bool = false, start_offset = 0, end_offset : Int32? = nil) def to_a(reversed : Bool = false, start_offset = 0, end_offset : Int32? = nil)
@data.values res = Array(V).new
each(reversed, start_offset, end_offset) do |v|
res << v
end
res
end end
def to_h(reversed : Bool = false, start_offset = 0, end_offset : Int32? = nil) def to_h(reversed : Bool = false, start_offset = 0, end_offset : Int32? = nil)