1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# PMAT-1055 (adversarial-verify): a SINGLE class that COMBINES the recent OOP
# codegen slices in one differential fixture — the combination the per-slice
# fixtures don't reach. Covers:
# * class constants folded across methods (str BASE + int WEIGHT/HOT), never
# emitted as struct fields (PMAT-1054);
# * an empty-dict field seeded from `{}` via the class-body K/V annotation,
# grown by `self.buckets[k].append(v)` grouping (PMAT-1052/1037);
# * a parallel insertion-order list so `trail()` PROVES dict iteration order
# == insertion order (indexmap parity with CPython dict);
# * a class-constant threshold read inside a nested loop (HOT);
# * negative-index read-back through a field (`keys_seen[-1]`);
# * a class constant in overflow-checked multiplication (WEIGHT).
# Differentially verified vs CPython (MATCH 'Hzam' / 2 / 6 / 'm').
class Histo:
BASE: str = "H"
WEIGHT: int = 3
HOT: int = 10
buckets: dict[str, list[int]]
keys_seen: list[str]
def __init__(self) -> None:
self.buckets = {}
self.keys_seen = []
def record(self, k: str, v: int) -> None:
if k not in self.buckets:
self.buckets[k] = []
self.keys_seen.append(k)
self.buckets[k].append(v)
def trail(self) -> str:
out: str = self.BASE
for k in self.buckets:
out += k
return out
def hot_count(self) -> int:
c: int = 0
for k in self.buckets:
for v in self.buckets[k]:
if v > self.HOT:
c += 1
return c
def weighted(self, k: str) -> int:
return len(self.buckets[k]) * self.WEIGHT
def newest(self) -> str:
return self.keys_seen[-1]
def combo_trail() -> str:
h: Histo = Histo()
h.record("z", 1)
h.record("a", 20)
h.record("z", 15)
h.record("m", 2)
return h.trail()
def combo_hot() -> int:
h: Histo = Histo()
h.record("z", 1)
h.record("a", 20)
h.record("z", 15)
h.record("m", 2)
return h.hot_count()
def combo_weighted() -> int:
h: Histo = Histo()
h.record("z", 1)
h.record("z", 9)
return h.weighted("z")
def combo_newest() -> str:
h: Histo = Histo()
h.record("z", 1)
h.record("a", 2)
h.record("m", 3)
return h.newest()