Next / Previous / Contents / Shipman's homepage

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

xnomo3.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 instance ->
              self.__txKeyMap  +:=  entries whose values are the Taxon
                  instances rooted at taxon and whose keys are the
                  .txKey attributes of those Taxon instances
              self.__sciMap    +:=  entries whose values are the Taxon
                  instances rooted at taxon and whose keys are the
                  .sci attributes of those Taxon instances ]
        """

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

xnomo3.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:

xnomo3.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 )