func Intersection(input ...*Dimension) []Key {
	if len(input) == 0 {
		return []Key{}
	} else if len(input) == 1 {
		return input[0].Keys
	}
	r := make(map[string]int)
	for _, v := range input {
		for _, k := range v.Keys {
			r[string(k)]++
		}
	}
	var res []Key
	for k, v := range r {
		if v == len(input) {
			res = append(res, []byte(k))
		}
	}
	return res
}
finds keys that are present in all dimensions
package dimension
import (
	"bytes"
	"sort"
	"sync"
)
type Key []byte
type Dimension struct {
	m sync.RWMutex
	Keys []Key
}
func New() *Dimension {
	return &Dimension{
		Keys: []Key{},
	}
}
func (d *Dimension) Insert(key Key) {
	d.m.Lock()
	defer d.m.Unlock()
	i := sort.Search(len(d.Keys), func(i int) bool {
		return bytes.Compare(d.Keys[i], key) >= 0
	})
	if i < len(d.Keys) && bytes.Equal(d.Keys[i], key) {
		return
	}
	if i > len(d.Keys)-1 || !bytes.Equal(d.Keys[i], key) {
		d.Keys = append(d.Keys, key)
		copy(d.Keys[i+1:], d.Keys[i:])
		d.Keys[i] = key
	}
}
func (d *Dimension) Delete(key Key) {
	d.m.Lock()
	defer d.m.Unlock()
	i := sort.Search(len(d.Keys), func(i int) bool {
		return bytes.Compare(d.Keys[i], key) >= 0
	})
	if i < len(d.Keys) && bytes.Equal(d.Keys[i], key) {
		d.Keys = append(d.Keys[:i], d.Keys[i+1:]...)
		return
	}
}
type advanceResult int
const (
	match advanceResult = iota
	noMatch
	end
)
type sortableDim struct {
	keys []Key
	i    int
	l    int
}
func (sd *sortableDim) current() Key {
	return sd.keys[sd.i]
}
func (sd *sortableDim) advance(cmp Key) advanceResult {
	for {
		v := bytes.Compare(sd.current(), cmp)
		switch v {
		case 0:
			return match
		case 1:
			return noMatch
		}
		sd.i++
		if sd.i == sd.l {
			return end
		}
	}
}
type sortableDims []*sortableDim
func (s sortableDims) Len() int {
	return len(s)
}
func (s sortableDims) Less(i, j int) bool {
	return bytes.Compare(s[i].current(), s[j].current()) >= 0
}
func (s sortableDims) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}