Class: Kudzu::Adapter::Memory::Frontier

Inherits:
Object
  • Object
show all
Defined in:
lib/kudzu/adapter/memory/frontier.rb

Instance Method Summary collapse

Constructor Details

#initialize(uuid) ⇒ Frontier

Returns a new instance of Frontier.


5
6
7
8
9
10
# File 'lib/kudzu/adapter/memory/frontier.rb', line 5

def initialize(uuid)
  @uuid = uuid
  @monitor = Monitor.new
  @queue = []
  @queued = {}
end

Instance Method Details

#clearObject


31
32
33
34
# File 'lib/kudzu/adapter/memory/frontier.rb', line 31

def clear
  @queue.clear
  @queued.clear
end

#dequeue(limit: 1) ⇒ Object


22
23
24
25
26
27
28
29
# File 'lib/kudzu/adapter/memory/frontier.rb', line 22

def dequeue(limit: 1)
  @monitor.synchronize do
    links = @queue.shift(limit)
    links.each do |link|
      link.state = 1
    end
  end
end

#enqueue(links) ⇒ Object


12
13
14
15
16
17
18
19
20
# File 'lib/kudzu/adapter/memory/frontier.rb', line 12

def enqueue(links)
  @monitor.synchronize do
    Array(links).each do |link|
      next if @queued.key?(link.url)
      @queued[link.url] = true
      @queue << link
    end
  end
end