Next / Previous / Contents / Shipman's homepage

4.12. Txny.__addTaxonMaps(): Add a taxon to the internal dictionaries

txny.py
# - - -   T x n y . _ _ a d d T a x o n M a p s   - - -

    def __addTaxonMaps ( self, taxon ):
        """Add a taxon and its descendants to the internal dictionaries.

          [ taxon is a Taxon object ->
              self.__txKeyMap  +:=  entries whose values are the Taxon
                  objects rooted at taxon and whose keys are the
                  .txKey attributes of those Taxon objects
              self.__sciMap    +:=  entries whose values are the Taxon
                  objects rooted at taxon and whose keys are the
                  .sci attributes of those Taxon objects ]
        """

This method is called recursively to visit every Taxon object in the tree. First we take care of the basis case, the Taxon object where we start:

txny.py
        #-- 1 --
        # [ self.__txKeyMap  +:=  an entry whose value is taxon and
        #       whose key is taxon.txKey
        #   self.__sciMap    +:=  an entry whose value is taxon and
        #       whose key is taxon.sci ]
        self.__txKeyMap[taxon.txKey]  =  taxon
        self.__sciMap[taxon.sci]      =  taxon

Then recursively evaluate the subtrees of this taxon:

txny.py
        #-- 2 --
        # [ self.__txKeyMap  +:=  entries whose values are the
        #       descendants of taxon and whose keys are the .txKey
        #       attributes of those descendants
        #   self.__sciMap    +:=  entries whose values are the
        #       descendants of taxon and whose keys are the .sci
        #       attributes of those descendants ]
        for  child in taxon:
            self.__addTaxonMaps ( child )