More consistent API.

toying-with-ramdb
Philippe PITTOLI 2024-05-09 00:04:15 +02:00
parent c88e738332
commit 42b82c8fa5
2 changed files with 13 additions and 7 deletions

View File

@ -43,11 +43,10 @@ class DODB::Partition(V) < DODB::Indexer(V)
end
def get(partition) : Array(V)
r_value = Array(V).new
partition_directory = indexing_directory partition
raise MissingEntry.new(@name, partition) unless Dir.exists? partition_directory
return r_value unless Dir.exists? partition_directory
r_value = Array(V).new
Dir.each_child partition_directory do |child|
r_value << @storage[get_key child]

View File

@ -42,11 +42,10 @@ class DODB::Tags(V) < DODB::Indexer(V)
end
def get_with_indice(tag : String) : Array(Tuple(V, Int32))
r_value = Array(Tuple(V, Int32)).new
tag_directory = indexing_directory tag
raise MissingEntry.new(@name, tag) unless Dir.exists? tag_directory
return r_value unless Dir.exists? tag_directory
r_value = Array(Tuple(V, Int32)).new
Dir.each_child tag_directory do |child|
key = get_key child
@ -56,10 +55,18 @@ class DODB::Tags(V) < DODB::Indexer(V)
r_value
end
# `get_with_indices` gets values with all the tags.
def get_with_indices(keys : Array(String)) : Array(Tuple(V, Int32))
r_value = Array(Tuple(V, Int32)).new
return r_value if keys.size < 1
first_key = keys.pop
r_value = get_with_indice(first_key) rescue return [] of Tuple(V, Int32)
keys.each do |tag|
r_value.concat get_with_indice tag
values = get_with_indice(tag) rescue return [] of Tuple(V, Int32)
r_value &= values
end
r_value
end