Exemplo n.º 1
0
 static void check(Incrementor inc, ref long rollingKey, byte nb, long mask)
 {
     if (nb == 255)
     {
         return;
     }
     rollingKey = ((rollingKey & mask) << 2) | nb;
     inc.Increment(rollingKey);
 }
Exemplo n.º 2
0
        static Task <string> count(int l, long mask, Func <Dictionary <long, int>, string> summary)
        {
            return(Task.Run(() =>
            {
                long rollingKey = 0;
                var firstBlock = threeBlocks[0];
                var start = threeStart;
                while (--l > 0)
                {
                    rollingKey = (rollingKey << 2) | firstBlock[start++];
                }
                var dict = new Dictionary <long, int>(1024);
                using (var incrementor = new Incrementor(dict))
                {
                    for (int i = start; i < firstBlock.Length; i++)
                    {
                        check(incrementor, ref rollingKey, firstBlock[i], mask);
                    }

                    int lastBlockId = threeBlocks.Count - 1;
                    for (int bl = 1; bl < lastBlockId; bl++)
                    {
                        var bytes = threeBlocks[bl];
                        for (int i = 0; i < bytes.Length; i++)
                        {
                            check(incrementor, ref rollingKey, bytes[i], mask);
                        }
                    }

                    var lastBlock = threeBlocks[lastBlockId];
                    for (int i = 0; i < threeEnd; i++)
                    {
                        check(incrementor, ref rollingKey, lastBlock[i], mask);
                    }
                }
                return summary(dict);
            }));
        }