Class: SortedLruFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/hooks/all_files.rb

Overview

Matches suffixes of an array of urls Converts suffixes to prefixes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSortedLruFiles

Returns a new instance of SortedLruFiles.



19
20
21
# File 'lib/hooks/all_files.rb', line 19

def initialize
  @msbs = MSlinnBinarySearch.new %i[url start_with?]
end

Instance Attribute Details

#msbsObject (readonly)

Returns the value of attribute msbs.



17
18
19
# File 'lib/hooks/all_files.rb', line 17

def msbs
  @msbs
end

Instance Method Details

#add_pages(apages) ⇒ Object

Parameters:

  • apages (Array[APage])


24
25
26
27
# File 'lib/hooks/all_files.rb', line 24

def add_pages(apages)
  apages.each { |apage| insert apage.href, apage }
  @msbs.enable_search
end

#enable_searchObject



29
30
31
# File 'lib/hooks/all_files.rb', line 29

def enable_search
  @msbs.enable_search
end

#find(suffix) ⇒ Object



33
34
35
# File 'lib/hooks/all_files.rb', line 33

def find(suffix)
  @msbs.find suffix
end

#insert(url, file) ⇒ Object



37
38
39
40
41
# File 'lib/hooks/all_files.rb', line 37

def insert(url, file)
  lru_file = LruFile.new(url.reverse, file)
  lru_file.new_chain [:url, %i[start_with? placeholder]]
  @msbs.insert(lru_file)
end

#select(suffix) ⇒ Object



43
44
45
# File 'lib/hooks/all_files.rb', line 43

def select(suffix)
  @msbs.select_pages suffix
end