Renaming (+ fix EfficientFIFO#delete).

toying-with-ramdb
Philippe PITTOLI 2024-05-27 18:13:14 +02:00
parent 9d2b5157fe
commit cd48aad945
7 changed files with 45 additions and 17 deletions

View File

@ -21,7 +21,7 @@ class Context
class_property from = 1_000
class_property to = 50_000
class_property incr = 1_000
class_property fifo_size = 10_000
class_property fifo_size : UInt32 = 10_000
end
# To simplify the creation of graphs, it's better to have fake data for
@ -77,9 +77,9 @@ end
def search_benchmark(storage : DODB::Storage(Car),
current_db_size : Int32,
name : String,
search_name : DODB::Index::Basic(Car),
search_color : DODB::Index::Partition(Car),
search_keywords : DODB::Index::Tags(Car))
search_name : DODB::Trigger::Index(Car),
search_color : DODB::Trigger::Partition(Car),
search_keywords : DODB::Trigger::Tags(Car))
name_to_search = ENV["CARNAME"] rescue "Corvet-#{(current_db_size/2).to_i}"
color_to_search = ENV["CARCOLOR"] rescue "red"
keyword_to_search = ENV["CARKEYWORD"] rescue "spacious"
@ -113,7 +113,7 @@ def bench_searches()
semi_Sby_name, semi_Sby_color, semi_Sby_keywords = cached_indexes cars_semi
uncached_Sby_name, uncached_Sby_color, uncached_Sby_keywords = uncached_indexes cars_uncached
fn = ->search_benchmark(DODB::Storage(Car), Int32, String, DODB::Index::Basic(Car), DODB::Index::Partition(Car), DODB::Index::Tags(Car))
fn = ->search_benchmark(DODB::Storage(Car), Int32, String, DODB::Trigger::Index(Car), DODB::Trigger::Partition(Car), DODB::Trigger::Tags(Car))
prepare_env cars_ram, "ram", ram_Sby_name, ram_Sby_color, ram_Sby_keywords, &fn
prepare_env cars_cached, "cached", cached_Sby_name, cached_Sby_color, cached_Sby_keywords, &fn
@ -176,7 +176,7 @@ def bench_50_shades_of_fifo()
fifo_Sby_name5, fifo_Sby_color5, fifo_Sby_keywords5 = cached_indexes cars_fifo5
fifo_Sby_name10, fifo_Sby_color10, fifo_Sby_keywords10 = cached_indexes cars_fifo10
fn = ->search_benchmark(DODB::Storage(Car), Int32, String, DODB::Index::Basic(Car), DODB::Index::Partition(Car), DODB::Index::Tags(Car))
fn = ->search_benchmark(DODB::Storage(Car), Int32, String, DODB::Trigger::Index(Car), DODB::Trigger::Partition(Car), DODB::Trigger::Tags(Car))
prepare_env cars_fifo1, "fifo1", fifo_Sby_name1, fifo_Sby_color1, fifo_Sby_keywords1, &fn
prepare_env cars_fifo5, "fifo5", fifo_Sby_name5, fifo_Sby_color5, fifo_Sby_keywords5, &fn
@ -191,7 +191,7 @@ ENV["NBRUN"]?.try { |it| Context.nb_run = it.to_i }
ENV["DBSIZE"]?.try { |it| Context.to = it.to_i }
ENV["DBSIZE_START"]?.try { |it| Context.from = it.to_i }
ENV["DBSIZE_INCREMENT"]?.try { |it| Context.incr = it.to_i }
ENV["FIFO_SIZE"]?.try { |it| Context.fifo_size = it.to_i }
ENV["FIFO_SIZE"]?.try { |it| Context.fifo_size = it.to_u32 }
pp! Context.nb_run
pp! Context.from

View File

@ -45,7 +45,7 @@ describe "tracking inconsistencies between implementations" do
cars_ram0 = SPECDB::RAMOnly(Car).new "-0"
cars_ram1 = SPECDB::RAMOnly(Car).new "-1"
cars_ram2 = SPECDB::RAMOnly(Car).new "-2"
cars_fifo = SPECDB::FIFO(Car).new "-2", 5
cars_fifo = SPECDB::Common(Car).new "-2", 5
uncached_searchby_name, uncached_searchby_color, uncached_searchby_keywords = uncached_indexes cars_ram0
cached_searchby_name, cached_searchby_color, cached_searchby_keywords = cached_indexes cars_ram1

View File

@ -24,9 +24,10 @@ describe "SPECDB::Common" do
db << car3
db.data.keys.sort.should eq([0, 2, 3] of Int32)
db.fifo.to_s.should eq "[ 3, 0, 2 ]"
db.delete 2
db.data.keys.sort.should eq([0, 3] of Int32)
db.fifo.data.should eq([3, 0] of Int32)
db.fifo.to_s.should eq "[ 3, 0 ]"
end
end

View File

@ -32,5 +32,23 @@ describe "EfficientFIFO" do
fifo.delete 2
fifo.list.to_s.should eq "[ 5, 4 ]"
(fifo << 4).should be_nil # -> nil (just a re-order)
fifo.list.to_s.should eq "[ 4, 5 ]"
fifo.delete 5
(fifo << 0).should be_nil
fifo.list.to_s.should eq "[ 0, 4 ]"
(fifo << 1).should be_nil
fifo.list.to_s.should eq "[ 1, 0, 4 ]"
fifo.delete 4
fifo.list.to_s.should eq "[ 1, 0 ]"
fifo.delete 4
fifo.list.to_s.should eq "[ 1, 0 ]"
fifo.list.size.should eq 2
fifo.hash.size.should eq 2
end
end

View File

@ -39,7 +39,7 @@ class DODB::Storage::Common(V) < DODB::Storage::Cached(V)
# Initializes the `DODB::Storage::Common` database with a maximum number of entries in the cache.
def initialize(@directory_name : String, max_entries : UInt32)
@fifo = FIFO(Int32).new max_entries
@fifo = EfficientFIFO(Int32).new max_entries
Dir.mkdir_p data_path
Dir.mkdir_p locks_directory

View File

@ -48,6 +48,10 @@ class FIFO(V)
def delete(v : V)
@data.select! { |x| v != x }
end
def to_s(io : IO)
data.to_s(io)
end
end
# This class is used to implement a cache policy for `DODB::Storage::Common`.
@ -114,6 +118,11 @@ class EfficientFIFO(V)
def delete(v : V)
if node = hash[v]?
list.delete node
hash.delete v
end
end
def to_s(io : IO)
list.to_s(io)
end
end

View File

@ -92,15 +92,15 @@ class DoubleLinkedList(V)
#
# ```
# list = DoubleLinkedList(Int32).new
# list << 1 << 2 << 3 << 4 # -> [ 1, 2, 3, 4 ]
# list.delete_at 2 # -> [ 1, 2, 4 ]
# list << 1 << 2 << 3 << 4 # -> [ 1, 2, 3, 4 ]
# list.delete Node(Int32).new 2 # -> [ 1, 3, 4 ]
# ```
def delete(n : Node(V)) : Node(V)
if n == @first
@first = n.next
if first = @first
@first = n.next if n.value == first.value
end
if n == @last
@last = n.previous
if last = @last
@last = n.previous if n.value == last.value
end
if prev_node = n.previous
prev_node.next = n.next
@ -434,7 +434,7 @@ class DoubleLinkedList(V)
end
# Fancy print of the list's content.
def to_s(io)
def to_s(io : IO)
io << "[ "
remaining_values = @size
each do |value|