A list of Intervals. The intervals in the list must not overlap and must be in ascending order.
# File lib/taskjuggler/IntervalList.rb, line 24 24: def &(list) 25: res = IntervalList.new 26: si = li = 0 27: while si < length && li < list.length do 28: if self[si].start < list[li].start 29: # The current Interval of self starts earlier than the current 30: # Interval of list. 31: if self[si].end <= list[li].start 32: # self[si] does not overlap with list[li]. Ignore it. 33: si += 1 34: elsif self[si].end < list[li].end 35: # self[si] does overlap with list[li] but list[li] goes further 36: res << Interval.new(list[li].start, self[si].end) 37: si += 1 38: else 39: # self[si] does overlap with list[li] but self[si] goes further 40: res << Interval.new(list[li].start, list[li].end) 41: li += 1 42: end 43: elsif list[li].start < self[si].start 44: # The current Interval of list starts earlier than the current 45: # Interval of self. 46: if list[li].end <= self[si].start 47: # list[li] does not overlap with self[si]. Ignore it. 48: li += 1 49: elsif list[li].end < self[si].end 50: # list[li] does overlap with self[si] but self[si] goes further 51: res << Interval.new(self[si].start, list[li].end) 52: li += 1 53: else 54: # list[li] does overlap with self[si] but list[li] goes further 55: res << Interval.new(self[si].start, self[si].end) 56: si += 1 57: end 58: else 59: # self[si].start and list[li].start are identical 60: if self[si].end == list[li].end 61: # self[si] and list[li] are identical. Add the Interval and 62: # increase both pointers. 63: res << self[si] 64: li += 1 65: si += 1 66: elsif self[si].end < list[li].end 67: # self[si] ends earlier. 68: res << self[si] 69: si += 1 70: else 71: # list[li] ends earlier. 72: res << list[li] 73: li += 1 74: end 75: end 76: end 77: 78: res 79: end
Append the Interval iv. If the start of iv matches the end of the list list item, iv is merged with the last item.
# File lib/taskjuggler/IntervalList.rb, line 83 83: def <<(iv) 84: if last 85: if last.end > iv.start 86: raise "Intervals may not overlap and must be added in " + 87: "ascending order." 88: elsif last.end == iv.start 89: self[1] = Interval.new(last.start, iv.end) 90: return self 91: end 92: end 93: 94: append(iv) 95: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.