class DpStmMap::ReferenceCounts

Public Class Methods

new(references_dir) click to toggle source
# File lib/dp_stm_map/Manager.rb, line 153
def initialize references_dir
  @references_dir=references_dir
  FileUtils.mkdir_p(references_dir) unless File.exist?(references_dir)
  @cache=ThreadSafeLru::LruCache.new 9000
end

Public Instance Methods

add_reference(r) click to toggle source
# File lib/dp_stm_map/Manager.rb, line 163
def add_reference r
  count=0
  @cache.get(r) do |ref|
    count=File.open(file_name(ref),"r") {|f| f.read().to_i} if File.exist? file_name(ref)
  end
  File.open(file_name(r),"w") {|f| f.write(count+1)}
  @cache.drop(r)
end
file_name(ref) click to toggle source
# File lib/dp_stm_map/Manager.rb, line 159
def file_name ref
  "#{@references_dir}/#{ref}"
end
has_references?(r) click to toggle source
# File lib/dp_stm_map/Manager.rb, line 178
def has_references? r
  count=0
  @cache.get(r) do |ref|
    count=File.open(file_name(ref),"r") {|f| f.read().to_i} if File.exist? file_name(ref)
  end
  count > 0
end
remove_reference(ref) click to toggle source
# File lib/dp_stm_map/Manager.rb, line 172
def remove_reference ref
  count=File.open(file_name(ref),"r") {|f| f.read().to_i}
  File.open(file_name(ref),"w") {|f| f.write(count-1)}
  @cache.drop(ref)
end