Class: FSEvent::ScheduleMerger

Inherits:
Object
  • Object
show all
Defined in:
lib/fsevent/schedulemerger.rb

Overview

schedulemerger.rb — merge multiple schedules

Copyright © 2014 National Institute of Advanced Industrial Science and Technology (AIST)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <www.gnu.org/licenses/>.

Instance Method Summary collapse

Constructor Details

#initialize(*schedules) ⇒ ScheduleMerger

Returns a new instance of ScheduleMerger.



19
20
21
22
23
24
# File 'lib/fsevent/schedulemerger.rb', line 19

def initialize(*schedules)
  @q = Depq.new
  schedules.each {|s|
    merge_schedule(s)
  }
end

Instance Method Details

#clearObject



48
49
50
51
52
# File 'lib/fsevent/schedulemerger.rb', line 48

def clear
  until @q.empty?
    @q.delete_min
  end
end

#firstObject



33
34
35
36
# File 'lib/fsevent/schedulemerger.rb', line 33

def first
  return nil if @q.empty?
  @q.find_min_priority[1]
end

#merge_schedule(s) ⇒ Object



26
27
28
29
30
31
# File 'lib/fsevent/schedulemerger.rb', line 26

def merge_schedule(s)
  t = s.shift
  if t
    @q.insert s, t
  end
end

#shiftObject



38
39
40
41
42
43
44
45
46
# File 'lib/fsevent/schedulemerger.rb', line 38

def shift
  return nil if @q.empty?
  s, t = @q.delete_min_priority
  t2 = s.shift
  if t2
    @q.insert s, t2
  end
  t
end