示例#1
0
        /// <summary>Transform Delete-Insert case.</summary>
        /// <param name="o1">An operation to be transformed.</param>
        /// <param name="o2">Operation with respect to which perform the transformation.</param>
        /// <returns>Transformed operation.</returns>
        private static IOperation TransformDeleteInsert(IOperation o1, IOperation o2)
        {
            if (o1.Index < o2.Index)
            {
                // Tdi(Del[3], Ins[4, "b"]) -> Del[3]
                return(o1);
            }

            // Tdi(Del[3], Ins[1, "b"]) -> Del[4]
            return(OperationFactory.CreateOperation(o1.ClientId, o1.OperationType, o1.Index + 1, o1.Value, o1.Timestamp));
        }
示例#2
0
        /// <summary>Transform Insert-Delete case.</summary>
        /// <param name="o1">An operation to be transformed.</param>
        /// <param name="o2">Operation with respect to which perform the transformation.</param>
        /// <returns>Transformed operation.</returns>
        private static IOperation TransformInsertDelete(IOperation o1, IOperation o2)
        {
            if (o1.Index <= o2.Index)
            {
                // Tid(Ins[3, "a"], Del[4]) -> Ins[3, "a"]
                return(o1);
            }

            // Tid(Ins[3, "a"], Del[1]) -> Ins[2, "a"]
            return(OperationFactory.CreateOperation(o1.ClientId, o1.OperationType, o1.Index - 1, o1.Value, o1.Timestamp));
        }
示例#3
0
        /// <summary>Transform Insert-Insert case.</summary>
        /// <param name="o1">An operation to be transformed.</param>
        /// <param name="o2">Operation with respect to which perform the transformation.</param>
        /// <returns>Transformed operation.</returns>
        private static IOperation TransformInsertInsert(IOperation o1, IOperation o2)
        {
            // Original OT algorithm considers Timstamp to determine which operation has higher priority.
            // Here the value comparison is used to support sorted data set.
            if (o1.Index < o2.Index || (o1.Index == o2.Index && o1.Value.Value <= o2.Value.Value))
            {
                // Tii(Ins[3, "a"], Ins[4, "b"]) -> Ins[3, "a"]
                return(o1);
            }

            // Tii(Ins[3, "a"], Ins[1, "b"]) -> Ins[4, "a"]
            return(OperationFactory.CreateOperation(o1.ClientId, o1.OperationType, o1.Index + 1, o1.Value, o1.Timestamp));
        }
示例#4
0
        /// <summary>Transform Delete-Delete case.</summary>
        /// <param name="o1">An operation to be transformed.</param>
        /// <param name="o2">Operation with respect to which perform the transformation.</param>
        /// <returns>Transformed operation. NULL if operations are identical and operation execution is not needed.</returns>
        private static IOperation TransformDeleteDelete(IOperation o1, IOperation o2)
        {
            if (o1.Index < o2.Index)
            {
                // Tdd(Del[3], Del[4]) -> Del[3]
                return(o1);
            }

            if (o1.Index > o2.Index)
            {
                // Tdd(Del[3], Del[1]) -> Del[2]
                return(OperationFactory.CreateOperation(o1.ClientId, o1.OperationType, o1.Index - 1, o1.Value, o1.Timestamp));
            }

            // breaking deletion (identity operation), meaning operations are equivalent Tdd(Del[3], Del[3]) -> I
            return(null);
        }