Compare commits
No commits in common. "cf57773a259c46c706fd2b9360794af396bb6254" and "fbdb451f0ee0e8dae78245241fdd6415db3eb367" have entirely different histories.
cf57773a25
...
fbdb451f0e
13
spec/test.cr
13
spec/test.cr
@ -4,9 +4,6 @@ require "file_utils"
|
|||||||
require "../src/dodb.cr"
|
require "../src/dodb.cr"
|
||||||
require "./test-data.cr"
|
require "./test-data.cr"
|
||||||
|
|
||||||
def fork_process(&)
|
|
||||||
Process.new Crystal::System::Process.fork { yield }
|
|
||||||
end
|
|
||||||
|
|
||||||
class DODB::SpecDataBase < DODB::DataBase(Ship)
|
class DODB::SpecDataBase < DODB::DataBase(Ship)
|
||||||
def initialize(storage_ext = "", remove_previous_data = true)
|
def initialize(storage_ext = "", remove_previous_data = true)
|
||||||
@ -226,7 +223,7 @@ describe "DODB::DataBase" do
|
|||||||
}.should be_true
|
}.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
db_ships_by_class.get?("does-not-exist").should eq nil
|
db_ships_by_class.get("does-not-exist").should eq [] of Ship
|
||||||
end
|
end
|
||||||
|
|
||||||
it "removes select elements from partitions" do
|
it "removes select elements from partitions" do
|
||||||
@ -412,7 +409,7 @@ describe "DODB::DataBase" do
|
|||||||
processes = [] of Process
|
processes = [] of Process
|
||||||
|
|
||||||
fork_count.times do |fork_id|
|
fork_count.times do |fork_id|
|
||||||
processes << fork_process do
|
processes << Process.fork do
|
||||||
entries_per_fork.times do |entry_id|
|
entries_per_fork.times do |entry_id|
|
||||||
db << Ship.new("entry-#{fork_id}-#{entry_id}", "???")
|
db << Ship.new("entry-#{fork_id}-#{entry_id}", "???")
|
||||||
end
|
end
|
||||||
@ -433,7 +430,7 @@ describe "DODB::DataBase" do
|
|||||||
# First pass, creating data.
|
# First pass, creating data.
|
||||||
processes = [] of Process
|
processes = [] of Process
|
||||||
fork_count.times do |fork_id|
|
fork_count.times do |fork_id|
|
||||||
processes << fork_process do
|
processes << Process.fork do
|
||||||
entries_per_fork.times do |entry_id|
|
entries_per_fork.times do |entry_id|
|
||||||
db << Ship.new("entry-#{fork_id}-#{entry_id}", "???")
|
db << Ship.new("entry-#{fork_id}-#{entry_id}", "???")
|
||||||
end
|
end
|
||||||
@ -444,7 +441,7 @@ describe "DODB::DataBase" do
|
|||||||
# Second pass, updating data.
|
# Second pass, updating data.
|
||||||
processes = [] of Process
|
processes = [] of Process
|
||||||
fork_count.times do |fork_id|
|
fork_count.times do |fork_id|
|
||||||
processes << fork_process do
|
processes << Process.fork do
|
||||||
entries_per_fork.times do |entry_id|
|
entries_per_fork.times do |entry_id|
|
||||||
db_entries_by_name.update Ship.new("entry-#{fork_id}-#{entry_id}", "???", tags: ["updated"])
|
db_entries_by_name.update Ship.new("entry-#{fork_id}-#{entry_id}", "???", tags: ["updated"])
|
||||||
end
|
end
|
||||||
@ -474,7 +471,7 @@ describe "DODB::DataBase" do
|
|||||||
|
|
||||||
processes = [] of Process
|
processes = [] of Process
|
||||||
fork_count.times do |fork_id|
|
fork_count.times do |fork_id|
|
||||||
processes << fork_process do
|
processes << Process.fork do
|
||||||
entries_per_fork.times do |entry_id|
|
entries_per_fork.times do |entry_id|
|
||||||
db_entries_by_name.safe_get "test" do |entry|
|
db_entries_by_name.safe_get "test" do |entry|
|
||||||
entry.klass = (entry.klass.to_i + 1).to_s
|
entry.klass = (entry.klass.to_i + 1).to_s
|
||||||
|
@ -43,11 +43,12 @@ class DODB::Partition(V) < DODB::Indexer(V)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get(partition) : Array(V)
|
def get(partition) : Array(V)
|
||||||
partition_directory = indexing_directory partition
|
|
||||||
raise MissingEntry.new(@name, partition) unless Dir.exists? partition_directory
|
|
||||||
|
|
||||||
r_value = Array(V).new
|
r_value = Array(V).new
|
||||||
|
|
||||||
|
partition_directory = indexing_directory partition
|
||||||
|
|
||||||
|
return r_value unless Dir.exists? partition_directory
|
||||||
|
|
||||||
Dir.each_child partition_directory do |child|
|
Dir.each_child partition_directory do |child|
|
||||||
r_value << @storage[get_key child]
|
r_value << @storage[get_key child]
|
||||||
end
|
end
|
||||||
|
@ -42,11 +42,12 @@ class DODB::Tags(V) < DODB::Indexer(V)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_with_indice(tag : String) : Array(Tuple(V, Int32))
|
def get_with_indice(tag : String) : Array(Tuple(V, Int32))
|
||||||
tag_directory = indexing_directory tag
|
|
||||||
raise MissingEntry.new(@name, tag) unless Dir.exists? tag_directory
|
|
||||||
|
|
||||||
r_value = Array(Tuple(V, Int32)).new
|
r_value = Array(Tuple(V, Int32)).new
|
||||||
|
|
||||||
|
tag_directory = indexing_directory tag
|
||||||
|
|
||||||
|
return r_value unless Dir.exists? tag_directory
|
||||||
|
|
||||||
Dir.each_child tag_directory do |child|
|
Dir.each_child tag_directory do |child|
|
||||||
key = get_key child
|
key = get_key child
|
||||||
r_value << { @storage[key], key }
|
r_value << { @storage[key], key }
|
||||||
@ -55,18 +56,10 @@ class DODB::Tags(V) < DODB::Indexer(V)
|
|||||||
r_value
|
r_value
|
||||||
end
|
end
|
||||||
|
|
||||||
# `get_with_indices` gets values with all the tags.
|
|
||||||
|
|
||||||
def get_with_indices(keys : Array(String)) : Array(Tuple(V, Int32))
|
def get_with_indices(keys : Array(String)) : Array(Tuple(V, Int32))
|
||||||
r_value = Array(Tuple(V, Int32)).new
|
r_value = Array(Tuple(V, Int32)).new
|
||||||
return r_value if keys.size < 1
|
|
||||||
|
|
||||||
first_key = keys.pop
|
|
||||||
r_value = get_with_indice(first_key) rescue return [] of Tuple(V, Int32)
|
|
||||||
|
|
||||||
keys.each do |tag|
|
keys.each do |tag|
|
||||||
values = get_with_indice(tag) rescue return [] of Tuple(V, Int32)
|
r_value.concat get_with_indice tag
|
||||||
r_value &= values
|
|
||||||
end
|
end
|
||||||
r_value
|
r_value
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user