// EncodeInt64 hashes an array of int64 to a string containing at least MinLength characters taken from the Alphabet.
// Use DecodeInt64 using the same Alphabet and Salt to get back the array of int64.
961596
func (h *HashID) EncodeInt64(numbers []int64) (string, error) {
	if len(numbers) == 0 {
		return "", errors.New("encoding empty array of numbers makes no sense")
	}
	for _, n := range numbers {
		if n < 0 {
			return "", errors.New("negative number not supported")
		}
	}

	alphabet := duplicateRuneSlice(h.alphabet)

	numbersHash := int64(0)
	for i, n := range numbers {
		numbersHash += (n % int64(i+100))
	}

	maxRuneLength := h.maxLengthPerNumber * len(numbers)
	if maxRuneLength < h.minLength {
		maxRuneLength = h.minLength
	}

	result := make([]rune, 0, maxRuneLength)
	lottery := alphabet[numbersHash%int64(len(alphabet))]
	result = append(result, lottery)
	hashBuf := make([]rune, maxRuneLength)
	buffer := make([]rune, len(alphabet)+len(h.salt)+1)

	for i, n := range numbers {
		buffer = buffer[:1]
		buffer[0] = lottery
		buffer = append(buffer, h.salt...)
		buffer = append(buffer, alphabet...)
		consistentShuffleInPlace(alphabet, buffer[:len(alphabet)])
		hashBuf = hash(n, alphabet, hashBuf)
		result = append(result, hashBuf...)

		if i+1 < len(numbers) {
			n %= int64(hashBuf[0]) + int64(i)
			result = append(result, h.seps[n%int64(len(h.seps))])
		}
	}

	if len(result) < h.minLength {
		guardIndex := (numbersHash + int64(result[0])) % int64(len(h.guards))
		result = append([]rune{h.guards[guardIndex]}, result...)

		if len(result) < h.minLength {
			guardIndex = (numbersHash + int64(result[2])) % int64(len(h.guards))
			result = append(result, h.guards[guardIndex])
		}
	}

	halfLength := len(alphabet) / 2
	for len(result) < h.minLength {
		consistentShuffleInPlace(alphabet, duplicateRuneSlice(alphabet))
		result = append(alphabet[halfLength:], append(result, alphabet[:halfLength]...)...)
		excess := len(result) - h.minLength
		if excess > 0 {
			result = result[excess/2 : excess/2+h.minLength]
		}
	}

	return string(result), nil
}
586675
func decodeInt64(rd *bufio.Reader) (string, Int64, error) {
	// name
	name, err := readCstring(rd)
	if err != nil {
		return "", 0, err
	}

	// value
	i64, err := readInt64(rd)
	if err != nil {
		return "", 0, err
	}
	return name, Int64(i64), nil
}
1148828
func EncodeBase64(pw_cost uint, hash, salt []byte) (str string) {
	b64_salt := base64.URLEncoding.EncodeToString(salt)
	b64_hash := base64.URLEncoding.EncodeToString(hash)
	str = fmt.Sprintf("%d:%s:%s", pw_cost, b64_hash, b64_salt)
	return
}
1168189
func (d *Context) Base64Encode(index int) string {
	if s := C.duk_base64_encode(d.duk_context, C.duk_idx_t(index)); s != nil {
		return C.GoString(s)
	}
	return ""
}
853057
func (x *Big) Int64() (int64, bool) {
	if debug {
		x.validate()
	}

	if !x.IsFinite() {
		return 0, false
	}

	// x might be too large to fit into an int64 *now*, but rescaling x might
	// shrink it enough. See issue #20.
	if !x.isCompact() {
		xb := x.Int(nil)
		return xb.Int64(), xb.IsInt64()
	}

	u := x.compact
	if x.exp != 0 {
		var ok bool
		if u, ok = scalex(u, x.exp); !ok {
			return 0, false
		}
	}
	su := int64(u)
	if su >= 0 || x.Signbit() && su == -su {
		if x.Signbit() {
			su = -su
		}
		return su, true
	}
	return 0, false
}
1079258
func (p *parser) Int64(i int, context string) int64 {
	s := p.String(i, context)
	if p.err != nil {
		return 0
	}
	if s == "" {
		return 0
	}
	v, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		p.SetErr(context, s)
	}
	return v
}
150732
func EncodeInt64(value int64) (t Trits, size uint64, err error) {
	size = EncodedLength(value)

	if value == 0 {
		return encodedZero, size, nil
	}

	var encoding int64 = 0
	index := 0
	length := nearestGreaterMultipleOfThree(MinTrits(MustAbsInt64(value)))
	t = make(Trits, size)
	copy(t, IntToTrits(value))

	for i := 0; i < int(length)-TrinaryRadix; i += TrinaryRadix {
		if TritsToInt(t[i:i+TrinaryRadix]) >= 0 {
			encoding |= 1 << uint(index)
			for j := 0; j < TrinaryRadix; j++ {
				t[i+j] = -t[i+j]
			}
		}
		index++
	}

	if TritsToInt(t[length-TrinaryRadix:length]) <= 0 {
		encoding |= 1 << uint(index)
		for i := 1; i < TrinaryRadix+1; i++ {
			t[int(length)-i] = -t[int(length)-i]
		}
	}

	copy(t[length:], IntToTrits(encoding))
	return t, size, nil
}
129150
func (c *Config) Int64(key string) (int64, error) {
	return strconv.ParseInt(c.get(key), 10, 64)
}
1344689
func (be *BinaryEncoder) WriteInt64(value int64) {
	binary.BigEndian.PutUint64(be.buffer[be.pos:], uint64(value))
	be.pos += 8
}
750998
func DecodeInt64(t Trits) (value int64, size uint64, err error) {
	numTrits := uint64(len(t))

	equal, err := TritsEqual(t[0:4], encodedZero)
	if err != nil {
		return 0, 0, err
	}

	if equal {
		return 0, EncodedLength(0), nil
	}

	value = 0
	var encodingStart uint64 = 0

	for (encodingStart < numTrits) && (TritsToInt(t[encodingStart:encodingStart+TrinaryRadix]) <= 0) {
		encodingStart += TrinaryRadix
	}

	if encodingStart >= numTrits {
		return 0, 0, errors.New("encodingStart > numTrits")
	}

	encodingStart += TrinaryRadix
	encodingLength := MinTrits((1 << (encodingStart / TrinaryRadix)) - 1)
	encoding := TritsToInt(t[encodingStart : encodingStart+encodingLength])

	// Bound checking for the lookup table
	if encodingStart/TrinaryRadix > 13 {
		return 0, 0, errors.New("encodingStart/TrinaryRadix > 13")
	}

	for i := 0; i < int(encodingStart/TrinaryRadix); i++ {
		tryteValue := TritsToInt(t[i*TrinaryRadix : (i*TrinaryRadix)+TrinaryRadix])

		if ((encoding >> uint(i)) & 1) == 1 {
			tryteValue = -tryteValue
		}
		value += Pow27LUT[i] * tryteValue
	}

	return value, encodingStart + encodingLength, nil
}
579051
func _int64(i interface{}) (int64, bool) {

	switch v := i.(type) {

	case int:
		return int64(v), true
	case int8:
		return int64(v), true
	case int16:
		return int64(v), true
	case int32:
		return int64(v), true
	case int64:
		return v, true
	case uint:
		return int64(v), true
	case uint8:
		return int64(v), true
	case uint16:
		return int64(v), true
	case uint32:
		return int64(v), true
	case uint64:
		return int64(v), true
	}

	return 0, false
}
1091559
func GetInt64(r Retriever, k Key) (int64, error) {
	val, err := r.Get(k)
	if IsErrNotFound(err) {
		return 0, nil
	}
	if err != nil {
		return 0, err
	}
	intVal, err := strconv.ParseInt(string(val), 10, 0)
	if err != nil {
		return intVal, errors.Trace(err)
	}
	return intVal, nil
}
173412
func (r *Encoder) EncodeInt64(x int64) error {
	_, err := r.w.Write([]byte{CHR_INT8})
	if err != nil {
		return err
	}
	return binary.Write(r.w, binary.BigEndian, x)
}
1049965
func (enc *Encoder) Uint64(v uint64) {
	enc.grow(10)
	r := enc.getPreviousRune()
	if r != '[' {
		enc.writeByte(',')
	}
	enc.buf = strconv.AppendUint(enc.buf, v, 10)
}
342135
func (b *ByteBuf) WriteInt64(v int64) (n int, err error) {
	b.Expansion(8)
	Int64ToBytesTo(v, b.buf[b.writerIndex:b.writerIndex+8])
	b.writerIndex += 8
	return 8, nil
}
1315396
func EncodeUint64(i uint64) string {
	enc := make([]byte, 2, 10)
	copy(enc, "0x")
	return string(strconv.AppendUint(enc, i, 16))
}
632361
func (dec *Decoder) Int64(v *int64) error {
	err := dec.decodeInt64(v)
	if err != nil {
		return err
	}
	dec.called |= 1
	return nil
}