Fix FIFO.
parent
188c5a439e
commit
543e1ce80f
|
@ -37,7 +37,7 @@ class DODB::Storage::Stacked(V) < DODB::Storage::Cached(V)
|
|||
property stack : FIFO(Int32)
|
||||
|
||||
# Initializes the `StackedDataBase` with a maximum number of entries in the cache.
|
||||
def initialize(@directory_name : String, max_entries : UInt32 = 100_000)
|
||||
def initialize(@directory_name : String, max_entries : UInt32)
|
||||
@stack = FIFO(Int32).new max_entries
|
||||
Dir.mkdir_p data_path
|
||||
Dir.mkdir_p locks_directory
|
||||
|
|
|
@ -30,7 +30,7 @@ class FIFO(V)
|
|||
# NOTE: `#<<(v : V)` is (almost) the only function since it's enough for the intended use, feel free to improve this.
|
||||
# WARNING: implementation is extremely simple (3 lines) and not designed to be highly efficient.
|
||||
def <<(v : V) : V?
|
||||
@data.select! { |x| v != v } # remove dups
|
||||
@data.select! { |x| v != x } # remove dups
|
||||
@data.unshift v # push on top of the stack
|
||||
@data.pop if @data.size > @max_entries # remove least recently used entry if `@data` is too big
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue