// Should the supplied object for a new positive entry replace the given
// existing entry?
501591
func shouldReplace(o *gcs.Object, existing entry) bool {
	// Negative entries should always be replaced with positive entries.
	if existing.o == nil {
		return true
	}

	// Compare first on generation.
	if o.Generation != existing.o.Generation {
		return o.Generation > existing.o.Generation
	}

	// Break ties on metadata generation.
	if o.MetaGeneration != existing.o.MetaGeneration {
		return o.MetaGeneration > existing.o.MetaGeneration
	}

	// Break ties by preferring fresher entries.
	return true
}
287266
func (c *Client) ReplaceVariable(ctx context.Context, variable *platform.Variable) error {
	op := getOp(platform.OpReplaceVariable)
	return c.db.Update(func(tx *bolt.Tx) error {
		if err := c.putVariableOrgsIndex(ctx, tx, variable); err != nil {
			return &platform.Error{
				Op:  op,
				Err: err,
			}
		}
		return c.putVariable(ctx, tx, variable)
	})
}
50195
func (s *EventStore) Replace(ctx context.Context, event eh.Event) error {
	// Ensure that the namespace exists.
	ns := s.namespace(ctx)

	s.dbMu.RLock()
	aggregate, ok := s.db[ns][event.AggregateID()]
	if !ok {
		s.dbMu.RUnlock()
		return eh.ErrAggregateNotFound
	}
	s.dbMu.RUnlock()

	// Find the event to replace.
	idx := -1
	for i, e := range aggregate.Events {
		if e.Version == event.Version() {
			idx = i
			break
		}
	}
	if idx == -1 {
		return eh.ErrInvalidEvent
	}

	// Replace event.
	s.dbMu.Lock()
	defer s.dbMu.Unlock()
	aggregate.Events[idx] = newDBEvent(event)

	return nil
}
533431
func (immutable *Immutable) Insert(entries ...Entry) (*Immutable, Entries) {
	if len(entries) == 0 {
		return immutable, Entries{}
	}

	overwritten := make(Entries, 0, len(entries))
	cp := immutable.copy()
	for _, e := range entries {
		overwritten = append(overwritten, cp.insert(e))
	}

	return cp, overwritten
}
1290420
func (c *MockClient) Replace(item *Item) MutateResponse {
	return NewMutateErrorResponse(
		item.Key,
		errors.Newf("Replace not implemented"))
}
324469
func (r *Record) Replace(k jstream.KVS) error {
	r.KVS = k
	return nil
}
191127
func replacePrefix(s string, args ...string) string {
	if len(args) != 2 {
		return s
	}
	if strings.HasPrefix(s, args[0]) {
		return strings.Replace(s, args[0], args[1], 1)
	}
	return s
}
330421
func newEntry(priority float64) *Entry {
	result := new(Entry)
	result.degree = 0
	result.marked = false
	result.child = nil
	result.parent = nil
	result.next = result
	result.prev = result
	result.Priority = priority
	return result
}
432355
func (b *Bucket) Replace(key string, value interface{}, cas Cas, expiry uint32) (Cas, error) {
	cas, _, err := b.replace(key, value, cas, expiry)
	return cas, err
}
1300168
func (u *Unit) NewValue(value int64, explicitSign Sign) (*Value, error) {
	if (value < 0 && explicitSign == Positive) || (value > 0 && explicitSign == Negative) {
		return nil, errors.New("Invalid value/explicitSign combination")
	}

	return &Value{
		unit:         u,
		Value:        value,
		ExplicitSign: explicitSign,
	}, nil
}
803817
func (d *defaultCacheMutationDetector) AddObject(obj interface{}) {
	if _, ok := obj.(DeletedFinalStateUnknown); ok {
		return
	}
	if obj, ok := obj.(runtime.Object); ok {
		copiedObj := obj.DeepCopyObject()

		d.lock.Lock()
		defer d.lock.Unlock()
		d.cachedObjs = append(d.cachedObjs, cacheObj{cached: obj, copied: copiedObj})
	}
}
1182435
func (sli *serviceLogInfo) GreaterThanOrEqual(value string) bool {
	if sli.Version == "" {
		return false
	} else if value == "" {
		return true
	}

	a := version.Version(sli.Version)
	b := version.Version(value)
	return a.GreaterThanOrEqualTo(b)
}
120638
func MakeAddition(key string, newVal interface{}) ItemChange {
	return ItemChange{
		Type:     added,
		Key:      key,
		NewValue: newVal,
	}
}
470244
func (nDB *NetworkDB) createOrUpdateEntry(nid, tname, key string, entry interface{}) (bool, bool) {
	_, okTable := nDB.indexes[byTable].Insert(fmt.Sprintf("/%s/%s/%s", tname, nid, key), entry)
	_, okNetwork := nDB.indexes[byNetwork].Insert(fmt.Sprintf("/%s/%s/%s", nid, tname, key), entry)
	if !okNetwork {
		// Add only if it is an insert not an update
		n, ok := nDB.networks[nDB.config.NodeID][nid]
		if ok {
			n.entriesNumber++
		}
	}
	return okTable, okNetwork
}
486472
func NewImmutable(id string) (*Predicate, error) {
	if id == "" {
		return nil, fmt.Errorf("predicate.NewImmutable(%q) cannot create a immutable predicate with empty ID", id)
	}
	return &Predicate{
		id: ID(id),
	}, nil
}
776077
func (r resourceEntry) EventUpdate(oldObject api.StoreObject) api.Event {
	if oldObject != nil {
		return api.EventUpdateResource{Resource: r.Resource, OldResource: oldObject.(resourceEntry).Resource}
	}
	return api.EventUpdateResource{Resource: r.Resource}
}
948557
func (c *mutationCache) newerObject(key string, backing runtime.Object) runtime.Object {
	mutatedObj, exists := c.mutationCache.Get(key)
	if !exists {
		return backing
	}
	mutatedObjRuntime, ok := mutatedObj.(runtime.Object)
	if !ok {
		return backing
	}
	if c.comparator.CompareResourceVersion(backing, mutatedObjRuntime) >= 0 {
		c.mutationCache.Remove(key)
		return backing
	}
	return mutatedObjRuntime
}