Next / Previous / Contents / TCC Help System / NM Tech homepage

4.13. SkipList.__compareItemKey()

This small routine compares two keys, one from a _SkipItem and one in the key domain.

pyskip.py
# - - -   S k i p L i s t . _ _ c o m p a r e I t e m K e y   - - -

    def __compareItemKey ( self, skipItem, keyB ):
        """Compare the key from a _SkipItem to a key in the key domain.

          [ return cmp ( key-of ( skipItem's child ), keyB ) ]
        """

First we get the key from skipItem; see Section 4.9, “SkipList.__keyOf().

pyskip.py
        #-- 1 --
        # [ keyA  :=  key-of ( skipItem's child ) ]
        keyA  =  self.__keyOf ( skipItem.child )

We increment self.nCompares, the count of the number of comparison operations. Then we use Python's built-in cmp() function to do the comparison, returning its result as our result.

pyskip.py
        #-- 2 --
        self.nCompares  =  self.nCompares + 1
        return cmp ( keyA, keyB )