Exemple #1
0
        /// <summary>
        /// Utility that could be on SortedSet. Allows faster implementation than
        /// what is in .NET for doing UnionWith, ExceptWith, IntersectWith, (complementAll).
        /// </summary>
        /// <typeparam name="T">Type of element. Must implement <see cref="IComparable{T}"/>.</typeparam>
        /// <param name="a">First set.</param>
        /// <param name="relation">Relation the relation filter, using <see cref="ANY"/>, <see cref="CONTAINS"/>, etc.</param>
        /// <param name="b">Second set.</param>
        /// <returns>The new set.</returns>
        public static SortedSet <T> DoOperation <T>(SortedSet <T> a, int relation, SortedSet <T> b) where T : IComparable <T>
        {
            // TODO: optimize this as above
            SortedSet <T> temp;

            switch (relation)
            {
            case ADDALL:
                a.UnionWith(b);
                return(a);

            case A:
                return(a);    // no action

            case B:
                a.Clear();
                a.UnionWith(b);
                return(a);

            case REMOVEALL:
                a.ExceptWith(b);
                return(a);

            case RETAINALL:
                a.IntersectWith(b);
                return(a);

            // the following is the only case not really supported by .NET
            // although all could be optimized
            case COMPLEMENTALL:
                temp = new SortedSet <T>(b, GenericComparer.NaturalComparer <T>());
                temp.ExceptWith(a);
                a.ExceptWith(b);
                a.UnionWith(temp);
                // a.SymmetricExceptWith(b); // ICU4N TODO: This should be the equivalent in .NET (need to test it)
                return(a);

            case B_REMOVEALL:
                temp = new SortedSet <T>(b, GenericComparer.NaturalComparer <T>());
                temp.ExceptWith(a);
                a.Clear();
                a.UnionWith(temp);
                return(a);

            case NONE:
                a.Clear();
                return(a);

            default:
                throw new ArgumentException("Relation " + relation + " out of range");
            }
        }
Exemple #2
0
        public static bool VerifySetsIdentical(AbstractTestLog here, ISet <T> values1, ISet <T> values2)
        {
            if (SetEqualityComparer <T> .Aggressive.Equals(values1, values2))
            {
                return(true);
            }
            ISet <T> temp;

            TestFmwk.Errln("Values differ:");
            TestFmwk.Errln("UnicodeMap - HashMap");
            temp = new JCG.SortedSet <T>(values1, GenericComparer.NaturalComparer <T>() /*JCG.Comparer<T>.Default*/);
            temp.ExceptWith(values2);
            TestFmwk.Errln(Show(temp));
            TestFmwk.Errln("HashMap - UnicodeMap");
            temp = new JCG.SortedSet <T>(values2, GenericComparer.NaturalComparer <T>() /*JCG.Comparer<T>.Default*/);
            temp.ExceptWith(values1);
            TestFmwk.Errln(Show(temp));
            return(false);
        }
Exemple #3
0
        public static bool VerifySetsIdentical(AbstractTestLog here, ISet <T> values1, ISet <T> values2)
        {
            if (CollectionUtil.Equals(values1, values2))
            {
                return(true);
            }
            ISet <T> temp;

            TestFmwk.Errln("Values differ:");
            TestFmwk.Errln("UnicodeMap - HashMap");
            temp = new SortedSet <T>(values1, GenericComparer.NaturalComparer <T>());
            temp.ExceptWith(values2);
            TestFmwk.Errln(Show(temp));
            TestFmwk.Errln("HashMap - UnicodeMap");
            temp = new SortedSet <T>(values2, GenericComparer.NaturalComparer <T>());
            temp.ExceptWith(values1);
            TestFmwk.Errln(Show(temp));
            return(false);
        }