System.Net.WebPermission.intersectList C# (CSharp) Method

intersectList() private static method

private static intersectList ( ArrayList A, ArrayList B, ArrayList result ) : void
A System.Collections.ArrayList
B System.Collections.ArrayList
result System.Collections.ArrayList
return void
        private static void intersectList(ArrayList A, ArrayList B, ArrayList result) {
            bool[]  aDone = new bool[A.Count];
            bool[]  bDone = new bool[B.Count];
            int     ia=0, ib;

            // The optimization is done according to the following truth
            // (A|B|C) intersect (B|C|E|D)) == B|C|(A inter E)|(A inter D)
            //
            // We also check on any duplicates in the result

            // Round 1st
            // Getting rid of same permissons in the input arrays (assuming X /\ X = X)
            foreach (object a in  A) {
                ib = 0;
                foreach (object b in  B) {

                    // check to see if b is in the result already
                    if (!bDone[ib]) {

                        //if both are regexes or both are Uris or both are strings
                        if (a.GetType() == b.GetType())
                        {
                            if (a is Uri)
                            {
                                // both are uris
                                if (a.Equals(b))
                                {
                                    result.Add(a);
                                    aDone[ia]=bDone[ib]=true;
                                    //since permissions are ORed we can break and go to the next A
                                    break;
                                }
                            }
                            else
                            {
                                // regexes and strings uses ToString() output
                                if (string.Compare(a.ToString(), b.ToString(), StringComparison.OrdinalIgnoreCase ) == 0)
                                {
                                    result.Add(a);
                                    aDone[ia]=bDone[ib]=true;
                                    //since permissions are ORed we can break and go to the next A
                                    break;
                                }
                            }
                        }
                    }
                    ++ib;
                } //foreach b in B
                ++ia;
            } //foreach a in A

            ia = 0;
            // Round second
            // Grab only intersections of objects not found in both A and B
            foreach (object a in  A) {

                if (!aDone[ia]) {
                    ib = 0;
                    foreach(object b in B) {

                        if (!bDone[ib]) {
                            bool resultUri;
                            object intesection = intersectPair(a, b, out resultUri);

                            if (intesection != null) {
                                bool found = false;
                                // check to see if we already have the same result
                                foreach (object obj in result) {
                                    if (resultUri == (obj is Uri))
                                    {
                                        if(resultUri
                                           ? intesection.Equals(obj)
                                           : string.Compare(obj.ToString(), intesection.ToString(), StringComparison.OrdinalIgnoreCase ) == 0)
                                        {
                                            found = true;
                                            break;
                                        }
                                    }
                                }

                                if (!found) {
                                    result.Add(intesection);
                                }
                            }
                        }
                        ++ib;
                    }
                }
                ++ia;
            }
        }