# Path: gala/iterprogress.py
# class NoProgressBar(object):
#     def __init__(self, *args, **kwargs): pass
#     def start(self, *args, **kwargs): pass
#     def update(self, *args, **kwargs): pass
#     def update_i(self, *args, **kwargs): pass
#     def finish(self, *args, **kwargs): pass
#     def set_title(self, *args, **kwargs): pass
# 
# class StandardProgressBar(object):
#     def __init__(self, title='Progress: '):
#         self.title = title
#         self.is_finished = False
# 
#     def start(self, total, widgets=None):
#         if widgets is None:
#             widgets = [self.title, RotatingMarker(), ' ',
#                         Percentage(), ' ', Bar(marker='='), ' ', ETA()]
#         self.pbar = ProgressBar(widgets=widgets, maxval=total)
#         self.pbar.start()
#         self.i = 0
# 
#     def update(self, step=1):
#         self.i += step
#         self.pbar.update(self.i)
#         if self.i == self.pbar.maxval:
#             self.finish()
# 
#     def update_i(self, value):
#         self.i = value
#         self.pbar.update(value)
#         if value == self.pbar.maxval:
#             self.finish()
# 
#     def finish(self):
#         if self.is_finished:
#             pass
#         else:
#             self.pbar.finish()
#             self.is_finished = True
# 
#     def set_title(self, title):
#         self.title = title


from heapq import heapify, heappush, heappop
from .iterprogress import NoProgressBar, StandardProgressBar
    def peek(self):
        while not self.q[0][1]:
            heappop(self.q)
        return self.q[0]

    def pop(self):
        self.pop = self.pop_no_start
        self.pbar.start(self.original_length)
        return self.pop_no_start()

    def pop_no_start(self):
        try:
            while not self.q[0][1]:
                _ = heappop(self.q)
        except IndexError:
            raise IndexError('pop from empty merge queue')
        item = heappop(self.q)
        self.invalidate(item)
        self.pbar.update_i(self.original_length - self.num_valid_items)
        return item

    def push(self, item):
        self.is_null_queue = False
        self.push = self.push_next
        self.push_next(item)

    def push_next(self, item):
        heappush(self.q, item)
        self.num_valid_items += 1


# Path: gala/iterprogress.py
# class NoProgressBar(object):
#     def __init__(self, *args, **kwargs): pass
#     def start(self, *args, **kwargs): pass
#     def update(self, *args, **kwargs): pass
#     def update_i(self, *args, **kwargs): pass
#     def finish(self, *args, **kwargs): pass
#     def set_title(self, *args, **kwargs): pass
# 
# class StandardProgressBar(object):
#     def __init__(self, title='Progress: '):
#         self.title = title
#         self.is_finished = False
# 
#     def start(self, total, widgets=None):
#         if widgets is None:
#             widgets = [self.title, RotatingMarker(), ' ',
#                         Percentage(), ' ', Bar(marker='='), ' ', ETA()]
#         self.pbar = ProgressBar(widgets=widgets, maxval=total)
#         self.pbar.start()
#         self.i = 0
# 
#     def update(self, step=1):
#         self.i += step
#         self.pbar.update(self.i)
#         if self.i == self.pbar.maxval:
#             self.finish()
# 
#     def update_i(self, value):
#         self.i = value
#         self.pbar.update(value)
#         if value == self.pbar.maxval:
#             self.finish()
# 
#     def finish(self):
#         if self.is_finished:
#             pass
#         else:
#             self.pbar.finish()
#             self.is_finished = True
# 
#     def set_title(self, title):
#         self.title = title


# Path: gala/mergequeue.py
from heapq import heapify, heappush, heappop
from .iterprogress import NoProgressBar, StandardProgressBar

    def peek(self):
        while not self.q[0][1]:
            heappop(self.q)
        return self.q[0]

    def pop(self):
        self.pop = self.pop_no_start
        self.pbar.start(self.original_length)
        return self.pop_no_start()

    def pop_no_start(self):
        try:
            while not self.q[0][1]:
                _ = heappop(self.q)
        except IndexError:
            raise IndexError('pop from empty merge queue')
        item = heappop(self.q)
        self.invalidate(item)
        self.pbar.update_i(self.original_length - self.num_valid_items)
        return item

    def push(self, item):
        self.is_null_queue = False
        self.push = self.push_next
        self.push_next(item)

    def push_next(self, item):
        heappush(self.q, item)
        self.num_valid_items += 1


    def invalidate(self, item):