// Intersect creates a new slice of values that are included in all given arrays.
// The order of values in the result is random.
Intersect creates a new slice of values that are included in all given arrays.
The order of values in the result is random.
// Intersect creates a new slice of values that are included in all given arrays . // The order of values in the result is random .
func Intersect(s []uint32, more ...[]uint32) Uint32s {
	type count struct {
		slices  int
		maxHits int
	}
	counts := make(map[uint32]count)
	for _, e := range s {
		if c, ok := counts[e]; ok {
			c.maxHits++
			counts[e] = c
		} else {
			counts[e] = count{slices: 1, maxHits: 1}
		}
	}
	for _, x := range more {
		hits := make(map[uint32]int)
		for _, e := range x {
			if v, ok := hits[e]; ok {
				hits[e] = v + 1
			} else {
				hits[e] = 1
			}
		}
		for k, v := range hits {
			if c, ok := counts[k]; ok {
				if c.maxHits > v {
					c.maxHits = v
				}
				c.slices++
				counts[k] = c
			}
		}
	}
	var m Uint32s
	for e, c := range counts {
		if c.slices >= len(more)+1 {
			for i := 0; i < c.maxHits; i++ {
				m = append(m, e)
			}
		}
	}
	return m
}
func Intersect ( s [ ] uint32 , more ... [ ] uint32 ) Uint32s { type count struct { slices int maxHits int } counts := make ( map [ uint32 ] count ) for _ , e := range s { if c , ok := counts [ e ] ; ok { c . maxHits ++ counts [ e ] = c } else { counts [ e ] = count { slices : 1 , maxHits : 1 } } } for _ , x := range more { hits := make ( map [ uint32 ] int ) for _ , e := range x { if v , ok := hits [ e ] ; ok { hits [ e ] = v + 1 } else { hits [ e ] = 1 } } for k , v := range hits { if c , ok := counts [ k ] ; ok { if c . maxHits > v { c . maxHits = v } c . slices ++ counts [ k ] = c } } } var m Uint32s for e , c := range counts { if c . slices >= len ( more ) + 1 { for i := 0 ; i < c . maxHits ; i ++ { m = append ( m , e ) } } } return m }
Intersect creates a new slice of values that are included in all given arrays.
Intersect creates a new slice of values that are included in all given arrays .