Reimplemented entries data-structure to Hash.

This commit is contained in:
Tristan Ancelet 2024-05-18 18:17:03 -05:00
parent 2125a2f9d5
commit db3e99e1c9

View File

@ -220,7 +220,7 @@ class Bucket
def initialize (clientbucketdir) def initialize (clientbucketdir)
log "Bucket is being created from #{clientbucketdir}" log "Bucket is being created from #{clientbucketdir}"
@bucketdir = clientbucketdir @bucketdir = clientbucketdir
@entries = Array.new @entries = Hash.new
load_bucket load_bucket
end end
@ -229,7 +229,7 @@ class Bucket
Dir["#{@bucketdir}/**/paths"].each.map{|path| File.dirname(path)}.each do |directory| Dir["#{@bucketdir}/**/paths"].each.map{|path| File.dirname(path)}.each do |directory|
log "\"#{directory}\" was grabbed from bucket directory. Making new BucketEntry" log "\"#{directory}\" was grabbed from bucket directory. Making new BucketEntry"
entry = BucketEntry.new(directory) entry = BucketEntry.new(directory)
@entries.push(entry) @entries[entry.hash]=entry
log "BucketEntry[#{entry.hash}] was added to @entries Size=#{@entries.count()}" log "BucketEntry[#{entry.hash}] was added to @entries Size=#{@entries.count()}"
end end
log "Bucket[#{@bucketdir}] was loaded" log "Bucket[#{@bucketdir}] was loaded"
@ -244,7 +244,7 @@ end
def search_entries_paths (bucket) def search_entries_paths (bucket)
log "user entered" log "user entered"
bucket.entries.each do |entry| bucket.entries.each_value do |entry|
log "checking Entry[#{entry.hash}]" log "checking Entry[#{entry.hash}]"
if entry.path_include? $CONFIG[:search_term] if entry.path_include? $CONFIG[:search_term]
puts entry.inline_info puts entry.inline_info
@ -254,23 +254,21 @@ end
def get_content_of_entry_hash (bucket) def get_content_of_entry_hash (bucket)
log "user entered" log "user entered"
bucket.entries.each do |entry| if bucket.entries.has_key? $CONFIG[:search_term]
log "checking Entry[#{entry.hash}]" puts bucket.entries[$CONFIG[:search_term]].content
if entry.hash == $CONFIG[:search_term] else
log "BucketEntry[#{entry.hash}] Matched. Getting contents" puts "There were no entries corresponding to #{$CONFIG[:search_term]}"
puts entry.content exit
exit
end
end end
end end
def list_all_entries (bucket) def list_all_entries (bucket)
puts bucket.entries.each.map{|entry| entry.inline_info}.sort.join("\n") puts bucket.entries.each_value.each.map{|entry| entry.inline_info}.sort.join("\n")
end end
def list_entry_files (bucket) def list_entry_files (bucket)
filenames = Array.new filenames = Array.new
bucket.entries.each do |entry| bucket.entries.each_value do |entry|
entry.filepaths.each do |path| entry.filepaths.each do |path|
if not filenames.include? path if not filenames.include? path
filenames.push(path) filenames.push(path)