Ejemplo n.º 1
0
        public OUR_SetWithVC <T> Update(T value, Guid tag, VectorClock vectorClock)
        {
            var elementToUpdate = Adds.FirstOrDefault(a => a.Value.Id == value.Id && a.Tag == tag);

            if (elementToUpdate is null || elementToUpdate?.VectorClock > vectorClock)
            {
                return(this);
            }

            var adds = Adds.Remove(elementToUpdate);

            adds = adds.Add(new OUR_SetWithVCElement <T>(value, tag, vectorClock));

            return(new(adds, Removes));
        }
Ejemplo n.º 2
0
        public OUR_Set <T> Update(T value, Guid tag, long timestamp)
        {
            var elementToUpdate = Adds.FirstOrDefault(a => a.Value.Id == value.Id && a.Tag == tag);

            if (elementToUpdate is null || elementToUpdate?.Timestamp > timestamp)
            {
                return(this);
            }

            var adds = Adds.Remove(elementToUpdate);

            adds = adds.Add(new OUR_SetElement <T>(value, tag, timestamp));

            return(new(adds, Removes));
        }
Ejemplo n.º 3
0
        public LWW_SetWithVC <T> Add(T value, VectorClock vectorClock)
        {
            var existingElement = Adds.FirstOrDefault(a => a.Value.Id == value.Id);

            if (existingElement is not null && existingElement.VectorClock < vectorClock)
            {
                var elements = Adds.Remove(existingElement);

                return(new(elements.Add(new LWW_SetWithVCElement <T>(value, vectorClock)), Removes));
            }

            if (existingElement is null)
            {
                return(new(Adds.Add(new LWW_SetWithVCElement <T>(value, vectorClock)), Removes));
            }

            return(this);
        }
Ejemplo n.º 4
0
        public LWW_Set <T> Assign(T value, long timestamp)
        {
            var existingElement = Adds.FirstOrDefault(a => a.Value.Id == value.Id);

            if (existingElement is not null && existingElement.Timestamp < timestamp)
            {
                var elements = Adds.Remove(existingElement);

                return(new(elements.Add(new LWW_SetElement <T>(value, timestamp)), Removes));
            }

            if (existingElement is null)
            {
                return(new(Adds.Add(new LWW_SetElement <T>(value, timestamp)), Removes));
            }

            return(this);
        }