Renamed “N-N partitions” to “tags”.
Increased version number in shard.yml due to the implied API changes.
This commit is contained in:
parent
2f00b56f0c
commit
1a1380d674
@ -1,5 +1,5 @@
|
|||||||
name: fs
|
name: fs
|
||||||
version: 0.1.0
|
version: 0.2.0
|
||||||
|
|
||||||
authors:
|
authors:
|
||||||
- Luka Vandervelden <lukc@upyum.com>
|
- Luka Vandervelden <lukc@upyum.com>
|
||||||
|
14
src/fs.cr
14
src/fs.cr
@ -26,7 +26,7 @@ class FS::Hash(K, V)
|
|||||||
end
|
end
|
||||||
|
|
||||||
@partitions = [] of PartitionData(V)
|
@partitions = [] of PartitionData(V)
|
||||||
@nn_partitions = [] of NNPartitionData(V)
|
@tags = [] of NNPartitionData(V)
|
||||||
|
|
||||||
def initialize(@directory_name : String)
|
def initialize(@directory_name : String)
|
||||||
Dir.mkdir_p data_path
|
Dir.mkdir_p data_path
|
||||||
@ -48,8 +48,8 @@ class FS::Hash(K, V)
|
|||||||
Dir.mkdir_p dir_path_indexes(name)
|
Dir.mkdir_p dir_path_indexes(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_nn_partition(name : String, &block : Proc(V, Array(String)))
|
def new_tags(name : String, &block : Proc(V, Array(String)))
|
||||||
@nn_partitions.push NNPartitionData(V).new name, block
|
@tags.push NNPartitionData(V).new name, block
|
||||||
|
|
||||||
Dir.mkdir_p "#{@directory_name}/.by_nn_#{name}"
|
Dir.mkdir_p "#{@directory_name}/.by_nn_#{name}"
|
||||||
end
|
end
|
||||||
@ -76,7 +76,7 @@ class FS::Hash(K, V)
|
|||||||
r_value
|
r_value
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_nn_partition(name, key : K)
|
def get_tags(name, key : K)
|
||||||
r_value = Array(V).new
|
r_value = Array(V).new
|
||||||
|
|
||||||
partition_directory = "#{dir_path_nn name}/#{key}"
|
partition_directory = "#{dir_path_nn name}/#{key}"
|
||||||
@ -146,7 +146,7 @@ class FS::Hash(K, V)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@nn_partitions.each do |nn|
|
@tags.each do |nn|
|
||||||
indices = nn.key_proc.call value
|
indices = nn.key_proc.call value
|
||||||
|
|
||||||
indices.each do |index|
|
indices.each do |index|
|
||||||
@ -193,7 +193,7 @@ class FS::Hash(K, V)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@nn_partitions.each do |nn|
|
@tags.each do |nn|
|
||||||
indices = nn.key_proc.call value
|
indices = nn.key_proc.call value
|
||||||
|
|
||||||
indices.each do |index_key|
|
indices.each do |index_key|
|
||||||
@ -257,7 +257,7 @@ class FS::Hash(K, V)
|
|||||||
end
|
end
|
||||||
|
|
||||||
private def dir_path_nn(name : String)
|
private def dir_path_nn(name : String)
|
||||||
"#{@directory_name}/nn_partitions/by_#{name}"
|
"#{@directory_name}/tags/by_#{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
private def file_path_indexes(key : String, index_name : String)
|
private def file_path_indexes(key : String, index_name : String)
|
||||||
|
@ -13,9 +13,9 @@ class Article
|
|||||||
end
|
end
|
||||||
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"]
|
article = Article.new "Mutsuki", ["mutsuki", "kuchikukan"]
|
||||||
s[article.id] = article
|
s[article.id] = article
|
||||||
@ -38,10 +38,10 @@ s[article.id] = article
|
|||||||
article = Article.new "Yuudachi", ["shiratsuyu", "kuchikukan"]
|
article = Article.new "Yuudachi", ["shiratsuyu", "kuchikukan"]
|
||||||
s[article.id] = article
|
s[article.id] = article
|
||||||
|
|
||||||
pp! s.get_nn_partition("tags", "senkan").map &.title
|
pp! s.get_tags("tags", "senkan").map &.title
|
||||||
pp! s.get_nn_partition("tags", "kuchikukan").map &.title
|
pp! s.get_tags("tags", "kuchikukan").map &.title
|
||||||
pp! s.get_nn_partition("tags", "mutsuki").map &.title
|
pp! s.get_tags("tags", "mutsuki").map &.title
|
||||||
pp! s.get_nn_partition("tags", "shiratsuyu").map &.title
|
pp! s.get_tags("tags", "shiratsuyu").map &.title
|
||||||
|
|
||||||
s.to_h.size.times do
|
s.to_h.size.times do
|
||||||
first = s.to_h.to_a[0][1]
|
first = s.to_h.to_a[0][1]
|
||||||
@ -49,13 +49,13 @@ s.to_h.size.times do
|
|||||||
|
|
||||||
s.delete first.id
|
s.delete first.id
|
||||||
|
|
||||||
pp! s.get_nn_partition("tags", "senkan").map &.title
|
pp! s.get_tags("tags", "senkan").map &.title
|
||||||
pp! s.get_nn_partition("tags", "kuchikukan").map &.title
|
pp! s.get_tags("tags", "kuchikukan").map &.title
|
||||||
pp! s.get_nn_partition("tags", "mutsuki").map &.title
|
pp! s.get_tags("tags", "mutsuki").map &.title
|
||||||
pp! s.get_nn_partition("tags", "shiratsuyu").map &.title
|
pp! s.get_tags("tags", "shiratsuyu").map &.title
|
||||||
end
|
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user