// CompareAndSwap atomatically swaps the old with the new value.
342896
func (s *AtomicString) CompareAndSwap(oldval, newval string) (swqpped bool) {
	s.mu.Lock()
	defer s.mu.Unlock()
	if s.str == oldval {
		s.str = newval
		return true
	}
	return false
}
965087
func (slice RevelHooks) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}
634351
func Difference(wants []string, haves []string) (revoke []string, add []string) {
	for _, want := range wants {
		found := false
		for _, got := range haves {
			if want != got {
				continue
			}
			found = true
		}
		if !found {
			add = append(add, want)
		}
	}
	for _, got := range haves {
		found := false
		for _, want := range wants {
			if want != got {
				continue
			}
			found = true
			break
		}
		if !found {
			revoke = append(revoke, got)
		}
	}
	return
}
599096
func NewChangeWatchResp(ctx context.Context, delegate datasync.ProtoWatchResp, prevVal datasync.LazyValue) *ChangeWatchResp {
	return &ChangeWatchResp{
		ctx: ctx,
		changes: []datasync.ProtoWatchResp{
			&changePrev{
				ProtoWatchResp: delegate,
				prev:           prevVal,
			},
		},
		DoneChannel: &syncbase.DoneChannel{DoneChan: nil},
	}
}
942898
func (u *user) compareSubkeys(subkeys []keybase1.KID) error {
	return compareKeys(subkeys, u.subkeys)
}
834887
func (m *Memory) CompareAndSwap(ctx context.Context, expected backend.Item, replaceWith backend.Item) (*backend.Lease, error) {
	if len(expected.Key) == 0 {
		return nil, trace.BadParameter("missing parameter Key")
	}
	if len(replaceWith.Key) == 0 {
		return nil, trace.BadParameter("missing parameter Key")
	}
	if bytes.Compare(expected.Key, replaceWith.Key) != 0 {
		return nil, trace.BadParameter("expected and replaceWith keys should match")
	}
	m.Lock()
	defer m.Unlock()
	m.removeExpired()
	i := m.tree.Get(&btreeItem{Item: expected})
	if i == nil {
		return nil, trace.CompareFailed("key %q is not found", string(expected.Key))
	}
	existingItem := i.(*btreeItem).Item
	if bytes.Compare(existingItem.Value, expected.Value) != 0 {
		return nil, trace.CompareFailed("current value does not match expected for %v", string(expected.Key))
	}
	event := backend.Event{
		Type: backend.OpPut,
		Item: replaceWith,
	}
	m.processEvent(event)
	if !m.EventsOff {
		m.buf.Push(event)
	}
	return m.newLease(replaceWith), nil
}
702621
func CompareValues(v1, v2 Value) int {
	switch v1 := v1.(type) {
	case Document:
		v2, ok := v2.(Document)
		if !ok {
			return -1
		} else if len(v1) != len(v2) {
			return len(v1) - len(v2)
		}
		return -1 // TODO: implement proper sorting?
	case Strings:
		v2, ok := v2.(Strings)
		if !ok {
			return -1
		} else if len(v1) != len(v2) {
			return len(v1) - len(v2)
		}
		for i := range v1 {
			if dn := CompareValues(String(v1[i]), String(v2[i])); dn != 0 {
				return dn
			}
		}
		return 0
	case Bytes:
		v2, ok := v2.(Bytes)
		if !ok {
			return -1
		}
		return bytes.Compare(v1, v2)
	case Time:
		v2, ok := v2.(Time)
		if !ok {
			return -1
		}
		t1, t2 := time.Time(v1), time.Time(v2)
		if t1.Equal(t2) {
			return 0
		} else if t1.Before(t2) {
			return -1
		}
		return +1
	case String:
		v2, ok := v2.(String)
		if !ok {
			return -1
		}
		return strings.Compare(string(v1), string(v2))
	case Int:
		v2, ok := v2.(Int)
		if !ok {
			return -1
		}
		if v1 == v2 {
			return 0
		} else if v1 < v2 {
			return -1
		}
		return +1
	case Float:
		v2, ok := v2.(Float)
		if !ok {
			return -1
		}
		if v1 == v2 {
			return 0
		} else if v1 < v2 {
			return -1
		}
		return +1
	}
	return -1
}
973994
func (s windowsDiff) Compare(ctx context.Context, lower, upper []mount.Mount, opts ...diff.Opt) (d ocispec.Descriptor, err error) {
	return emptyDesc, errdefs.ErrNotImplemented
}
1205336
func Compare(a, b interface{}) Diff {
	mapA := map[string]interface{}{}
	mapB := map[string]interface{}{}

	jsonA, _ := json.Marshal(a)
	jsonB, _ := json.Marshal(b)

	json.Unmarshal(jsonA, &mapA)
	json.Unmarshal(jsonB, &mapB)

	return compareStringMaps(mapA, mapB)
}
1227236
func compareKeys(keys []keybase1.KID, expected map[keybase1.KID]struct{}) error {
	if len(keys) != len(expected) {
		return ErrKeysNotEqual
	}
	for _, kid := range keys {
		if _, ok := expected[kid]; !ok {
			return ErrKeysNotEqual
		}
	}
	return nil
}
980244
func (history *History) Swap(i, j int) {
	sandboxes := *history
	sandboxes[i], sandboxes[j] = sandboxes[j], sandboxes[i]
}
858518
func (s optionDescriptorSlice) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
1368020
func compareAndSwap(args [][]byte, txn *mdb.Txn) ([]byte, error) {
	dbName := string(args[0])
	dbi, err := txn.DBIOpen(&dbName, mdb.CREATE) // create if not exists
	existingVal, err := txn.Get(dbi, args[1])
	if err != nil && err != mdb.NotFound {
		txn.Abort()
		return nil, err
	}
	if err == mdb.NotFound || bytesEqual(args[2], existingVal) {
		err = txn.Put(dbi, args[1], args[3], 0)
		if err != nil {
			return nil, err
		}
		err = txn.Commit()
		return args[3], err
	} else {
		txn.Abort()
		return existingVal, nil
	}
}
1235950
func (so SortOrder) Compare(cachedScoring, cachedDesc []bool, i, j *DocumentMatch) int {
	// compare the documents on all search sorts until a differences is found
	for x := range so {
		c := 0
		if cachedScoring[x] {
			if i.Score < j.Score {
				c = -1
			} else if i.Score > j.Score {
				c = 1
			}
		} else {
			iVal := i.Sort[x]
			jVal := j.Sort[x]
			c = strings.Compare(iVal, jVal)
		}

		if c == 0 {
			continue
		}
		if cachedDesc[x] {
			c = -c
		}
		return c
	}
	// if they are the same at this point, impose order based on index natural sort order
	if i.HitNumber == j.HitNumber {
		return 0
	} else if i.HitNumber > j.HitNumber {
		return 1
	}
	return -1
}
756149
func (sp crSortedPaths) Swap(i, j int) {
	sp[j], sp[i] = sp[i], sp[j]
}
550618
func (s *Sorter) Swap(i, j int) {
	x := s.Slice.Index(i)
	y := s.Slice.Index(j)
	tmp := reflect.New(s.itemType).Elem()
	tmp.Set(x)
	x.Set(y)
	y.Set(tmp)
}
444851
func ValuesEqual(vss1, vss2 [][]*querypb.Value) bool {
	if len(vss1) != len(vss2) {
		return false
	}
	for i, vs1 := range vss1 {
		if len(vs1) != len(vss2[i]) {
			return false
		}
		for j, v1 := range vs1 {
			if !proto.Equal(v1, vss2[i][j]) {
				return false
			}
		}
	}
	return true
}