Ejemplo n.º 1
0
        public static VectorClock max(VectorClock vcOne, VectorClock vcTwo)
        {
            VectorClock newClock = new VectorClock("default");
            foreach (var x in vcOne.versions)
            {
                newClock.versions.Add(x);
            }

            foreach (var x in vcTwo.versions)
            {
                if (!newClock.versions.Contains(x))
                {
                    newClock.versions.Add(x);
                }
            }

            return newClock;
        }
Ejemplo n.º 2
0
        public static VectorComparison compare(VectorClock vcOne, VectorClock vcTwo)
        {
            // Initially we assume it is all possible things.
            bool equal   = true;
            bool greater = true;
            bool smaller = true;

            // Go over all elements in Clock one.
            foreach (var x in vcOne.versions)
            {
                // Compare if also present in clock two.
                if (vcTwo.versions.Contains(x))
                {
                    // If there is a difference, it can never be equal.
                    // Greater / smaller depends on the difference.
                    if (vcOne.getTimestamp() < vcTwo.getTimestamp())
                    {
                        equal   = false;
                        greater = false;
                    }
                    if (vcOne.getTimestamp() > vcTwo.getTimestamp())
                    {
                        equal   = false;
                        smaller = false;
                    }
                }
                // Else assume zero (default value is 0).
                else if (vcOne.getTimestamp() != 0)
                {
                    equal   = false;
                    smaller = false;
                }
            }

            // Go over all elements in Clock two.
            foreach (var x in vcTwo.versions)
            {
                // Only elements we have not found in One still need to be checked.
                if (vcOne.getTimestamp() != 0 && vcTwo.getTimestamp() != 0)
                {
                    equal   = false;
                    greater = false;
                }
            }

            // Return based on determined information.
            if (equal)
            {
                return(VectorComparison.Equal);
            }
            else if (greater && !smaller)
            {
                return(VectorComparison.Greater);
            }
            else if (smaller && !greater)
            {
                return(VectorComparison.Smaller);
            }
            else
            {
                return(VectorComparison.Simultaneous);
            }
        }
Ejemplo n.º 3
0
 public static VectorClock compare(VectorClock vcOne, VectorClock vcTwo)
 {
     return vcOne;
 }
Ejemplo n.º 4
0
        public static VectorComparison compare(VectorClock vcOne, VectorClock vcTwo)
        {
            // Initially we assume it is all possible things.
            bool equal	 = true;
            bool greater = true;
            bool smaller = true;

            // Go over all elements in Clock one.
            foreach (var x in vcOne.versions)
            {
                // Compare if also present in clock two.
                if (vcTwo.versions.Contains(x))
                {
                    // If there is a difference, it can never be equal.
                    // Greater / smaller depends on the difference.
                    if (vcOne.getTimestamp() < vcTwo.getTimestamp())
                    {
                        equal	 = false;
                        greater = false;
                    }
                    if (vcOne.getTimestamp() > vcTwo.getTimestamp())
                    {
                        equal	 = false;
                        smaller = false;
                    }
                }
                // Else assume zero (default value is 0).
                else if (vcOne.getTimestamp() != 0)
                {
                    equal	 = false;
                    smaller = false;
                }
            }

            // Go over all elements in Clock two.
            foreach (var x in vcTwo.versions)
            {
                // Only elements we have not found in One still need to be checked.
                if (vcOne.getTimestamp() !=0 && vcTwo.getTimestamp() != 0)
                {
                    equal	 = false;
                    greater = false;
                }
            }

            // Return based on determined information.
            if (equal)
            {
                return VectorComparison.Equal;
            }
            else if (greater && !smaller)
            {
                return VectorComparison.Greater;
            }
            else if (smaller && !greater)
            {
                return VectorComparison.Smaller;
            }
            else
            {
                return VectorComparison.Simultaneous;
            }
        }