示例#1
0
        public EnvironmentDomain <Key, Val> Remove(Key key)
        {
            if (map == null)
            {
                throw new InvalidOperationException();
            }

            return(new EnvironmentDomain <Key, Val>(map.Remove(key)));
        }
示例#2
0
        public EnvironmentDomain <Key, Val> Join(EnvironmentDomain <Key, Val> newState, out bool weaker, bool widen)
        {
            if (map == newState.map)
            {
                weaker = false; return(this);
            }

            bool resultWeaker = false;

            if (this.IsTop)
            {
                weaker = false; return(this);
            }
            if (newState.IsTop)
            {
                weaker = !this.IsTop; return(newState);
            }
            if (this.IsBottom)
            {
                weaker = !newState.IsBottom; return(newState);
            }
            if (newState.IsBottom)
            {
                weaker = false; return(this);
            }

            // compare pointwise
            IFunctionalMap <Key, Val> smaller;
            IFunctionalMap <Key, Val> larger;

            if (map.Count < newState.map.Count)
            {
                smaller = map;
                larger  = newState.map;
            }
            else
            {
                smaller = newState.map;
                larger  = map;
            }
            IFunctionalMap <Key, Val> result = smaller;

            foreach (Key k in smaller.Keys)
            {
                if (!larger.Contains(k))
                {
                    result = result.Remove(k);
                }
                else
                {
                    bool joinWeaker;
                    Val  join = smaller[k].Join(larger[k], out joinWeaker, widen);
                    if (joinWeaker)
                    {
                        resultWeaker = true;
                        if (join.IsTop)
                        {
                            result = result.Remove(k);
                        }
                        else
                        {
                            result = result.Add(k, join);
                        }
                    }
                }
            }
            weaker = resultWeaker || (result.Count < map.Count);
            return(new EnvironmentDomain <Key, Val>(result));
        }