src/utils.js
// Comppute the neighborMasksByHop and neighborMasks (all hops combined)
Comppute the neighborMasksByHop and neighborMasks (all hops combined)
Comppute the neighborMasksByHop and neighborMasks ( all hops combined )
function computeNeighborMasks(numNodes, edgeDict, hops) {
    const masks = [],
        masksByHop = [];
    let last;
    for (let i = 0; i < numNodes; i++) {
        masks.push(bs(0));
        masks[i].set(i, 1);
    }
    for (let sid = 0; sid < edgeDict.length; sid++) {
        for (let targetNode of edgeDict[sid]) {
            const tid = targetNode.nid;
            masks[sid].set(tid, 1);
            masks[tid].set(sid, 1);
        }
    }
    masksByHop.push(masks.map((m) => m.clone()));
    last = masksByHop[0];
    for (let h = 1; h < hops; h++) {
        const cur = [];
        for (let i = 0; i < numNodes; i++) {
            cur.push(bs(0));
        }
        for (let i = 0; i < numNodes; i++) {
            let m = masks[i];
            for (let sid of m.toArray()) {
                for (let targetNode of edgeDict[sid]) {
                    m.set(targetNode.nid, 1);
                }
            }
            for (let sid of last[i].toArray()) {
                for (let targetNode of edgeDict[sid]) {
                    cur[i].set(targetNode.nid, 1);
                }
            }
        }
        masksByHop.push(cur);
        last = cur;
    }
    return { neighborMasks: masks, neighborMasksByHop: masksByHop };
}
function computeNeighborMasks ( numNodes , edgeDict , hops ) { const masks = [ ] , masksByHop = [ ] ; let last ; for ( let i = 0 ; i < numNodes ; i ++ ) { masks . push ( bs ( 0 ) ) ; masks [ i ] . set ( i , 1 ) ; } for ( let sid = 0 ; sid < edgeDict . length ; sid ++ ) { for ( let targetNode of edgeDict [ sid ] ) { const tid = targetNode . nid ; masks [ sid ] . set ( tid , 1 ) ; masks [ tid ] . set ( sid , 1 ) ; } } masksByHop . push ( masks . map ( ( m ) => m . clone ( ) ) ) ; last = masksByHop [ 0 ] ; for ( let h = 1 ; h < hops ; h ++ ) { const cur = [ ] ; for ( let i = 0 ; i < numNodes ; i ++ ) { cur . push ( bs ( 0 ) ) ; } for ( let i = 0 ; i < numNodes ; i ++ ) { let m = masks [ i ] ; for ( let sid of m . toArray ( ) ) { for ( let targetNode of edgeDict [ sid ] ) { m . set ( targetNode . nid , 1 ) ; } } for ( let sid of last [ i ] . toArray ( ) ) { for ( let targetNode of edgeDict [ sid ] ) { cur [ i ] . set ( targetNode . nid , 1 ) ; } } } masksByHop . push ( cur ) ; last = cur ; } return { neighborMasks : masks , neighborMasksByHop : masksByHop } ; }
Comppute the neighborMasksByHop and neighborMasks (all hops combined)
Comppute the neighborMasksByHop and neighborMasks ( all hops combined )
// include self // first hop // hop > 1