Commit c896acb
Performance optimizations for hierarchical clustering
- Lance-Williams UPGMA update replaces per-pair member enumeration, making
distance maintenance O(n) per merge instead of O(cluster_size²)
- Active-index list (swap-with-last removal) replaces flag array so the
find-minimum loop iterates only live clusters, ~3x fewer comparisons
- Distance matrix computed over upper triangle only and mirrored, halving
initial pairwise computation
- Linked list tracks leaf order in O(1) per merge, replacing index array copies
- clock() check moved outside inner distance-matrix loop (was called n² times)
- rebuildTree rewritten with stable slot IDs, O(n) with no array splices
- clustersGivenK rebuilt using active Set + membership map for stable slot IDs
- Remove unused dummy Float32Array distances allocation and field from ClusterResult
- Add integration tests covering known inputs end-to-end through real WASM
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 956ac78 commit c896acb
8 files changed
Lines changed: 242 additions & 235 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 29 | + | |
| 30 | + | |
32 | 31 | | |
33 | 32 | | |
34 | | - | |
| 33 | + | |
35 | 34 | | |
36 | | - | |
37 | | - | |
| 35 | + | |
38 | 36 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 37 | + | |
| 38 | + | |
48 | 39 | | |
49 | 40 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 41 | + | |
54 | 42 | | |
55 | 43 | | |
56 | 44 | | |
57 | | - | |
58 | 45 | | |
59 | 46 | | |
60 | 47 | | |
| |||
Binary file not shown.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
50 | | - | |
51 | | - | |
| 49 | + | |
52 | 50 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
56 | 54 | | |
57 | 55 | | |
58 | 56 | | |
59 | 57 | | |
60 | | - | |
61 | 58 | | |
62 | 59 | | |
63 | | - | |
64 | 60 | | |
65 | 61 | | |
66 | 62 | | |
67 | 63 | | |
68 | | - | |
69 | 64 | | |
70 | 65 | | |
71 | 66 | | |
| |||
75 | 70 | | |
76 | 71 | | |
77 | 72 | | |
78 | | - | |
| 73 | + | |
79 | 74 | | |
80 | 75 | | |
81 | 76 | | |
82 | 77 | | |
83 | 78 | | |
84 | 79 | | |
85 | | - | |
86 | | - | |
| 80 | + | |
87 | 81 | | |
88 | 82 | | |
89 | 83 | | |
| |||
93 | 87 | | |
94 | 88 | | |
95 | 89 | | |
96 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
97 | 94 | | |
98 | 95 | | |
99 | 96 | | |
| |||
112 | 109 | | |
113 | 110 | | |
114 | 111 | | |
115 | | - | |
116 | 112 | | |
117 | 113 | | |
118 | 114 | | |
| |||
126 | 122 | | |
127 | 123 | | |
128 | 124 | | |
129 | | - | |
130 | 125 | | |
131 | 126 | | |
132 | 127 | | |
| |||
140 | 135 | | |
141 | 136 | | |
142 | 137 | | |
| 138 | + | |
| 139 | + | |
143 | 140 | | |
144 | 141 | | |
145 | 142 | | |
146 | 143 | | |
147 | 144 | | |
148 | 145 | | |
149 | 146 | | |
150 | | - | |
151 | 147 | | |
152 | 148 | | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 149 | + | |
157 | 150 | | |
158 | | - | |
159 | | - | |
160 | 151 | | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
| 152 | + | |
| 153 | + | |
168 | 154 | | |
169 | 155 | | |
170 | | - | |
| 156 | + | |
171 | 157 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | 158 | | |
182 | | - | |
183 | 159 | | |
184 | 160 | | |
0 commit comments