1 # frozen_string_literal: true
4 # Keeps track of what elements are in the queue in
5 # priority and also ensures that when one element
6 # engulfs/covers/eats another that the larger element
7 # evicts the smaller element
8 class PriorityEngulfQueue
10 @queue = PriorityQueue.new
41 private def flush_deleted
42 while @queue&.peek&.deleted?
47 private def prune_engulf(block)
48 # If we're about to pop off the same block, we can skip deleting
49 # things from the frontier this iteration since we'll get it
50 # on the next iteration
51 return if @queue.peek && (block <=> @queue.peek) == 1
53 if block.starts_at != block.ends_at # A block of size 1 cannot engulf another
54 @queue.to_a.each { |b|
55 if b.starts_at >= block.starts_at && b.ends_at <= block.ends_at