def killUselessSwarms(self):
<EOL>numExistingSprints = len(self._state['<STR_LIT>'])<EOL>if self._hsObj._searchType == HsSearchType.legacyTemporal:<EOL><INDENT>if numExistingSprints <= <NUM_LIT:2>:<EOL><INDENT>return<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if numExistingSprints <= <NUM_LIT:1>:<EOL><INDENT>return<EOL><DEDENT><DEDENT>completedSwarms = self.getCompletedSwarms()<EOL>completedSwarms = [(swarm, self._state["<STR_LIT>"][swarm],<EOL>self._state["<STR_LIT>"][swarm]["<STR_LIT>"])for swarm in completedSwarms]<EOL>completedMatrix = [[] for i in range(numExistingSprints)]<EOL>for swarm in completedSwarms:<EOL><INDENT>completedMatrix[swarm[<NUM_LIT:1>]["<STR_LIT>"]].append(swarm)<EOL><DEDENT>for sprint in completedMatrix:<EOL><INDENT>sprint.sort(key=itemgetter(<NUM_LIT:2>))<EOL><DEDENT>activeSwarms = self.getActiveSwarms()<EOL>activeSwarms.extend(self.getCompletingSwarms())<EOL>activeSwarms = [(swarm, self._state["<STR_LIT>"][swarm],<EOL>self._state["<STR_LIT>"][swarm]["<STR_LIT>"])for swarm in activeSwarms]<EOL>activeMatrix = [[] for i in range(numExistingSprints)]<EOL>for swarm in activeSwarms:<EOL><INDENT>activeMatrix[swarm[<NUM_LIT:1>]["<STR_LIT>"]].append(swarm)<EOL><DEDENT>for sprint in activeMatrix:<EOL><INDENT>sprint.sort(key=itemgetter(<NUM_LIT:2>))<EOL><DEDENT>toKill = []<EOL>for i in range(<NUM_LIT:1>, numExistingSprints):<EOL><INDENT>for swarm in activeMatrix[i]:<EOL><INDENT>curSwarmEncoders = swarm[<NUM_LIT:0>].split("<STR_LIT:.>")<EOL>if(len(activeMatrix[i-<NUM_LIT:1>])==<NUM_LIT:0>):<EOL><INDENT>if i==<NUM_LIT:2> and (self._hsObj._tryAll3FieldCombinations orself._hsObj._tryAll3FieldCombinationsWTimestamps):<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>bestInPrevious = completedMatrix[i-<NUM_LIT:1>][<NUM_LIT:0>]<EOL>bestEncoders = bestInPrevious[<NUM_LIT:0>].split('<STR_LIT:.>')<EOL>for encoder in bestEncoders:<EOL><INDENT>if not encoder in curSwarmEncoders:<EOL><INDENT>toKill.append(swarm)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if len(toKill) > <NUM_LIT:0>:<EOL><INDENT>print("<STR_LIT>" + str(toKill))<EOL><DEDENT>for swarm in toKill:<EOL><INDENT>self.setSwarmState(swarm[<NUM_LIT:0>], "<STR_LIT>")<EOL><DEDENT>return<EOL>
See if we can kill off some speculative swarms. If an earlier sprint
        has finally completed, we can now tell which fields should *really* be present
        in the sprints we've already started due to speculation, and kill off the
        swarms that should not have been included.