// concat two byte slices, returning a third new copy
762178
func concat(a, b []byte) []byte {
	c := make([]byte, len(a)+len(b))
	copy(c, a)
	copy(c[len(a):], b)
	return c
}
527830
func CopyAppend(slice []interface{}, elements ...interface{}) []interface{} {
	sliceLength := len(slice)
	newSlice := make([]interface{}, sliceLength+len(elements))
	for i, e := range slice {
		newSlice[i] = e
	}
	for i, e := range elements {
		newSlice[sliceLength+i] = e
	}
	return newSlice
}
195508
func (f *fifoProcessor) Concat(cnx redis.Conn, src, dest string) (err error) {
	return rlConcat(cnx, src, dest)
}
1349326
func padByteSlice(slice []byte, length int) []byte {
	offset := length - len(slice)
	if offset <= 0 {
		return slice
	}
	newSlice := make([]byte, length)
	copy(newSlice[offset:], slice)
	return newSlice
}
854587
func MergeSortedUInts(n ...[]uint64) []uint64 {
	var result []uint64
	if len(n) == 0 {
		return nil
	} else if len(n) == 1 {
		// Special case. Merge single slice with a nil slice, to remove any
		// duplicates from the single slice.
		return MergeSortedUInts(n[0], nil)
	}

	var maxSize int
	for _, a := range n {
		if len(a) > maxSize {
			maxSize = len(a)
		}
	}
	result = make([]uint64, 0, maxSize) // This will likely be too small but it's a start.

	idxs := make([]int, len(n)) // Indexes we've processed.
	var j int                   // Index we currently think is minimum.

	for {
		j = -1

		// Find the smallest minimum in all slices.
		for i := 0; i < len(n); i++ {
			if idxs[i] >= len(n[i]) {
				continue // We have completely drained all values in this slice.
			} else if j == -1 {
				// We haven't picked the minimum value yet. Pick this one.
				j = i
				continue
			}

			// It this value key is lower than the candidate.

			if n[i][idxs[i]] < n[j][idxs[j]] {
				j = i
			} else if n[i][idxs[i]] == n[j][idxs[j]] {
				// Duplicate value. Throw it away.
				idxs[i]++
			}

		}

		// We could have drained all of the values and be done...
		if j == -1 {
			break
		}

		// First value to just append it and move on.
		if len(result) == 0 {
			result = append(result, n[j][idxs[j]])
			idxs[j]++
			continue
		}

		// Append the minimum value to results if it's not a duplicate of
		// the existing one.

		if result[len(result)-1] < n[j][idxs[j]] {
			result = append(result, n[j][idxs[j]])
		} else if result[len(result)-1] == n[j][idxs[j]] {
			// Duplicate so drop it.
		} else {
			panic("value being merged out of order.")
		}

		idxs[j]++
	}
	return result
}
67805
func Combine(parts [][]byte) ([]byte, error) {
	// Verify enough parts provided
	if len(parts) < 2 {
		return nil, fmt.Errorf("less than two parts cannot be used to reconstruct the secret")
	}

	// Verify the parts are all the same length
	firstPartLen := len(parts[0])
	if firstPartLen < 2 {
		return nil, fmt.Errorf("parts must be at least two bytes")
	}
	for i := 1; i < len(parts); i++ {
		if len(parts[i]) != firstPartLen {
			return nil, fmt.Errorf("all parts must be the same length")
		}
	}

	// Create a buffer to store the reconstructed secret
	secret := make([]byte, firstPartLen-1)

	// Buffer to store the samples
	x_samples := make([]uint8, len(parts))
	y_samples := make([]uint8, len(parts))

	// Set the x value for each sample and ensure no x_sample values are the same,
	// otherwise div() can be unhappy
	checkMap := map[byte]bool{}
	for i, part := range parts {
		samp := part[firstPartLen-1]
		if exists := checkMap[samp]; exists {
			return nil, fmt.Errorf("duplicate part detected")
		}
		checkMap[samp] = true
		x_samples[i] = samp
	}

	// Reconstruct each byte
	for idx := range secret {
		// Set the y value for each sample
		for i, part := range parts {
			y_samples[i] = part[idx]
		}

		// Interpolate the polynomial and compute the value at 0
		val := interpolatePolynomial(x_samples, y_samples, 0)

		// Evaluate the 0th value to get the intercept
		secret[idx] = val
	}
	return secret, nil
}
693173
func CloneSlice(a [][]byte) [][]byte {
	other := make([][]byte, len(a))
	for i := range a {
		other[i] = Clone(a[i])
	}
	return other
}
1363934
func JoinRepeat(s, sep string, count int) string {
	switch count {
	case 0:
		return ""
	case 1:
		return s
	case 2:
		return s + sep + s
	case 3:
		return s + sep + s + sep + s
	}

	n := (len(s)+len(sep))*(count-1) + len(s)
	buf := make([]byte, n)
	bp := copy(buf, s)
	for i := 1; i < count; i++ {
		bp += copy(buf[bp:], sep)
		bp += copy(buf[bp:], s)
	}
	return *(*string)(unsafe.Pointer(&buf))
}
635200
func shiftNRuneBytes(rb [4]byte, n int) [4]byte {
	switch n {
	case 0:
		return rb
	case 1:
		return [4]byte{rb[1], rb[2], rb[3], 0}
	case 2:
		return [4]byte{rb[2], rb[3]}
	case 3:
		return [4]byte{rb[3]}
	default:
		return [4]byte{}
	}
}
45624
func Join(list []string, delim string) string {
	var buf bytes.Buffer
	for i := 0; i < len(list)-1; i++ {
		buf.WriteString(list[i] + delim)
	}
	buf.WriteString(list[len(list)-1])
	return buf.String()
}
560482
func (s ByteArraySlice) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
360859
func Hex2Bytes(src []byte) []byte {
	dst := make([]byte, len(src)/2)
	hex.Decode(dst, src)

	return dst
}
368541
func copySlice(slice []byte) []byte {
	ret := make([]byte, len(slice))
	copy(ret, slice)
	return ret
}
364953
func Join(sep string, a ...string) string {
	switch len(a) {
	case 0:
		return ""
	case 1:
		return a[0]
	case 2:
		// Special case for common small values.
		// Remove if golang.org/issue/6714 is fixed
		if sep == "" {
			return a[0] + a[1]
		}
		return a[0] + sep + a[1]
	case 3:
		// Special case for common small values.
		// Remove if golang.org/issue/6714 is fixed
		if sep == "" {
			return a[0] + a[1] + a[2]
		}
		return a[0] + sep + a[1] + sep + a[2]
	}

	var n int
	if sep != "" {
		n = len(sep) * (len(a) - 1)
	}
	for i := 0; i < len(a); i++ {
		n += len(a[i])
	}

	buf := make([]byte, n)
	bp := copy(buf, a[0])
	if sep == "" {
		for _, s := range a[1:] {
			bp += copy(buf[bp:], s)
		}
	} else {
		for _, s := range a[1:] {
			bp += copy(buf[bp:], sep)
			bp += copy(buf[bp:], s)
		}
	}
	return *(*string)(unsafe.Pointer(&buf))
	//return string(buf)
}
1093502
func (h *Histo) Combine(other []byte) error {
	otherHistogram := tdigest.NewMerging(100, false)
	if err := otherHistogram.GobDecode(other); err != nil {
		return err
	}
	h.Value.Merge(otherHistogram)
	return nil
}
582289
func (c *Client) Concat(targetPath string, r resource.Resources) (resource.Resource, error) {
	// The CACHE_OTHER will make sure this will be re-created and published on rebuilds.
	return c.rs.ResourceCache.GetOrCreate(resources.CACHE_OTHER, targetPath, func() (resource.Resource, error) {
		var resolvedm media.Type

		// The given set of resources must be of the same Media Type.
		// We may improve on that in the future, but then we need to know more.
		for i, r := range r {
			if i > 0 && r.MediaType().Type() != resolvedm.Type() {
				return nil, fmt.Errorf("resources in Concat must be of the same Media Type, got %q and %q", r.MediaType().Type(), resolvedm.Type())
			}
			resolvedm = r.MediaType()
		}

		concatr := func() (hugio.ReadSeekCloser, error) {
			var rcsources []hugio.ReadSeekCloser
			for _, s := range r {
				rcr, ok := s.(resource.ReadSeekCloserResource)
				if !ok {
					return nil, fmt.Errorf("resource %T does not implement resource.ReadSeekerCloserResource", s)
				}
				rc, err := rcr.ReadSeekCloser()
				if err != nil {
					// Close the already opened.
					for _, rcs := range rcsources {
						rcs.Close()
					}
					return nil, err
				}
				rcsources = append(rcsources, rc)
			}

			readers := make([]io.Reader, len(rcsources))
			for i := 0; i < len(rcsources); i++ {
				readers[i] = rcsources[i]
			}

			mr := io.MultiReader(readers...)

			return &multiReadSeekCloser{mr: mr, sources: rcsources}, nil
		}

		composite, err := c.rs.NewForFs(
			c.rs.FileCaches.AssetsCache().Fs,
			resources.ResourceSourceDescriptor{
				LazyPublish:        true,
				OpenReadSeekCloser: concatr,
				RelTargetFilename:  filepath.Clean(targetPath)})

		if err != nil {
			return nil, err
		}

		return composite, nil
	})

}
747759
func CopyByteSlice(in []byte) []byte {
	if in == nil {
		return nil
	}
	out := make([]byte, len(in))
	copy(out, in)
	return out
}