From 1a1380d674298977e6df2955b725c496720bdcae Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Tue, 10 Dec 2019 20:50:25 +0100 Subject: [PATCH] =?UTF-8?q?Renamed=20=E2=80=9CN-N=20partitions=E2=80=9D=20?= =?UTF-8?q?to=20=E2=80=9Ctags=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Increased version number in shard.yml due to the implied API changes. --- shard.yml | 2 +- src/fs.cr | 14 +++++++------- test-nn.cr => test-tags.cr | 24 ++++++++++++------------ 3 files changed, 20 insertions(+), 20 deletions(-) rename test-nn.cr => test-tags.cr (58%) diff --git a/shard.yml b/shard.yml index ee0dee0..acbdc4d 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: fs -version: 0.1.0 +version: 0.2.0 authors: - Luka Vandervelden diff --git a/src/fs.cr b/src/fs.cr index c78f212..5c0f7df 100644 --- a/src/fs.cr +++ b/src/fs.cr @@ -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) diff --git a/test-nn.cr b/test-tags.cr similarity index 58% rename from test-nn.cr rename to test-tags.cr index b1a7973..89aae50 100644 --- a/test-nn.cr +++ b/test-tags.cr @@ -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