API change: get_with_index -> get_with_keys

This commit is contained in:
Philippe PITTOLI 2024-05-21 20:57:44 +02:00
parent 378f8c76db
commit 0549879140
2 changed files with 8 additions and 8 deletions

View File

@ -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

View File

@ -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|