// Ring1 returns the value of ((a*b) + a).
550700
func (c C) Ring1(val Input) Input {
	if v, ok := val.(C); ok {
		return C((c * v) + c)
	}
	return val.Ring1(c)
}
1358754
func (ins Inputs) Ring1(val Input) Input {
	converted := make([]Input, len(ins))
	for i, in := range ins {
		converted[i] = in.Ring1(val)
	}
	return Inputs(converted)
}
681486
func Dot4(a, b *T) float32 {
	return a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3]
}
979042
func (ns *Namespace) Add(a, b interface{}) (interface{}, error) {
	return _math.DoArithmetic(a, b, '+')
}
742716
func Ring(b orb.Bound, r orb.Ring) orb.Ring {
	result := ring(b, r)
	if len(result) == 0 {
		return nil
	}

	return result
}
130985
func (r *Ring) mod(p int) int {
	return p % len(r.buff)
}
525344
func Div(a, b []float64) {
	b = b[:len(a)]
	for i, v := range a {
		if b[i] == 0 {
			a[i] = math.Inf(0)
			continue
		}

		a[i] = v / b[i]
	}
}
840725
func (gf *GaloisField) Multiply(a, b int) int {
	if a == 0 || b == 0 {
		return 0
	}
	return gf.ALogTbl[(gf.LogTbl[a]+gf.LogTbl[b])%(gf.Size-1)]
}
332064
func (m *Map) B(a interface{}) interface{} {
	if b, ok := m.mapAToB[a]; ok {
		return b
	}
	return m.defaultB
}
872411
func ring(box orb.Bound, in orb.Ring) orb.Ring {
	var out orb.Ring
	if len(in) == 0 {
		return in
	}

	f := in[0]
	l := in[len(in)-1]

	initClosed := false
	if f == l {
		initClosed = true
	}

	for edge := 1; edge <= 8; edge <<= 1 {
		out = out[:0]

		loopTo := len(in)

		// if we're not a nice closed ring, don't implicitly close it.
		prev := in[loopTo-1]
		if !initClosed {
			prev = in[0]
		}

		prevInside := bitCode(box, prev)&edge == 0

		for i := 0; i < loopTo; i++ {
			p := in[i]
			inside := bitCode(box, p)&edge == 0

			// if segment goes through the clip window, add an intersection
			if inside != prevInside {
				i := intersect(box, edge, prev, p)
				out = append(out, i)
			}
			if inside {
				out = append(out, p)
			}

			prev = p
			prevInside = inside
		}

		if len(out) == 0 {
			return nil
		}

		in, out = out, in
	}
	out = in // swap back

	if initClosed {
		// need to make sure our output is also closed.
		if l := len(out); l != 0 {
			f := out[0]
			l := out[l-1]

			if f != l {
				out = append(out, f)
			}
		}
	}

	return out
}
1154483
func binOpRing1(rate int8, x, y Input, numOutputs int) Input {
	CheckRate(rate)
	return NewInput(BinOpUgenName, rate, BinOpRing1, numOutputs, x, y)
}
370990
func (u *Ugen) Ring1(val Input) Input {
	return binOpRing1(u.Rate, u, val, u.NumOutputs)
}
748178
func (u *Ugen) Ring2(val Input) Input {
	return binOpRing2(u.Rate, u, val, u.NumOutputs)
}
411768
func Add(a, b *T) T {
	return T{a[0] + b[0], a[1] + b[1], a[2] + b[2]}
}
967723
func (c *ringShards) rebalance() {
	c.mu.RLock()
	shards := c.shards
	c.mu.RUnlock()

	hash := newConsistentHash(c.opt)
	var shardsNum int
	for name, shard := range shards {
		if shard.IsUp() {
			hash.Add(name)
			shardsNum++
		}
	}

	c.mu.Lock()
	c.hash = hash
	c.len = shardsNum
	c.mu.Unlock()
}
31233
func (rb *ringBuffer) Push(values ...interface{}) {
	for _, value := range values {
		if rb.end.next.used == false {
			rb.end.next.used = true
			rb.end.next.value = value
			rb.end = rb.end.next
			continue
		}
		link := &valueLink{
			used:  true,
			value: value,
			next:  rb.start,
		}
		rb.end.next = link
		rb.end = rb.end.next
	}
}
13264
func (u *Ugen) Ring4(val Input) Input {
	return binOpRing4(u.Rate, u, val, u.NumOutputs)
}