Add features across agents, collab, trust, indexes, and hyperbee.
Manual pass: task cancelTask, workflow topologicalOrder/fail/reset, collab kick/replay, trust trustedPeers and multisig TTL sweep, graph shortestPath, inverted topTerms, dedup filterNew, bee notifyBatch/seekVersion — all with tests. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -103,6 +103,27 @@ class HyperP2PGraphIndex extends EventEmitter {
|
||||
return true
|
||||
}
|
||||
|
||||
shortestPath (from, to, maxHops = 32) {
|
||||
assertNonEmpty(from, 'from')
|
||||
assertNonEmpty(to, 'to')
|
||||
if (from === to) return [from]
|
||||
const queue = [[from]]
|
||||
const visited = new Set([from])
|
||||
while (queue.length) {
|
||||
const path = queue.shift()
|
||||
if (path.length > maxHops) break
|
||||
const node = path[path.length - 1]
|
||||
for (const nbr of this.neighbors(node)) {
|
||||
if (visited.has(nbr)) continue
|
||||
const next = [...path, nbr]
|
||||
if (nbr === to) return next
|
||||
visited.add(nbr)
|
||||
queue.push(next)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
getStats () {
|
||||
return {
|
||||
...this._stats,
|
||||
|
||||
@@ -47,3 +47,12 @@ test('removeEdge outDegree edgeCount', async (t) => {
|
||||
t.is(m.outDegree('a'), 1)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('shortestPath', async (t) => {
|
||||
const m = new HyperP2PGraphIndex()
|
||||
m.addEdge('a', 'b')
|
||||
m.addEdge('b', 'c')
|
||||
t.alike(m.shortestPath('a', 'c'), ['a', 'b', 'c'])
|
||||
t.is(m.shortestPath('a', 'z'), null)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
@@ -104,6 +104,13 @@ class HyperP2PInvertedIndex extends EventEmitter {
|
||||
return this._docs.size
|
||||
}
|
||||
|
||||
topTerms (limit = 10) {
|
||||
const ranked = [...this._terms.entries()]
|
||||
.map(([term, set]) => ({ term, docs: set.size }))
|
||||
.sort((a, b) => b.docs - a.docs)
|
||||
return ranked.slice(0, Math.max(0, limit | 0))
|
||||
}
|
||||
|
||||
_gossip (data) {
|
||||
if (!this._peerMsgs) return
|
||||
gossipSend(this, data)
|
||||
|
||||
@@ -48,3 +48,13 @@ test('searchAll getDocTerms', async (t) => {
|
||||
t.alike(m.getDocTerms('d1'), ['cat', 'dog'])
|
||||
await m.close()
|
||||
})
|
||||
|
||||
test('topTerms', async (t) => {
|
||||
const m = new HyperP2PInvertedIndex()
|
||||
m.index('a', ['x'])
|
||||
m.index('b', ['x', 'y'])
|
||||
m.index('c', ['x'])
|
||||
t.is(m.topTerms(1)[0].term, 'x')
|
||||
t.is(m.topTerms(1)[0].docs, 3)
|
||||
await m.close()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user