Maximum string borders by Knuth-Morris-Pratt

    :param w: string
    :returns: table f such that f[i] is the longest border length of w[:i + 1]
    :complexity: linear
548709
def maximum_border_length(w):
    
    n = len(w)
    f = [0] * n                # init f[0] = 0
    k = 0                      # current longest border length
    for i in range(1, n):      # compute f[i]
        while w[k] != w[i] and k > 0:
            k = f[k - 1]       # try shorter lengths
        if w[k] == w[i]:       # last caracters match
            k += 1             # we can increment the border length
        f[i] = k               # we found the maximal border of w[:i + 1]
    return f
286936
def _dump_linestring(obj, big_endian, meta):
    
    coords = obj['coordinates']
    vertex = coords[0]
    # Infer the number of dimensions from the first vertex
    num_dims = len(vertex)

    wkb_string, byte_fmt, byte_order = _header_bytefmt_byteorder(
        'LineString', num_dims, big_endian, meta
    )
    # append number of vertices in linestring
    wkb_string += struct.pack('%sl' % byte_order, len(coords))

    for vertex in coords:
        wkb_string += struct.pack(byte_fmt, *vertex)

    return wkb_string
88160
def _maxlength(X):
    
    return np.fromiter((map(lambda x: len(x), X)), dtype=int).max()
823496
public static void borderTable(XWPFTable table, int size) {
        CTTblPr tblPr = getTblPr(table);
        CTTblBorders tblBorders = tblPr.getTblBorders();
        BigInteger borderSize = BigInteger.valueOf(size);
        tblBorders.getBottom().setSz(borderSize);
        tblBorders.getLeft().setSz(borderSize);
        tblBorders.getTop().setSz(borderSize);
        tblBorders.getRight().setSz(borderSize);
        tblBorders.getInsideH().setSz(borderSize);
        tblBorders.getInsideV().setSz(borderSize);
    }
1343128
def _longest_val_in_column(self, col):
        
        try:
            # +2 is for implicit separator
            return max([len(x[col]) for x in self.table if x[col]]) + 2
        except KeyError:
            logger.error("there is no column %r", col)
            raise
131706
def max_end(self):
        
        return max(len(self.input_string), self._max_end) if self.input_string else self._max_end
93771
def _longest_contig(self, contig_set, contig_lengths):
        ''''''
        longest_name = None
        max_length = -1
        for name in contig_set:
            if contig_lengths[name] > max_length:
                longest_name = name
                max_length = contig_lengths[name]
        assert max_length != -1
        assert longest_name is not None
        return longest_name
1335514
def maximumORFLength(self, openORFs=True):
        
        return max(len(orf) for orf in self.ORFs(openORFs))
2951
def _max_lengths():
    
    max_header_length = max([len(x.byte_match) + x.offset
                             for x in magic_header_array])
    max_footer_length = max([len(x.byte_match) + abs(x.offset)
                             for x in magic_footer_array])
    return max_header_length, max_footer_length
1077569
def maximum_length(text)
      lines = text.split(/\n/, -1)
      display_width(lines.max_by { |line| display_width(line) } || '')
    end
830573
def fmt_border(self, dimensions, t = 'm', border_style = 'utf8.a', border_formating = {}):
        
        cells = []
        for column in dimensions:
            cells.append(self.bchar('h', t, border_style) * (dimensions[column] + 2))

        border = '{}{}{}'.format(self.bchar('l', t, border_style), self.bchar('m', t, border_style).join(cells), self.bchar('r', t, border_style))
        return self.fmt_text(border, **border_formating)
457863
def longest_non_repeat_v1(string):
    
    if string is None:
        return 0
    dict = {}
    max_length = 0
    j = 0
    for i in range(len(string)):
        if string[i] in dict:
            j = max(dict[string[i]], j)
        dict[string[i]] = i + 1
        max_length = max(max_length, i - j + 1)
    return max_length
1122415
def longest(args):
    
    from jcvi.formats.sizes import Sizes

    p = OptionParser(longest.__doc__)
    p.add_option("--maxsize", default=20000, type="int",
                 help="Limit max size")
    p.add_option("--minsize", default=60, type="int",
                 help="Limit min size")
    p.add_option("--precedence", default="Medtr",
                 help="Accessions with prefix take precedence")
    opts, args = p.parse_args(args)

    if len(args) != 2:
        sys.exit(not p.print_help())

    bedfile, fastafile = args
    maxsize = opts.maxsize
    minsize = opts.minsize
    prec = opts.precedence
    mergedbed = mergeBed(bedfile, nms=True)
    sizes = Sizes(fastafile).mapping
    bed = Bed(mergedbed)

    pf = bedfile.rsplit(".", 1)[0]
    ids = set()
    for b in bed:
        accns = b.accn.split(";")
        prec_accns = [x for x in accns if x.startswith(prec)]
        if prec_accns:
            accns = prec_accns
        accn_sizes = [(sizes.get(x, 0), x) for x in accns]
        accn_sizes = [(size, x) for size, x in accn_sizes if size < maxsize]
        if not accn_sizes:
            continue
        max_size, max_accn = max(accn_sizes)
        if max_size < minsize:
            continue
        ids.add(max_accn)

    newids = remove_isoforms(ids)
    logging.debug("Remove isoforms: before={0} after={1}".\
                    format(len(ids), len(newids)))

    longestidsfile = pf + ".longest.ids"
    fw = open(longestidsfile, "w")
    print("\n".join(newids), file=fw)
    fw.close()
    logging.debug("A total of {0} records written to `{1}`.".\
                    format(len(newids), longestidsfile))

    longestbedfile = pf + ".longest.bed"
    some([bedfile, longestidsfile, "--outfile={0}".format(longestbedfile),
            "--no_strip_names"])
445924
def longest_lines(shape):
    
    lines = []
    for level in set(shape):
        count = 0
        for i in range(len(shape)):
            if shape[i] <= level:
                count += 1
            elif count:
                lines.append({'row': level, 'col': i - count + 1, 'len': count})
                count = 0
        if count:
            lines.append({'row': level, 'col': i - count + 2, 'len': count})

    return sorted(lines, key=lambda l: l['row'])
897463
def edge_just(left, right, width, fillchar=' ', min_padding_length=1):
    
    assert unicode_width(fillchar) == 1, 'fillchar must be single-width char'
    padding = fillchar * max(min_padding_length, width - unicode_width(left + right))
    return left + padding + right
1115168
def full_line_width(self):
        
        bar_str_len = sum([
            self._indent,
            ((len(self.title) + 1) if self._title_pos in ["left", "right"]
             else 0),  # Title if present
            len(self.start_char),
            self.max_width,  # Progress bar
            len(self.end_char),
            1,  # Space between end_char and amount_complete_str
            len(str(self.max_value)) * 2 + 1  # 100/100
        ])
        return bar_str_len
953092
def find_largest_contig(contig_lengths_dict):
    
    # Initialise the dictionary
    longest_contig_dict = dict()
    for file_name, contig_lengths in contig_lengths_dict.items():
        # As the list is sorted in descending order, the largest contig is the first entry in the list
        longest_contig_dict[file_name] = contig_lengths[0]
    return longest_contig_dict