Пример #1
0
        public TupleDomain <U> Transform <U>(Func <T, U> function)
        {
            if (this.Domains == null)
            {
                return(TupleDomain <U> .None());
            }

            IDictionary <U, Domain> Result = new Dictionary <U, Domain>();

            foreach (KeyValuePair <T, Domain> Entry in this.Domains)
            {
                U Key = function.Invoke(Entry.Key);

                if (Key == null)
                {
                    continue;
                }

                if (Result.ContainsKey(Key))
                {
                    throw new ArgumentException($"Every argument must have a unique mapping, {Key.ToString()} maps to {Entry.Value.ToString()} and {Result[Key].ToString()}.");
                }

                Result.Add(Key, Entry.Value);
            }

            return(TupleDomain <U> .WithColumnDomains(Result));
        }
Пример #2
0
        /// <summary>
        /// Extract all column constraints that require exactly one value or only null in their respective Domains.
        /// Returns an empty Optional if the Domain is none.
        /// </summary>
        /// <param name="tupleDomain"></param>
        /// <returns></returns>
        public static IDictionary <T, object> ExtractFixedValues(TupleDomain <T> tupleDomain)
        {
            if (tupleDomain.Domains == null)
            {
                return(null);
            }

            return(tupleDomain.Domains.Where(x => x.Value.IsNullableSingleValue()).ToDictionary(x => x.Key, x => (object)x.Value));
        }
Пример #3
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }

            if (obj == null || this.GetType() != obj.GetType())
            {
                return(false);
            }

            TupleDomain <T> Other = (TupleDomain <T>)obj;

            return(Object.Equals(this.Domains, Other.Domains));
        }
Пример #4
0
        public static TupleDomain <T> ColumnWiseUnion(TupleDomain <T> first, TupleDomain <T> second, params TupleDomain <T>[] rest)
        {
            List <TupleDomain <T> > Domains = new List <TupleDomain <T> >();

            if (first != null)
            {
                Domains.Add(first);
            }

            if (second != null)
            {
                Domains.Add(second);
            }

            if (rest != null && rest.Length > 0)
            {
                Domains.AddRange(rest);
            }

            return(ColumnWiseUnion(Domains));
        }
Пример #5
0
        /// <summary>
        /// Returns the strict intersection of the TupleDomains.
        /// The resulting TupleDomain represents the set of tuples that would be valid
        /// in both TupleDomains.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public TupleDomain <T> Intersect(TupleDomain <T> other)
        {
            if (this.IsNone() || other.IsNone())
            {
                return(None());
            }

            IDictionary <T, Domain> Intersected = this.Domains.ToDictionary(x => x.Key, x => x.Value);

            foreach (KeyValuePair <T, Domain> Item in other.Domains)
            {
                if (!Intersected.ContainsKey(Item.Key))
                {
                    Intersected.Add(Item.Key, Item.Value);
                }
                else
                {
                    Intersected[Item.Key] = Item.Value.Intersect(Intersected[Item.Key]);
                }
            }

            return(WithColumnDomains(Intersected));
        }
Пример #6
0
 /// <summary>
 /// Returns true only if the this TupleDomain contains all possible tuples that would be allowable by
 /// the other TupleDomain.
 /// </summary>
 /// <param name="domains"></param>
 /// <returns></returns>
 public bool Contains(TupleDomain <T> other)
 {
     return(other.IsNone() || ColumnWiseUnion(this, other).Equals(this));
 }
Пример #7
0
 /// <summary>
 /// Returns true only if there exists a strict intersection between the TupleDomains.
 /// i.e. there exists some potential tuple that would be allowable in both TupleDomains.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Overlaps(TupleDomain <T> other)
 {
     return(!this.Intersect(other).IsNone());
 }