// finds keys that are present in all dimensions
finds keys that are present in all dimensions
// finds keys that are present in all dimensions
func Intersection(input ...*Dimension) []Key {
	if len(input) == 0 {
		return []Key{}
	} else if len(input) == 1 {
		return input[0].keys
	}
	result := []Key{}
	dims := []*sortableDim{}
	for _, v := range input {
		if len(v.keys) == 0 {
			return []Key{}
		}
		v.m.RLock()
		defer v.m.RUnlock()
		dims = append(dims, &sortableDim{
			keys: v.keys,
			i:    0,
			l:    len(v.keys),
		})
	}
	for {
		sd := sortableDims(dims)
		sort.Sort(sd)
		val := dims[0].current()
		allMatch := true
		for _, dim := range sd[1:] {
			res := dim.advance(val)
			switch res {
			case noMatch:
				allMatch = false
			case end:
				return result
			}
		}
		if allMatch {
			result = append(result, val)
		}
		for _, dim := range sd {
			dim.i++
			if dim.i == dim.l {
				return result
			}
		}
	}
}
func Intersection ( input ... * Dimension ) [ ] Key { if len ( input ) == 0 { return [ ] Key { } } else if len ( input ) == 1 { return input [ 0 ] . keys } result := [ ] Key { } dims := [ ] * sortableDim { } for _ , v := range input { if len ( v . keys ) == 0 { return [ ] Key { } } v . m . RLock ( ) defer v . m . RUnlock ( ) dims = append ( dims , & sortableDim { keys : v . keys , i : 0 , l : len ( v . keys ) , } ) } for { sd := sortableDims ( dims ) sort . Sort ( sd ) val := dims [ 0 ] . current ( ) allMatch := true for _ , dim := range sd [ 1 : ] { res := dim . advance ( val ) switch res { case noMatch : allMatch = false case end : return result } } if allMatch { result = append ( result , val ) } for _ , dim := range sd { dim . i ++ if dim . i == dim . l { return result } } } }
finds keys that are present in all dimensions
finds keys that are present in all dimensions
// kinda ugly imo // step 1: find the dimension with the smallest element // step 2: for each other dimension move the pointer until found the matching element or an element higher // step 3: if all series are on the same matching element, add it to result