@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
48 lines • 1.58 kB
JavaScript
/** Per-owner readiness, independent of counted references: one leaf can unblock many rows/trees. */
export class CompactCommitDependencies {
constructor(store, ready) {
this.pending = new Map();
this.dependants = new Map();
this.store = store;
store.subscribeCommitted((id) => {
const keys = this.dependants.get(id);
this.dependants.delete(id);
for (const key of keys ?? []) {
const pending = this.pending.get(key);
pending?.delete(id);
if (pending?.size === 0) {
this.pending.delete(key);
ready(key);
}
}
});
}
get size() {
return this.pending.size;
}
has(key) {
return this.pending.has(key);
}
set(key, refs) {
this.delete(key);
const pending = new Set(refs.filter((id) => !this.store.isCommitted(id)));
if (pending.size === 0)
return;
this.pending.set(key, pending);
for (const id of pending) {
const keys = this.dependants.get(id) ?? new Set();
keys.add(key);
this.dependants.set(id, keys);
}
}
delete(key) {
for (const id of this.pending.get(key) ?? []) {
const keys = this.dependants.get(id);
keys?.delete(key);
if (keys?.size === 0)
this.dependants.delete(id);
}
this.pending.delete(key);
}
}
//# sourceMappingURL=compact-commit-dependencies.js.map