nheight
This commit is contained in:
parent
3474e536fc
commit
a91ab94771
@ -47,7 +47,7 @@ RUN git fetch && git checkout f81543a34ee363dcc00e8632fd7cfcd4a3478b23
|
|||||||
ENV SRCDIR="."
|
ENV SRCDIR="."
|
||||||
ENV SRCPATTERN="*.[ach]*"
|
ENV SRCPATTERN="*.[ach]*"
|
||||||
|
|
||||||
FROM metrics-radn as metrics-repo
|
FROM metrics-cargo as metrics-repo
|
||||||
|
|
||||||
FROM metrics-repo as metrics-commits
|
FROM metrics-repo as metrics-commits
|
||||||
COPY common.py /code/common.py
|
COPY common.py /code/common.py
|
||||||
|
@ -4,22 +4,33 @@ from subprocess import check_output
|
|||||||
|
|
||||||
from common import counter
|
from common import counter
|
||||||
|
|
||||||
|
BITS = 7
|
||||||
|
|
||||||
|
def mask(height: int) -> int:
|
||||||
|
return ((1 << height.bit_length()) - 1) >> BITS
|
||||||
|
|
||||||
|
def valid(commit: str, height: int) -> bool:
|
||||||
|
expected = int.from_bytes(bytes.fromhex(commit), "little")
|
||||||
|
return mask(height) & (height ^ expected) == 0
|
||||||
|
|
||||||
args = []
|
args = []
|
||||||
original_commits = check_output(["git", "log", "--pretty=%H", *args], text=True).splitlines()
|
original_commits = check_output(["git", "log", "--pretty=%H", *args], text=True).splitlines()
|
||||||
N = len(original_commits)
|
N = len(original_commits)
|
||||||
BITS = 10
|
|
||||||
total_changes: dict[str, tuple[int, int]] = {}
|
total_changes: dict[str, tuple[int, int]] = {}
|
||||||
chosen_parents: dict[str, str | None] = {}
|
chosen_parents: dict[str, str | None] = {}
|
||||||
heights: dict[str, int] = {}
|
heights: dict[str, int] = {}
|
||||||
|
nheights: dict[str, int] = {}
|
||||||
included = set()
|
included = set()
|
||||||
for i, commit in enumerate(reversed(original_commits)):
|
for i, commit in enumerate(reversed(original_commits)):
|
||||||
print(f"C={i / N:6f}", flush=True)
|
print(f"C={i / N:6f}", flush=True)
|
||||||
parents = check_output(["git", "log", "--pretty=%P", "-n", "1", commit], text=True).split()
|
parents = check_output(["git", "log", "--pretty=%P", "-n", "1", commit], text=True).split()
|
||||||
|
parents = [parent for parent in parents if parent in heights]
|
||||||
chosen_parent = None
|
chosen_parent = None
|
||||||
height = 1 + max((heights[parent] for parent in parents), default=0)
|
height = 1 + max((heights[parent] for parent in parents), default=0)
|
||||||
mask = ((1 << height.bit_length()) - 1) >> BITS
|
nheight = 1 + min((nheights[parent] for parent in parents), default=0)
|
||||||
expected = int.from_bytes(bytes.fromhex(commit), "little")
|
if valid(commit, height) or nheight > mask(height):
|
||||||
if mask & (height ^ expected) == 0:
|
included.add(commit)
|
||||||
|
nheight = 0
|
||||||
ctr = counter(commit, True)
|
ctr = counter(commit, True)
|
||||||
changes = ctr.total(), 1
|
changes = ctr.total(), 1
|
||||||
for parent in parents:
|
for parent in parents:
|
||||||
@ -36,7 +47,6 @@ for i, commit in enumerate(reversed(original_commits)):
|
|||||||
if maybe_changes > changes:
|
if maybe_changes > changes:
|
||||||
changes = maybe_changes
|
changes = maybe_changes
|
||||||
chosen_parent = parent
|
chosen_parent = parent
|
||||||
included.add(commit)
|
|
||||||
else:
|
else:
|
||||||
changes = 0, 1
|
changes = 0, 1
|
||||||
for parent in parents:
|
for parent in parents:
|
||||||
@ -51,6 +61,7 @@ for i, commit in enumerate(reversed(original_commits)):
|
|||||||
assert chosen_parent is None or chosen_parent in included
|
assert chosen_parent is None or chosen_parent in included
|
||||||
chosen_parents[commit] = chosen_parent
|
chosen_parents[commit] = chosen_parent
|
||||||
heights[commit] = height
|
heights[commit] = height
|
||||||
|
nheights[commit] = nheight
|
||||||
commit = original_commits[0]
|
commit = original_commits[0]
|
||||||
commits = []
|
commits = []
|
||||||
while commit is not None:
|
while commit is not None:
|
||||||
|
@ -13,7 +13,7 @@ C = min(len(commits), 720)
|
|||||||
for i, commit in enumerate(reversed(commits)):
|
for i, commit in enumerate(reversed(commits)):
|
||||||
print(f"P={i / len(commits):6f}", flush=True)
|
print(f"P={i / len(commits):6f}", flush=True)
|
||||||
print("running", commit, flush=True)
|
print("running", commit, flush=True)
|
||||||
current_ctr = counter(commit, True)
|
current_ctr = counter(commit, False)
|
||||||
added = current_ctr - last_ctr
|
added = current_ctr - last_ctr
|
||||||
deleted = last_ctr - current_ctr
|
deleted = last_ctr - current_ctr
|
||||||
entries.append((i, current_ctr.total(), added.total(), deleted.total()))
|
entries.append((i, current_ctr.total(), added.total(), deleted.total()))
|
||||||
|
Loading…
Reference in New Issue
Block a user