コード例 #1
0
ファイル: TSharpflake.cs プロジェクト: inthefabric/Fabric
        public void UniqueIds(int pMaxParallel)
        {
            var map   = new Dictionary <long, int>();
            int count = 0;
            var opt   = new ParallelOptions {
                MaxDegreeOfParallelism = pMaxParallel
            };

            Parallel.For(0, 100000, opt, (i, state) => {
                long id = Sharpflake.GetId <Vertex>();

                lock ( map ) {
                    if (map.ContainsKey(id))
                    {
                        Assert.Fail("Duplicate ID '" + id + "' at index '" + count + "'.");
                    }

                    map.Add(id, count);
                    ++count;
                }
            });

            /*foreach ( long id in map.Keys ) {
             *      Log.Debug("ID: "+id+" / "+GetIdComponentString(id, true)+" / "+
             *              GetIdComponentString(id, false));
             * }*/
        }
コード例 #2
0
 /*--------------------------------------------------------------------------------------------*/
 public override long GetSharpflakeId <T>()
 {
     lock (this) {
         long id = Sharpflake.GetId <T>();
         SharpflakeIds.Add(id);
         return(id);
     }
 }
コード例 #3
0
 /*--------------------------------------------------------------------------------------------*/
 public virtual long GetSharpflakeId <T>() where T : IVertex
 {
     return(Sharpflake.GetId <T>());
 }