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