// WriteQuad adds a quad to quad store.
//
// Deprecated: use AddQuad instead.
196005
func (qs *QuadStore) WriteQuad(q quad.Quad) error {
	qs.AddQuad(q)
	return nil
}
959190
func (s *ValidateService) Q(q string) *ValidateService {
	s.q = q
	return s
}
692078
func WriteQRFile(ctx context.Context, otp twofactor.OTP, label, file string) error {
	var qr []byte
	var err error
	switch otp.Type() {
	case twofactor.OATH_HOTP:
		hotp := otp.(*twofactor.HOTP)
		qr, err = hotp.QR(label)
	case twofactor.OATH_TOTP:
		totp := otp.(*twofactor.TOTP)
		qr, err = totp.QR(label)
	default:
		err = errors.New("QR codes can only be generated for OATH OTPs")
	}
	if err != nil {
		return errors.Wrapf(err, "%s", err)
	}

	if err := ioutil.WriteFile(file, qr, 0600); err != nil {
		return errors.Wrapf(err, "failed to write QR code: %s", err)
	}
	return nil
}
915067
func (w *Writer) WriteComplex128(c complex128) {
	if imag(c) == 0 {
		w.WriteFloat(real(c), 64)
		return
	}
	setWriterRef(w, nil, nil)
	writeListHeader(w, 2)
	w.WriteFloat(real(c), 64)
	w.WriteFloat(imag(c), 64)
	writeListFooter(w)
}
979587
func (d DoubleArray) WriteTo(w io.Writer) (n int64, err error) {
	sz := int64(len(d))
	//fmt.Println("write data len:", sz)
	if err = binary.Write(w, binary.LittleEndian, sz); err != nil {
		return
	}
	n += int64(binary.Size(sz))
	for _, v := range d {
		if err = binary.Write(w, binary.LittleEndian, v.Base); err != nil {
			return
		}
		n += int64(binary.Size(v.Base))
		if err = binary.Write(w, binary.LittleEndian, v.Check); err != nil {
			return
		}
		n += int64(binary.Size(v.Check))
	}
	return
}
830419
func (b *builderBuffer) Write(v []byte) {
	l := uint(len(v))
	if l > 0 {
		off := uint(len(*b))
		b.growCapacity(l)
		*b = (*b)[:off+l]
		copy((*b)[off:], v)
	}
}
596970
func (xxh *xxHash) Write(input []byte) (int, error) {
	n := len(input)
	m := xxh.bufused

	xxh.totalLen += uint64(n)

	r := len(xxh.buf) - m
	if n < r {
		copy(xxh.buf[m:], input)
		xxh.bufused += len(input)
		return n, nil
	}

	p := 0
	if m > 0 {
		// some data left from previous update
		copy(xxh.buf[xxh.bufused:], input[:r])
		xxh.bufused += len(input) - r

		// fast rotl(31)
		xxh.v1 = rol31(xxh.v1+u64(xxh.buf[:])*prime64_2) * prime64_1
		xxh.v2 = rol31(xxh.v2+u64(xxh.buf[8:])*prime64_2) * prime64_1
		xxh.v3 = rol31(xxh.v3+u64(xxh.buf[16:])*prime64_2) * prime64_1
		xxh.v4 = rol31(xxh.v4+u64(xxh.buf[24:])*prime64_2) * prime64_1
		p = r
		xxh.bufused = 0
	}

	// Causes compiler to work directly from registers instead of stack:
	v1, v2, v3, v4 := xxh.v1, xxh.v2, xxh.v3, xxh.v4
	for n := n - 32; p <= n; p += 32 {
		sub := input[p:][:32] //BCE hint for compiler
		v1 = rol31(v1+u64(sub[:])*prime64_2) * prime64_1
		v2 = rol31(v2+u64(sub[8:])*prime64_2) * prime64_1
		v3 = rol31(v3+u64(sub[16:])*prime64_2) * prime64_1
		v4 = rol31(v4+u64(sub[24:])*prime64_2) * prime64_1
	}
	xxh.v1, xxh.v2, xxh.v3, xxh.v4 = v1, v2, v3, v4

	copy(xxh.buf[xxh.bufused:], input[p:])
	xxh.bufused += len(input) - p

	return n, nil
}
344009
func (r *Result) Add(val int64) {
	r.Count++
	r.Sum += val
	// Sum of squares tends to roll over pretty easily
	r.SumOfSquares += float64(val) * float64(val)
}
350746
func (w *Writer) Write(i interface{}) {
	var s string
	switch i.(type) {
	case string:
		s = i.(string)
	case []byte:
		for _, b := range i.([]byte) {
			s += fmt.Sprintf("%.8b", b)
		}
	case bool:
		if i.(bool) {
			s = "1"
		} else {
			s = "0"
		}
	case uint8:
		s = fmt.Sprintf("%.8b", i)
	case uint16:
		s = fmt.Sprintf("%.16b", i)
	case uint32:
		s = fmt.Sprintf("%.32b", i)
	case uint64:
		s = fmt.Sprintf("%.64b", i)
	default:
		return
	}

	for _, c := range s {
		w.remainingBits = w.remainingBits + string(c)
		if len(w.remainingBits) == 8 {
			var nb byte
			var power float64
			for idx := len(w.remainingBits) - 1; idx >= 0; idx-- {
				if w.remainingBits[idx] == '1' {
					nb = nb + uint8(math.Pow(2, power))
				}
				power++
			}
			w.b = append(w.b, nb)
			w.remainingBits = ""
		}
	}
}
189195
func (w *Writer) WriteUint(i uint64) {
	if i <= 9 {
		w.writeByte(byte('0' + i))
		return
	}
	if i <= math.MaxInt32 {
		w.writeByte(TagInteger)
	} else {
		w.writeByte(TagLong)
	}
	var buf [20]byte
	w.write(util.GetUintBytes(buf[:], i))
	w.writeByte(TagSemicolon)
}
472485
func (b *builderBuffer) WriteByte(v byte) {
	off := len(*b)
	b.growCapacity(1)
	*b = (*b)[:off+1]
	(*b)[off] = v
}
337245
func (s QuadFilter) buildIterator(qs graph.QuadStore) graph.Iterator {
	if s.Values == nil {
		return iterator.NewNull()
	} else if v, ok := One(s.Values); ok {
		return qs.QuadIterator(s.Dir, v)
	}
	if s.Dir == quad.Any {
		panic("direction is not set")
	}
	sub := s.Values.BuildIterator(qs)
	return iterator.NewLinksTo(qs, sub, s.Dir)
}
730899
func distsqRef(x, y []simd.I32x4) int32 {
	if len(x) != len(y) {
		return -1
	}
	n := len(x)
	dist := int32(math.MaxInt32)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				continue
			}
			for idx := 0; idx < 4; idx++ {
				dx := x[j][idx] - x[i][idx]
				dy := y[j][idx] - y[i][idx]
				sqX := dx * dx
				sqY := dy * dy
				sqDist := sqX + sqY
				if sqDist < dist {
					dist = sqDist
				}
			}
		}
	}
	return dist
}
1329351
func (c *IterateChain) FirstValue(qs QuadStore) (quad.Value, error) {
	if qs != nil {
		c.qs = qs
	}
	if c.qs == nil {
		return nil, errNoQuadStore
	}
	v, err := c.First()
	if err != nil || v == nil {
		return nil, err
	}
	// TODO: return an error from NameOf once we have it exposed
	return c.qs.NameOf(v), nil
}
852752
func (w *QWriter) Q(s string) {
	w.Write(strQuote)
	writeJSONString(w, s)
	w.Write(strQuote)
}
1353538
func (c *DOM) GetContentQuadsWithParams(v *DOMGetContentQuadsParams) ([]float64, error) {
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "DOM.getContentQuads", Params: v})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			Quads []float64
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.Quads, nil
}
85907
func (t Tile) Quadkey() uint64 {
	var i, result uint64
	for i = 0; i < uint64(t.Z); i++ {
		result |= (uint64(t.X) & (1 << i)) << i
		result |= (uint64(t.Y) & (1 << i)) << (i + 1)
	}

	return result
}