From 0dc384dd79697878abba46e746d952fafea3b7a4 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Mon, 6 May 2024 20:20:07 +0200 Subject: [PATCH] Enable "get?" functions for partitions and tags. --- src/dodb/partition.cr | 8 +++++++- src/dodb/tags.cr | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/dodb/partition.cr b/src/dodb/partition.cr index 6aa817c..3735e7d 100644 --- a/src/dodb/partition.cr +++ b/src/dodb/partition.cr @@ -39,7 +39,7 @@ class DODB::Partition(V) < DODB::Indexer(V) ::File.delete symlink end - def get(partition) + def get(partition) : Array(V) r_value = Array(V).new partition_directory = indexing_directory partition @@ -53,6 +53,12 @@ class DODB::Partition(V) < DODB::Indexer(V) r_value end + def get?(partition) : Array(V)? + get partition + rescue MissingEntry + nil + end + def delete(partition) delete partition, do true end end diff --git a/src/dodb/tags.cr b/src/dodb/tags.cr index 30f9c5b..7957997 100644 --- a/src/dodb/tags.cr +++ b/src/dodb/tags.cr @@ -64,6 +64,12 @@ class DODB::Tags(V) < DODB::Indexer(V) get_with_indice(tag).map &.[0] end + def get?(tag : String) : Array(V)? + get tag + rescue MissingEntry + nil + end + def get(keys : Array(String)) : Array(V) get_with_indices(keys.sort).map &.[0] end @@ -140,7 +146,17 @@ class DODB::CachedTags(V) < DODB::Tags(V) end end - def get(tag : String) + def get_with_indice(tag : String) : Array(Tuple(V, Int32)) + r_value = Array(Tuple(V, Int32)).new + + @data[tag].each do |data_key| + r_value << { @storage[data_key], data_key } + end + + r_value + end + + def get(tag : String) : Array(V) r_value = Array(V).new @data[tag].each do |data_key|