// dedupItems only deduplicates items between slices, not within the slices.
761709
func dedupItems(a, b []*iniItem, flag bool) []*iniItem {
	for i := 0; i < len(a); i++ {
		itemA := a[i]
		if itemA == nil {
			continue
		}
		keyA := ident(flag, itemA.Key)
		for _, itemB := range b {
			if keyA != ident(flag, itemB.Key) {
				continue
			}
			copy(a[i:], a[i+1:])
			n := len(a) - 1
			a[n] = nil
			a = a[:n]
			i--
			break
		}
	}

	return append(a, b...)
}
332586
func isDuplicate(m map[item]struct{}, name, addr string, port uint16) bool {
	if addr != "" {
		_, ok := m[item{name, 0, addr}]
		if !ok {
			m[item{name, 0, addr}] = struct{}{}
		}
		return ok
	}
	_, ok := m[item{name, port, ""}]
	if !ok {
		m[item{name, port, ""}] = struct{}{}
	}
	return ok
}
301575
func convertProtoMounts(in []*proto.Mount) []*Mount {
	if in == nil {
		return nil
	}

	out := make([]*Mount, len(in))
	for i, d := range in {
		out[i] = convertProtoMount(d)
	}

	return out
}
712264
func (fis FileInfoSums) SortBySums() {
	dups := fis.GetDuplicatePaths()
	if len(dups) > 0 {
		sort.Sort(bySum{fis, dups})
	} else {
		sort.Sort(bySum{fis, nil})
	}
}
1073048
func (image *Image) recomputeDigests() error {
	validDigests := make([]digest.Digest, 0, len(image.BigDataDigests)+1)
	digests := make(map[digest.Digest]struct{})
	if image.Digest != "" {
		if err := image.Digest.Validate(); err != nil {
			return errors.Wrapf(err, "error validating image digest %q", string(image.Digest))
		}
		digests[image.Digest] = struct{}{}
		validDigests = append(validDigests, image.Digest)
	}
	for name, digest := range image.BigDataDigests {
		if !bigDataNameIsManifest(name) {
			continue
		}
		if digest.Validate() != nil {
			return errors.Wrapf(digest.Validate(), "error validating digest %q for big data item %q", string(digest), name)
		}
		// Deduplicate the digest values.
		if _, known := digests[digest]; !known {
			digests[digest] = struct{}{}
			validDigests = append(validDigests, digest)
		}
	}
	if image.Digest == "" && len(validDigests) > 0 {
		image.Digest = validDigests[0]
	}
	image.Digests = validDigests
	return nil
}
953621
func (k *tsmBatchKeyIterator) mergeUnsigned() {
	// No blocks left, or pending merged values, we're done
	if len(k.blocks) == 0 && len(k.merged) == 0 && k.mergedUnsignedValues.Len() == 0 {
		return
	}

	sort.Stable(k.blocks)

	dedup := k.mergedUnsignedValues.Len() != 0
	if len(k.blocks) > 0 && !dedup {
		// If we have more than one block or any partially tombstoned blocks, we many need to dedup
		dedup = len(k.blocks[0].tombstones) > 0 || k.blocks[0].partiallyRead()

		// Quickly scan each block to see if any overlap with the prior block, if they overlap then
		// we need to dedup as there may be duplicate points now
		for i := 1; !dedup && i < len(k.blocks); i++ {
			dedup = k.blocks[i].partiallyRead() ||
				k.blocks[i].overlapsTimeRange(k.blocks[i-1].minTime, k.blocks[i-1].maxTime) ||
				len(k.blocks[i].tombstones) > 0
		}

	}

	k.merged = k.combineUnsigned(dedup)
}
338336
func (s *DepsStage) ExpandShards() {
	newSlice := make([]*Dependency, 0, len(s.Deps))
	for _, dep := range s.Deps {
		if dep.Shards != 0 {
			for i := uint64(0); i < dep.Shards; i++ {
				depCopy := *dep
				depCopy.Shards = 0
				phraseCopy := *depCopy.Phrase
				phraseCopy.Name = fmt.Sprintf("%s_%d", phraseCopy.Name, i)
				depCopy.Phrase = &phraseCopy
				newSlice = append(newSlice, &depCopy)
			}
		} else {
			newSlice = append(newSlice, dep)
		}
	}
	s.Deps = newSlice
}
1104579
func DeleteDuplicateMisses(db *sql.DB) (int64, error) {
	if isuniq, err := IsUniqueIndex(db, "uix_misses_hashes_index"); err != nil && err != sql.ErrNoRows {
		return 0, err
	} else if isuniq {
		return 0, nil
	}
	execErrPrefix := "failed to delete duplicate misses: "
	return sqlExec(db, internal.DeleteMissesDuplicateRows, execErrPrefix)
}
1350178
func dedupDeltas(deltas Deltas) Deltas {
	n := len(deltas)
	if n < 2 {
		return deltas
	}
	a := &deltas[n-1]
	b := &deltas[n-2]
	if out := isDup(a, b); out != nil {
		d := append(Deltas{}, deltas[:n-2]...)
		return append(d, *out)
	}
	return deltas
}
618835
func dedup(rules []Rule) []Rule {
	// record hash of already added rules to detect duplicates
	added := make(map[uint64]struct{}, len(rules))
	result := []Rule{}
	for i := range rules {
		// TODO: detect duplicates styles where filters/zoom can be combined
		// if i != 0 && filterEqual(rules[i-1].Filters, rules[i].Filters) {
		// 	if rules[i-1].Properties.equal(rules[i].Properties) {
		// 		// update result[-1].zoom to combined zoom -> >=13 + >=15 -> >=13
		// 		continue
		// 	}
		// }
		hash := rules[i].hash()
		if _, ok := added[hash]; !ok {
			result = append(result, rules[i])
			added[hash] = struct{}{}
		}
	}
	return result
}
750552
func (eBase *elementBase) hasMixinDecs() bool {
	for _, mi := range eBase.mixins {
		if decs, _ := mi.decsParams(); len(decs) > 0 {
			return true
		}
	}

	return false
}
1206982
func enumUniqueItems(items []compile.EnumItem) []compile.EnumItem {
	used := make(map[int32]struct{}, len(items))
	filtered := items[:0] // zero-alloc filtering
	for _, i := range items {
		if _, isUsed := used[i.Value]; isUsed {
			continue
		}
		filtered = append(filtered, i)
		used[i.Value] = struct{}{}
	}
	return filtered
}
559350
func (v *Result) mergeErrors(otherResult *Result) {
	v.errors = append(v.errors, otherResult.Errors()...)
	v.score += otherResult.score
}
4425
func decapitalise(input string) string {
	if len(input) == 0 {
		return input
	}

	goForm := abi.ToCamelCase(input)
	return strings.ToLower(goForm[:1]) + goForm[1:]
}
742894
func DiffStringSlices(slice1 []string, slice2 []string) []string {
	diffStr := []string{}
	m := map[string]int{}

	for _, s1Val := range slice1 {
		m[s1Val] = 1
	}
	for _, s2Val := range slice2 {
		m[s2Val] = m[s2Val] + 1
	}

	for mKey, mVal := range m {
		if mVal == 1 {
			diffStr = append(diffStr, mKey)
		}
	}

	return diffStr
}
334924
func DepriveMutiBreak(s string) string {
	re, _ := regexp.Compile(`([^\n\f\r\t 　 ]*)([ 　 ]*[\n\f\r\t]+[ 　 ]*)+`)
	return re.ReplaceAllString(s, "${1}\n")

}
377082
func (h *HyperLogLogPlus) mergeSparse() {
	keys := make(sortableSlice, 0, len(h.tmpSet))
	for k := range h.tmpSet {
		keys = append(keys, k)
	}
	sort.Sort(keys)

	newList := newCompressedList(int(h.m))
	for iter, i := h.sparseList.Iter(), 0; iter.HasNext() || i < len(keys); {
		if !iter.HasNext() {
			newList.Append(keys[i])
			i++
			continue
		}

		if i >= len(keys) {
			newList.Append(iter.Next())
			continue
		}

		x1, x2 := iter.Peek(), keys[i]
		if x1 == x2 {
			newList.Append(iter.Next())
			i++
		} else if x1 > x2 {
			newList.Append(x2)
			i++
		} else {
			newList.Append(iter.Next())
		}
	}

	h.sparseList = newList
	h.tmpSet = set{}

	if uint32(h.sparseList.Len()) > h.m {
		h.toNormal()
	}
}