'Extracts all elements from the TopN. This is a destructive operation.
The only method that can be called immediately after extract() is reset().
Args:
sort: Whether to return the elements in descending sorted order.
Returns:
A list of data; the top n elements provided to the set.'

def extract(self, sort=False):

    assert (self._data is not None)
    data = self._data
    self._data = None
    if sort:
        data.sort(reverse=True)
    return data
