Renamed “N-N partitions” to “tags”.

Increased version number in shard.yml due to the implied API changes.
remotes/1708105384931250775/master
Luka Vandervelden 2019-12-10 20:50:25 +01:00
parent 2f00b56f0c
commit 1a1380d674
3 changed files with 20 additions and 20 deletions

View File

@ -1,5 +1,5 @@
name: fs
version: 0.1.0
version: 0.2.0
authors:
- Luka Vandervelden <lukc@upyum.com>

View File

@ -26,7 +26,7 @@ class FS::Hash(K, V)
end
@partitions = [] of PartitionData(V)
@nn_partitions = [] of NNPartitionData(V)
@tags = [] of NNPartitionData(V)
def initialize(@directory_name : String)
Dir.mkdir_p data_path
@ -48,8 +48,8 @@ class FS::Hash(K, V)
Dir.mkdir_p dir_path_indexes(name)
end
def new_nn_partition(name : String, &block : Proc(V, Array(String)))
@nn_partitions.push NNPartitionData(V).new name, block
def new_tags(name : String, &block : Proc(V, Array(String)))
@tags.push NNPartitionData(V).new name, block
Dir.mkdir_p "#{@directory_name}/.by_nn_#{name}"
end
@ -76,7 +76,7 @@ class FS::Hash(K, V)
r_value
end
def get_nn_partition(name, key : K)
def get_tags(name, key : K)
r_value = Array(V).new
partition_directory = "#{dir_path_nn name}/#{key}"
@ -146,7 +146,7 @@ class FS::Hash(K, V)
end
@nn_partitions.each do |nn|
@tags.each do |nn|
indices = nn.key_proc.call value
indices.each do |index|
@ -193,7 +193,7 @@ class FS::Hash(K, V)
end
end
@nn_partitions.each do |nn|
@tags.each do |nn|
indices = nn.key_proc.call value
indices.each do |index_key|
@ -257,7 +257,7 @@ class FS::Hash(K, V)
end
private def dir_path_nn(name : String)
"#{@directory_name}/nn_partitions/by_#{name}"
"#{@directory_name}/tags/by_#{name}"
end
private def file_path_indexes(key : String, index_name : String)

View File

@ -13,9 +13,9 @@ class Article
end
end
s = FS::Hash(String, Article).new "test-storage-nn"
s = FS::Hash(String, Article).new "test-storage-tags"
s.new_nn_partition "tags", &.tags.map(&.downcase)
s.new_tags "tags", &.tags.map(&.downcase)
article = Article.new "Mutsuki", ["mutsuki", "kuchikukan"]
s[article.id] = article
@ -38,10 +38,10 @@ s[article.id] = article
article = Article.new "Yuudachi", ["shiratsuyu", "kuchikukan"]
s[article.id] = article
pp! s.get_nn_partition("tags", "senkan").map &.title
pp! s.get_nn_partition("tags", "kuchikukan").map &.title
pp! s.get_nn_partition("tags", "mutsuki").map &.title
pp! s.get_nn_partition("tags", "shiratsuyu").map &.title
pp! s.get_tags("tags", "senkan").map &.title
pp! s.get_tags("tags", "kuchikukan").map &.title
pp! s.get_tags("tags", "mutsuki").map &.title
pp! s.get_tags("tags", "shiratsuyu").map &.title
s.to_h.size.times do
first = s.to_h.to_a[0][1]
@ -49,13 +49,13 @@ s.to_h.size.times do
s.delete first.id
pp! s.get_nn_partition("tags", "senkan").map &.title
pp! s.get_nn_partition("tags", "kuchikukan").map &.title
pp! s.get_nn_partition("tags", "mutsuki").map &.title
pp! s.get_nn_partition("tags", "shiratsuyu").map &.title
pp! s.get_tags("tags", "senkan").map &.title
pp! s.get_tags("tags", "kuchikukan").map &.title
pp! s.get_tags("tags", "mutsuki").map &.title
pp! s.get_tags("tags", "shiratsuyu").map &.title
end
puts "Testing get_nn_partition on unknown entries."
puts "Testing get_tags on unknown entries."
pp! s.get_nn_partition("tags", "kaga").map &.title
pp! s.get_tags("tags", "kaga").map &.title