From cf57773a259c46c706fd2b9360794af396bb6254 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Thu, 9 May 2024 00:04:15 +0200 Subject: [PATCH] More consistent API. --- src/dodb/partition.cr | 5 ++--- src/dodb/tags.cr | 15 +++++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/dodb/partition.cr b/src/dodb/partition.cr index 0880386..d77430d 100644 --- a/src/dodb/partition.cr +++ b/src/dodb/partition.cr @@ -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] diff --git a/src/dodb/tags.cr b/src/dodb/tags.cr index d4a31e2..117a226 100644 --- a/src/dodb/tags.cr +++ b/src/dodb/tags.cr @@ -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