Class: FSEvent::ScheduleMerger
- Inherits:
-
Object
- Object
- FSEvent::ScheduleMerger
- 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
- #first ⇒ Object
-
#initialize(*schedules) ⇒ ScheduleMerger
constructor
A new instance of ScheduleMerger.
- #merge_schedule(s) ⇒ Object
- #shift ⇒ Object
Constructor Details
#initialize(*schedules) ⇒ 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
#first ⇒ Object
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 |
#shift ⇒ Object
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 |