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

4.20. SkipList.__searchPrecedes()

This is a predicate used to test whether a given _SkipItem precedes the item with a given key.

pyskip.py
# - - -   S k i p L i s t . _ _ s e a r c h P r e c e d e s   - - -

    def __searchPrecedes ( self, skipItem, key ):
        """Does this item precede the item with a given key?

          [ ( skipItem is a _SkipItem ) and
            ( key is in self's key domain) ->
                if search-precedes ( skipItem, key ) ->
                  return 1
                else ->
                  return 0 ]
        """

Eliminate the case where skipItem is the terminator, because that item never precedes anything. Then use the .__compareItemKey() method to do the actual comparison.

pyskip.py
        #-- 1 --
        if  skipItem is self.__terminator:
            return 0

        #-- 2 --
        # [ if cmp ( key-of(skipItem's child), key ) < 0 ->
        #     return 1
        #   else ->
        #     return 0 ]
        if  self.__compareItemKey ( skipItem, key ) < 0:
            return 1
        else:
            return 0