예제 #1
0
파일: GDIDTests2.cs 프로젝트: azist/azos
        public void Test_Values(uint era, ulong id)
        {
            var g = new GDID(era, id);

            var str = g.ToString();
            var hex = g.ToHexString();

            var g2 = GDID.Parse(str);
            var g3 = GDID.Parse(hex);

            Aver.AreEqual(g, g2);
            Aver.AreEqual(g, g3);
            Aver.AreEqual(g2, g3);

            Aver.AreObjectsEqual(g, g2);
            Aver.AreObjectsEqual(g, g3);
            Aver.AreObjectsEqual(g2, g3);

            Aver.IsTrue(g == g2);
            Aver.IsTrue(g == g3);
            Aver.IsTrue(g2 == g3);

            Aver.IsFalse(g != g3);
            Aver.IsFalse(g != g2);
            Aver.IsFalse(g2 != g3);

            Aver.AreEqual(g.GetHashCode(), g2.GetHashCode());
            Aver.AreEqual(g.GetHashCode(), g3.GetHashCode());

            Aver.AreEqual(g.GetDistributedStableHash(), g2.GetDistributedStableHash());
            Aver.AreEqual(g.GetDistributedStableHash(), g3.GetDistributedStableHash());

            var json = new { g }.ToJson();

            "String: {0} \n Hex: {1} \n Json: {2} \n".SeeArgs(str, hex, json);


            var got = json.JsonToDataObject() as JsonDataMap;

            Aver.AreEqual(g, got["g"].AsGDID());

            var buf = g.Bytes;
            var g4  = new GDID(buf);

            Aver.AreEqual(g, g4);

            var buf2 = new byte[128];

            g.WriteIntoBuffer(buf2, 18);
            var g5 = new GDID(buf2, 18);

            Aver.AreEqual(g, g5);
        }
예제 #2
0
 public ulong GetDistributedStableHash()
 {
     return(GDID1.GetDistributedStableHash() ^
            GDID2.GetDistributedStableHash() ^
            (((ulong)ISO) << 32) ^
            (ulong)PAYLOAD);
 }
예제 #3
0
파일: ShardKey.cs 프로젝트: JohnPKosh/azos
        /// <summary>
        /// Returns a stable hash value derived from the actual value encoded in this instance.
        /// The system adds "avalanche" effect for better bit distribution
        /// </summary>
        public ulong GetDistributedStableHash()
        {
            switch (DataType)
            {
            case Type.Uninitialized: return(0);

            case Type.Gdid:  return(ForUlong(Buffer.GetDistributedStableHash()));

            case Type.Atom:  return(ForUlong(new Atom(Buffer.ID).GetDistributedStableHash()));

            case Type.EntityId: return(EntityId.Parse(ObjectValue as string).GetDistributedStableHash());//EntityId is already distributed

            case Type.Ulong: return(ForUlong(Buffer.ID));

            case Type.Uint:  return(ForUlong(Buffer.ID));

            case Type.DateTime: return(ForUlong(Buffer.ID));

            case Type.IDistributedStableHashProvider:
            {
                if (ObjectValue == null)
                {
                    return(0ul);
                }
                return(ForUlong(((IDistributedStableHashProvider)ObjectValue).GetDistributedStableHash()));
            }

            case Type.Guid:
            {
                if (ObjectValue == null)
                {
                    return(0ul);
                }
                return(ForBytes((byte[])ObjectValue));
            }

            case Type.String:
            {
                if (ObjectValue == null)
                {
                    return(0ul);
                }
                return(ForString((string)ObjectValue));
            }

            case Type.ByteArray:
            {
                if (ObjectValue == null)
                {
                    return(0ul);
                }
                return(ForBytes((byte[])ObjectValue));
            }
            }

            throw new DataException(StringConsts.SHARDING_OBJECT_ID_ERROR.Args(DataType));
        }
예제 #4
0
파일: KeyStructs.cs 프로젝트: uzbekdev1/nfx
 public ulong GetDistributedStableHash()
 {
     return(GDID.GetDistributedStableHash() ^ (ulong)ISO);
 }
예제 #5
0
파일: Todo.cs 프로젝트: rstonkus/azos
 public ulong GetDistributedStableHash()
 {
     return(m_SysID.GetDistributedStableHash());
 }
예제 #6
0
파일: ItemId.cs 프로젝트: rstonkus/azos
 public ulong GetDistributedStableHash() => Id.GetDistributedStableHash();