From 05498791408a330e076478e0cc559eb2832d4785 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Tue, 21 May 2024 20:57:44 +0200 Subject: [PATCH] API change: get_with_index -> get_with_keys --- spec/test-ships.cr | 4 ++-- src/dodb/partition.cr | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/test-ships.cr b/spec/test-ships.cr index 979a597..9a82c6d 100644 --- a/spec/test-ships.cr +++ b/spec/test-ships.cr @@ -295,7 +295,7 @@ describe "DODB::DataBase" do end # Removing the “flagship” tag, brace for impact. - flagship, index = db_ships_by_tags.get_with_indice("flagship")[0] + flagship, index = db_ships_by_tags.get_with_keys("flagship")[0] flagship.tags = [] of String db[index] = flagship @@ -815,7 +815,7 @@ describe "DODB::CachedDataBase" do end # Removing the “flagship” tag, brace for impact. - flagship, index = db_ships_by_tags.get_with_indice("flagship")[0] + flagship, index = db_ships_by_tags.get_with_keys("flagship")[0] flagship = flagship.clone flagship.tags = [] of String db[index] = flagship diff --git a/src/dodb/partition.cr b/src/dodb/partition.cr index 1bfc3de..29c8c42 100644 --- a/src/dodb/partition.cr +++ b/src/dodb/partition.cr @@ -256,14 +256,14 @@ class DODB::CachedPartition(V) < DODB::Partition(V) # # ``` # # For example, get all red cars. - # cars_by_color.get_with_indexes "red" + # cars_by_color.get_with_keys "red" # # Will return something like: # # [ (@storage[42], 42) # # , (@storage[91], 91) # # ] # # Each tuple is composed of a car and its key in the database. # ``` - def get_with_indexes(partition : String) : Array(Tuple(V, Int32)) + def get_with_keys(partition : String) : Array(Tuple(V, Int32)) r_value = Array(Tuple(V, Int32)).new # In case the partition is cached. @@ -330,8 +330,8 @@ class DODB::CachedPartition(V) < DODB::Partition(V) # ``` # TODO: in case the partition is left empty, should the partition be removed from the cache? def delete(partition : String, &matcher : Proc(V, Bool)) - # Use `get_with_indexes` to retrieve data on-disk, if necessary. - new_partition = get_with_indexes(partition).map(&.[1]).select do |key| + # Use `get_with_keys` to retrieve data on-disk, if necessary. + new_partition = get_with_keys(partition).map(&.[1]).select do |key| item = @storage[key] ! yield item end @@ -386,14 +386,14 @@ class DODB::RAMOnlyPartition(V) < DODB::CachedPartition(V) # # ``` # # Get all red cars. - # cars_by_color.get_with_indexes "red" + # cars_by_color.get_with_keys "red" # # Returns something like: # # [ (@storage[42], 42) # # , (@storage[91], 91) # # ] # # Each tuple is composed of a car and its key in the database. # ``` - def get_with_indexes(partition : String) : Array(Tuple(V, Int32)) + def get_with_keys(partition : String) : Array(Tuple(V, Int32)) r_value = Array(Tuple(V, Int32)).new if keys = @data[partition]? keys.each do |data_key|