@@ -252,38 +252,52 @@ export class SearchCluster implements SearchSpace {
252252 // and then reconverge at later points. If the split happens before such
253253 // a divergence-reconvergence sequence, it is possible for left-hand side
254254 // entries to be duplicated.
255- const resultsWithCluster : [ SearchCluster , SearchSpace ] [ ] = [ ] ;
255+ //
256+ // Deduplicate clusters based solely on spaceId, though; an intact cluster
257+ // should match on this basis alone.
258+ const headClusterResultMap : Map < number , {
259+ head : SearchCluster ,
260+ tails : SearchPath [ ]
261+ } > = new Map ( ) ;
256262
257- const resultMap = new Map < string , {
263+ const headPathResultMap = new Map < string , {
258264 heads : SearchPath [ ] ,
259265 tails : SearchPath [ ]
260266 } > ( ) ;
267+
261268 results . forEach ( ( result ) => {
262269 const [ head , tail ] = result ;
263270
264- // Is certainly possible.
265271 if ( head instanceof SearchCluster ) {
266- resultsWithCluster . push ( [ head , tail ] ) ;
272+ const bucket = headClusterResultMap . get ( head . spaceId ) ?? { head, tails : [ ] } ;
273+ bucket . tails . push ( tail ) ;
274+ headClusterResultMap . set ( head . spaceId , bucket ) ;
267275 return ;
268276 }
269277
270278 let key = head . inputCount + '+' + ( ! ( head instanceof SearchPath ) ? '' : head . clusterKey ) ;
271- const outerEntry = resultMap . get ( key ) ?? { heads : [ ] , tails : [ ] } ;
279+ const outerEntry = headPathResultMap . get ( key ) ?? { heads : [ ] , tails : [ ] } ;
272280
273281 if ( ! outerEntry . heads . find ( p => head . isSameSpace ( p ) ) ) {
274282 outerEntry . heads . push ( head as SearchPath ) ;
275283 }
276284
277285 outerEntry . tails . push ( tail ) ;
278- resultMap . set ( key , outerEntry ) ;
286+ headPathResultMap . set ( key , outerEntry ) ;
279287 } ) ;
280288
281- const resultsFromPaths = [ ...resultMap . values ( ) ] . map ( ( entry ) => {
289+ const resultsFromClusterHeadPaths = [ ...headClusterResultMap . values ( ) ] . map ( ( entry ) => {
290+ const tailSpace = entry . tails . length > 1 ? new SearchCluster ( entry . tails ) : entry . tails [ 0 ] ;
291+ return [ entry . head , tailSpace ] as [ SearchSpace , SearchSpace ] ;
292+ } ) ;
293+
294+ const resultsFromHeadPaths = [ ...headPathResultMap . values ( ) ] . map ( ( entry ) => {
282295 const headSpace = entry . heads . length > 1 ? new SearchCluster ( entry . heads ) : entry . heads [ 0 ] ;
283296 const tailSpace = entry . tails . length > 1 ? new SearchCluster ( entry . tails ) : entry . tails [ 0 ] ;
284297 return [ headSpace , tailSpace ] as [ SearchSpace , SearchSpace ] ;
285298 } ) ;
286- return ( resultsWithCluster as [ SearchSpace , SearchSpace ] [ ] ) . concat ( resultsFromPaths ) ;
299+
300+ return resultsFromClusterHeadPaths . concat ( resultsFromHeadPaths ) ;
287301 }
288302
289303 isSameSpace ( space : SearchSpace ) : boolean {
0 commit comments