@@ -417,7 +417,9 @@ function nextGeneration(dict) {
417417 node [ generationKey ] = 0 ;
418418
419419 // queue all other referenced nodes
420- const nodeStart = Math . imul ( popcount ( node . datamap ) , 2 ) ;
420+ // We need to query the length from the nodemap, as we don't know if this
421+ // is an overflow node or not! if it is, it will never have datamap set!
422+ const nodeStart = data . length - popcount ( node . nodemap ) ;
421423 for ( let i = nodeStart ; i < node . data . length ; ++ i ) {
422424 queue . push ( node . data [ i ] ) ;
423425 }
@@ -521,7 +523,7 @@ function insertIntoNode(transient, node, key, value, hash, shift) {
521523 const childShift = shift + bits ;
522524
523525 let child = emptyNode ;
524- child = insertIntoNode ( transient , emptyNode , key , value , hash , childShift ) ;
526+ child = insertIntoNode ( transient , child , key , value , hash , childShift ) ;
525527
526528 const key2 = data [ dataidx ] ;
527529 const value2 = data [ dataidx + 1 ] ;
@@ -638,7 +640,9 @@ export function map(dict, fun) {
638640 const node = queue . pop ( ) ;
639641 const data = node . data ;
640642 // every node contains popcount(datamap) direct entries
641- const edgesStart = Math . imul ( popcount ( node . datamap ) , 2 ) ;
643+ // We need to query the length from the nodemap, as we don't know if this
644+ // is an overflow node or not! if it is, it will never have datamap set!
645+ const edgesStart = data . length - popcount ( node . nodemap ) ;
642646 for ( let i = 0 ; i < edgesStart ; i += 2 ) {
643647 // we copied the node while queueing it, so direct mutation here is safe.
644648 data [ i + 1 ] = fun ( data [ i ] , data [ i + 1 ] ) ;
@@ -662,7 +666,9 @@ export function fold(dict, state, fun) {
662666 const node = queue . pop ( ) ;
663667 const data = node . data ;
664668 // every node contains popcount(datamap) direct entries
665- const edgesStart = Math . imul ( popcount ( node . datamap ) , 2 ) ;
669+ // We need to query the length from the nodemap, as we don't know if this
670+ // is an overflow node or not! if it is, it will never have datamap set!
671+ const edgesStart = data . length - popcount ( node . nodemap ) ;
666672 for ( let i = 0 ; i < edgesStart ; i += 2 ) {
667673 state = fun ( state , data [ i ] , data [ i + 1 ] ) ;
668674 }
0 commit comments