def processSegmentUpdates(self):
    """ Go through the list of accumulated segment updates and process them
    as follows:

    if the segment update is too old, remove the update
    elseif the cell that an update belongs to has it's learnState currently
          set to True (because it was predicted and just received bottom-up), then
          positively re-enforce the synapses that predicted it and remove the update.
    elseif the cell than an update belongs to just had it's predicted state
          turn off, then negatively re-enforce the synapses that predicted it
          and remove the update.
    else leave the update in the queue.

    """

    # =================================================================
    # The segmentUpdates dict has keys which are the column,cellIdx of the
    #  owner cell. The values are lists of segment updates for that cell
    removeKeys = []
    trimSegments = []
    for key, updateList in self.segmentUpdates.iteritems():

      # Get the column number and cell index of the owner cell
      c,i = key[0], key[1]

      # Should we positively or negatively re-enforce the predicting synapses?
      positiveReinforcement = None
      if self.learnState['t'][c,i] == 1:
        positiveReinforcement = True
      elif self.predictedState['t'][c,i] == 0 \
                                and self.predictedState['t-1'][c,i] == 1:
        positiveReinforcement = False

      # Process each segment for this cell. Each segment entry contains
      #  [creationDate, SegmentInfo]
      updateListKeep = []
      for (createDate, segUpdate) in updateList:

        # Decide whether to apply the update now. If update has expired, then
        # delete it. If update was created in Phase1 then apply immediately.
        # Otherwise, if update was not created during this pass then apply now.

        if self.iterationIdx - createDate > self.segUpdateValidDuration:
          # This segment has expired. Ignore this update (and hence remove it from list)
          pass
        elif (segUpdate.phase1Flag or
             self.iterationIdx > createDate) and (positiveReinforcement is not None):
          trimSegment = self.adaptSegment(segUpdate, positiveReinforcement)
          if trimSegment:
            trimSegments.append((segUpdate.columnIdx, segUpdate.cellIdx,
                                    segUpdate.segment))
        else:
          # Keep all updates that don't match the above criteria
          updateListKeep.append((createDate,segUpdate))

      self.segmentUpdates[key] = updateListKeep
      if len(updateListKeep) == 0:
        removeKeys.append(key)


    # =====================================================================
    # Clean out empty segment updates
    for key in removeKeys:
      self.segmentUpdates.pop(key)

    # =====================================================================
    # Trim segments that had synapses go to 0
    for (c, i, segment) in trimSegments:
      self.trimSegmentsInCell(c, i, [segment], minPermanence = 0.00001,
              minNumSyns = 0)