Path 1: 1092 calls (0.74)

LineSet (1092)

4 (1058) 6 (34)

tuple (1092)

1def hash_lineset(
2    lineset: LineSet, min_common_lines: int = DEFAULT_MIN_SIMILARITY_LINE
3) -> tuple[HashToIndex_T, IndexToLines_T]:
4    """Return two dicts.
5
6    The first associates the hash of successive stripped lines of a lineset
7    to the indices of the starting lines.
8    The second dict, associates the index of the starting line in the lineset's stripped lines to the
9    couple [start, end] lines number in the corresponding file.
10
11    :param lineset: lineset object (i.e the lines in a file)
12    :param min_common_lines: number of successive lines that are used to compute the hash
13    :return: a dict linking hashes to corresponding start index and a dict that links this
14             index to the start and end lines in the file
15    """
16    hash2index = defaultdict(list)
17    index2lines = {}
18    # Comments, docstring and other specific patterns maybe excluded -> call to stripped_lines
19    # to get only what is desired
20    lines = tuple(x.text for x in lineset.stripped_lines)
21    # Need different iterators on same lines but each one is shifted 1 from the precedent
22    shifted_lines = [iter(lines[i:]) for i in range(min_common_lines)]
23
24    for i, *succ_lines in enumerate(zip(*shifted_lines)):
25        start_linenumber = LineNumber(lineset.stripped_lines[i].line_number)
26        try:
27            end_linenumber = lineset.stripped_lines[i + min_common_lines].line_number
28        except IndexError:
29            end_linenumber = LineNumber(lineset.stripped_lines[-1].line_number + 1)
30
31        index = Index(i)
32        index2lines[index] = SuccessiveLinesLimits(
33            start=start_linenumber, end=end_linenumber
34        )
35
36        l_c = LinesChunk(lineset.name, index, *succ_lines)
37        hash2index[l_c].append(index)
38
39    return hash2index, index2lines
            

Path 2: 388 calls (0.26)

LineSet (388)

4 (388)

tuple (388)

IndexError (388)

1def hash_lineset(
2    lineset: LineSet, min_common_lines: int = DEFAULT_MIN_SIMILARITY_LINE
3) -> tuple[HashToIndex_T, IndexToLines_T]:
4    """Return two dicts.
5
6    The first associates the hash of successive stripped lines of a lineset
7    to the indices of the starting lines.
8    The second dict, associates the index of the starting line in the lineset's stripped lines to the
9    couple [start, end] lines number in the corresponding file.
10
11    :param lineset: lineset object (i.e the lines in a file)
12    :param min_common_lines: number of successive lines that are used to compute the hash
13    :return: a dict linking hashes to corresponding start index and a dict that links this
14             index to the start and end lines in the file
15    """
16    hash2index = defaultdict(list)
17    index2lines = {}
18    # Comments, docstring and other specific patterns maybe excluded -> call to stripped_lines
19    # to get only what is desired
20    lines = tuple(x.text for x in lineset.stripped_lines)
21    # Need different iterators on same lines but each one is shifted 1 from the precedent
22    shifted_lines = [iter(lines[i:]) for i in range(min_common_lines)]
23
24    for i, *succ_lines in enumerate(zip(*shifted_lines)):
25        start_linenumber = LineNumber(lineset.stripped_lines[i].line_number)
26        try:
27            end_linenumber = lineset.stripped_lines[i + min_common_lines].line_number
28        except IndexError:
29            end_linenumber = LineNumber(lineset.stripped_lines[-1].line_number + 1)
30
31        index = Index(i)
32        index2lines[index] = SuccessiveLinesLimits(
33            start=start_linenumber, end=end_linenumber
34        )
35
36        l_c = LinesChunk(lineset.name, index, *succ_lines)
37        hash2index[l_c].append(index)
38
39    return hash2index, index2lines