github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/storage/primary/intersect.go (about)

     1  package primary
     2  
     3  import (
     4  	"github.com/onflow/flow-go/model/flow"
     5  )
     6  
     7  func intersectHelper[
     8  	T1 any,
     9  	T2 any,
    10  ](
    11  	smallSet map[flow.RegisterID]T1,
    12  	largeSet map[flow.RegisterID]T2,
    13  ) (
    14  	bool,
    15  	flow.RegisterID,
    16  ) {
    17  	for id := range smallSet {
    18  		_, ok := largeSet[id]
    19  		if ok {
    20  			return true, id
    21  		}
    22  	}
    23  
    24  	return false, flow.RegisterID{}
    25  }
    26  
    27  func intersect[
    28  	T1 any,
    29  	T2 any,
    30  ](
    31  	set1 map[flow.RegisterID]T1,
    32  	set2 map[flow.RegisterID]T2,
    33  ) (
    34  	bool,
    35  	flow.RegisterID,
    36  ) {
    37  	if len(set1) > len(set2) {
    38  		return intersectHelper(set2, set1)
    39  	}
    40  
    41  	return intersectHelper(set1, set2)
    42  }