'Reorder template (bubble up) in template list if hits grows enough.
Parameters
num : int
Index of template should be moved.'

def _reorderTemplate(self, num):

    if num:
        templates = self.__templates
        ddtempl = templates[num]
        if (logSys.getEffectiveLevel() <= logLevel):
            logSys.log(logLevel, '        ->    reorder    template    #%02i,    hits:    %r', num, ddtempl.hits)
        untime = (ddtempl.lastUsed - self.__unusedTime)
        weight = ddtempl.weight
        pos = (self.__firstUnused if (self.__firstUnused < num) else (num // 2))
        def _moveable():
            pweight = templates[pos].weight
            if (logSys.getEffectiveLevel() <= logLevel):
                logSys.log(logLevel, '        ->    compare    template    #%02i    &    #%02i,    weight    %.3f    >    %.3f,    hits    %r    >    %r', num, pos, weight, pweight, ddtempl.hits, templates[pos].hits)
            return ((weight > pweight) or (untime > templates[pos].lastUsed))
        if (not _moveable()):
            if (pos == (num - 1)):
                return num
            pos = (num - 1)
            if (not _moveable()):
                return num
        del templates[num]
        templates[pos:0] = [ddtempl]
        while ((self.__firstUnused < len(templates)) and templates[self.__firstUnused].hits):
            self.__firstUnused += 1
        if (logSys.getEffectiveLevel() <= logLevel):
            logSys.log(logLevel, '        ->    moved    template    #%02i    ->    #%02i', num, pos)
        return pos
    return num
