wasSharp – Rev 51

Subversion Repositories:
Rev:
///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3      //
//  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  //
//  rights of fair usage, the disclaimer and warranty conditions.        //
///////////////////////////////////////////////////////////////////////////

using System;
using System.Threading.Tasks;

namespace wasSharp
{
    public static class Extensions
    {
        /// <summary>
        /// Combine two UUIDs together by taking the MD5 hash of a byte array
        /// containing both UUIDs
        /// </summary>
        /// <param name="first">First UUID to combine</param>
        /// <param name="second">Second UUID to combine</param>
        /// <returns>The UUID product of the combination</returns>
        public static Guid CombineXOR(this Guid p, Guid q)
        {
            var l = p.ToByteArray();
            var r = q.ToByteArray();
            byte[] combine = new byte[16];
            Parallel.For(0, 16, i =>
            {
                combine[i] = (byte)(l[i] ^ r[i]);
            });

            return new Guid(combine);
        }
    }
}