# Path: cache-simulator/cache_model_evaluation/bintrees/treeslice.py
# class TreeSlice(object):
#     __slots__ = ['_tree', '_start', '_stop']
# 
#     def __init__(self, tree, start, stop):
#         self._tree = tree
#         self._start = start
#         self._stop = stop
# 
#     def __repr__(self):
#         tpl = "%s({%s})" % (self._tree.__class__.__name__, '%s')
#         return tpl % ", ".join( ("%r: %r" % item for item in self.items()) )
# 
#     def __contains__(self, key):
#         if self._is_in_range(key):
#             return key in self._tree
#         else:
#             return False
# 
#     def _is_in_range(self, key):
#         if self._start is not None and key < self._start:
#                 return False
#         if self._stop is not None and key >= self._stop:
#                 return False
#         return True
# 
#     def __getitem__(self, key):
#         if isinstance(key, slice):
#             return self._sub_slice(key.start, key.stop)
#         if self._is_in_range(key):
#             return self._tree[key]
#         else:
#             raise KeyError(key)
# 
#     def _sub_slice(self, start, stop):
#         def newstart():
#             if start is None:
#                 return self._start
#             elif self._start is None:
#                 return start
#             else:
#                 return max(start, self._start)
# 
#         def newstop():
#             if stop is None:
#                 return self._stop
#             elif self._stop is None:
#                 return stop
#             else:
#                 return min(stop, self._stop)
# 
#         return TreeSlice(self._tree, newstart(), newstop())
# 
#     def keys(self):
#         return self._tree.key_slice(self._start, self._stop)
#     __iter__ = keys
# 
#     def values(self):
#         return self._tree.value_slice(self._start, self._stop)
# 
#     def items(self):
#         return self._tree.iter_items(self._start, self._stop)


import sys
from .treeslice import TreeSlice
from operator import attrgetter

        """T.is_empty() -> False if T contains any items else True"""
        return self.count == 0

    def keys(self, reverse=False):
        """T.keys([reverse]) -> an iterator over the keys of T, in ascending
        order if reverse is True, iterate in descending order, reverse defaults
        to False
        """
        return (item[0] for item in self.iter_items(reverse=reverse))
    __iter__ = keys

    def __reversed__(self):
        return self.keys(reverse=True)

    def values(self, reverse=False):
        """T.values([reverse]) -> an iterator over the values of T, in ascending order
        if reverse is True, iterate in descending order, reverse defaults to False
        """
        return (item[1] for item in self.iter_items(reverse=reverse))

    def items(self, reverse=False):
        """T.items([reverse]) -> an iterator over the (key, value) items of T,
        in ascending order if reverse is True, iterate in descending order,
        reverse defaults to False
        """
        return self.iter_items(reverse=reverse)

    def __getitem__(self, key):
        """T.__getitem__(y) <==> x[y]"""
        if isinstance(key, slice):

# Path: cache-simulator/cache_model_evaluation/bintrees/treeslice.py
# class TreeSlice(object):
#     __slots__ = ['_tree', '_start', '_stop']
# 
#     def __init__(self, tree, start, stop):
#         self._tree = tree
#         self._start = start
#         self._stop = stop
# 
#     def __repr__(self):
#         tpl = "%s({%s})" % (self._tree.__class__.__name__, '%s')
#         return tpl % ", ".join( ("%r: %r" % item for item in self.items()) )
# 
#     def __contains__(self, key):
#         if self._is_in_range(key):
#             return key in self._tree
#         else:
#             return False
# 
#     def _is_in_range(self, key):
#         if self._start is not None and key < self._start:
#                 return False
#         if self._stop is not None and key >= self._stop:
#                 return False
#         return True
# 
#     def __getitem__(self, key):
#         if isinstance(key, slice):
#             return self._sub_slice(key.start, key.stop)
#         if self._is_in_range(key):
#             return self._tree[key]
#         else:
#             raise KeyError(key)
# 
#     def _sub_slice(self, start, stop):
#         def newstart():
#             if start is None:
#                 return self._start
#             elif self._start is None:
#                 return start
#             else:
#                 return max(start, self._start)
# 
#         def newstop():
#             if stop is None:
#                 return self._stop
#             elif self._stop is None:
#                 return stop
#             else:
#                 return min(stop, self._stop)
# 
#         return TreeSlice(self._tree, newstart(), newstop())
# 
#     def keys(self):
#         return self._tree.key_slice(self._start, self._stop)
#     __iter__ = keys
# 
#     def values(self):
#         return self._tree.value_slice(self._start, self._stop)
# 
#     def items(self):
#         return self._tree.iter_items(self._start, self._stop)


# Path: cache-simulator/cache_model_evaluation/bintrees/abctree.py
import sys
from .treeslice import TreeSlice
from operator import attrgetter

        """T.is_empty() -> False if T contains any items else True"""
        return self.count == 0

    def keys(self, reverse=False):
        """T.keys([reverse]) -> an iterator over the keys of T, in ascending
        order if reverse is True, iterate in descending order, reverse defaults
        to False
        """
        return (item[0] for item in self.iter_items(reverse=reverse))
    __iter__ = keys

    def __reversed__(self):
        return self.keys(reverse=True)

    def values(self, reverse=False):
        """T.values([reverse]) -> an iterator over the values of T, in ascending order
        if reverse is True, iterate in descending order, reverse defaults to False
        """
        return (item[1] for item in self.iter_items(reverse=reverse))

    def items(self, reverse=False):
        """T.items([reverse]) -> an iterator over the (key, value) items of T,
        in ascending order if reverse is True, iterate in descending order,
        reverse defaults to False
        """
        return self.iter_items(reverse=reverse)

    def __getitem__(self, key):
        """T.__getitem__(y) <==> x[y]"""
        if isinstance(key, slice):

            return TreeSlice(self, key.start, key.stop)
