Exemple #1
0
        public void map(PatternCollector collector)
        {
            m_collector = collector;
            Debug.Assert(null != collector);
            int    i, j, c;
            ushort f1, f2;
            bool   cycle;

            byte[] keys;

            c = 0;
            var rnd = new Random();

            do
            {
                initGraph();
                cycle = false;

                /* Randomly generate T1 and T2 */
                for (i = 0; i < SetSize * EntryLen; i++)
                {
                    T1base[i] = (ushort)rnd.Next(NumVert);
                    T2base[i] = (ushort)rnd.Next(NumVert);
                }

                for (i = 0; i < NumEntry; i++)
                {
                    f1   = 0; f2 = 0;
                    keys = m_collector.getKey(i);
                    for (j = 0; j < EntryLen; j++)
                    {
                        f1 += T1base[j * SetSize + (keys[j] - SetMin)];
                        f2 += T2base[j * SetSize + (keys[j] - SetMin)];
                    }
                    f1 %= (ushort)NumVert;
                    f2 %= (ushort)NumVert;
                    if (f1 == f2)
                    {
                        /* A self loop. Reject! */
                        Debug.Print("Self loop on vertex %d!\n", f1);
                        cycle = true;
                        break;
                    }
                    addToGraph(numEdges++, f1, f2);
                }
                if (cycle || (cycle = isCycle()))   /* OK - is there a cycle? */
                {
                    Debug.Print("Iteration {0}", ++c);
                }
                else
                {
                    break;
                }
            }while (/* there is a cycle */ true);
        }
Exemple #2
0
        /* Part 1 of creating the tables */
        public void map(PatternCollector collector)
        {
            m_collector = collector;
            Debug.Assert(null != collector);
            int i, j, c;
            ushort f1, f2;
            bool cycle;
            byte[] keys;

            c = 0;
            var rnd = new Random();
            do
            {
                initGraph();
                cycle = false;

                /* Randomly generate T1 and T2 */
                for (i = 0; i < SetSize * EntryLen; i++)
                {
                    T1base[i] = (ushort)rnd.Next(NumVert);
                    T2base[i] = (ushort)rnd.Next(NumVert);
                }

                for (i = 0; i < NumEntry; i++)
                {
                    f1 = 0; f2 = 0;
                    keys = m_collector.getKey(i);
                    for (j = 0; j < EntryLen; j++)
                    {
                        f1 += T1base[ j * SetSize +(keys[j] - SetMin)];
                        f2 += T2base[ j * SetSize + (keys[j] - SetMin)];
                    }
                    f1 %= (ushort)NumVert;
                    f2 %= (ushort)NumVert;
                    if (f1 == f2)
                    {
                        /* A self loop. Reject! */
                        Debug.Print("Self loop on vertex %d!\n", f1);
                        cycle = true;
                        break;
                    }
                    addToGraph(numEdges++, f1, f2);
                }
                if (cycle || (cycle = isCycle()))   /* OK - is there a cycle? */
                {
                    Debug.Print("Iteration {0}", ++c);
                }
                else
                {
                    break;
                }
            }
            while (/* there is a cycle */ true);

        }