/// <summary>
        /// Removes all key/value pairs from set <paramref name="a"/> whose keys are not also contained in <paramref name="b"/>.
        /// </summary>
        /// <param name="a">A dictionary to change.</param>
        /// <param name="b">Another dictionary of compatible type to <paramref name="a"/>.</param>
        /// <param name="graph">The graph containing the node containing the attribute which gets changed.</param>
        /// <param name="owner">The node containing the attribute which gets changed.</param>
        /// <param name="attrType">The attribute type of the attribute which gets changed.</param>
        /// <returns>A truth value telling whether at least one element was changed in a</returns>
        public static bool IntersectChanged <K>(Dictionary <K, SetValueType> a,
                                                Dictionary <K, SetValueType> b,
                                                IGraph graph, INode owner, AttributeType attrType)
        {
            // First determine all elements from a not contained in b
            List <K> toBeRemoved = new List <K>(a.Count);

            foreach (KeyValuePair <K, SetValueType> entry in a)
            {
                if (!b.ContainsKey(entry.Key))
                {
                    toBeRemoved.Add(entry.Key);
                }
            }

            // Then remove them
            foreach (K key in toBeRemoved)
            {
                graph.ChangingNodeAttribute(owner, attrType, AttributeChangeType.RemoveElement, key, null);
                a.Remove(key);
                graph.ChangedNodeAttribute(owner, attrType);
            }

            return(toBeRemoved.Count > 0);
        }
Exemple #2
0
 // convenience helper function for firing the changed node/edge attribute event (contains graph element type dispatching)
 public static void ChangedAttribute(IGraph graph, IGraphElement elem, AttributeType attrType)
 {
     if (elem is INode)
     {
         graph.ChangedNodeAttribute((INode)elem, attrType);
     }
     else
     {
         graph.ChangedEdgeAttribute((IEdge)elem, attrType);
     }
 }
Exemple #3
0
        /// <summary>
        /// Appends all values from deque <paramref name="b"/> to <paramref name="a"/>.
        /// </summary>
        /// <param name="a">A Deque to change.</param>
        /// <param name="b">Another Deque of compatible type to <paramref name="a"/>.</param>
        /// <param name="graph">The graph containing the node containing the attribute which gets changed.</param>
        /// <param name="owner">The node containing the attribute which gets changed.</param>
        /// <param name="attrType">The attribute type of the attribute which gets changed.</param>
        /// <returns>A truth value telling whether a was changed (i.e. b not empty)</returns>
        public static bool ConcatenateChanged <V>(Deque <V> a, Deque <V> b,
                                                  IGraph graph, INode owner, AttributeType attrType)
        {
            // Append b to a
            foreach (V entry in b)
            {
                graph.ChangingNodeAttribute(owner, attrType, AttributeChangeType.PutElement, entry, null);
                a.Enqueue(entry);
                graph.ChangedNodeAttribute(owner, attrType);
            }

            return(b.Count > 0);
        }
        /// <summary>
        /// Removes all key/value pairs from map <paramref name="a"/> whose keys are contained in <paramref name="b"/>.
        /// </summary>
        /// <param name="a">A dictionary to change.</param>
        /// <param name="b">Another dictionary of compatible key type to <paramref name="a"/>.</param>
        /// <param name="graph">The graph containing the node containing the attribute which gets changed.</param>
        /// <param name="owner">The node containing the attribute which gets changed.</param>
        /// <param name="attrType">The attribute type of the attribute which gets changed.</param>
        /// <returns>A truth value telling whether at least one element was changed in a</returns>
        public static bool ExceptChanged <K, V, W>(Dictionary <K, V> a, Dictionary <K, W> b,
                                                   IGraph graph, INode owner, AttributeType attrType)
        {
            bool changed = false;

            // Remove all elements from a contained in b.
            foreach (KeyValuePair <K, W> entry in b)
            {
                graph.ChangingNodeAttribute(owner, attrType, AttributeChangeType.RemoveElement, null, entry.Key);
                changed |= a.Remove(entry.Key);
                graph.ChangedNodeAttribute(owner, attrType);
            }

            return(changed);
        }
        /// <summary>
        /// Adds all key/value pairs from map <paramref name="b"/> to <paramref name="a"/>.
        /// If both dictionaries contain one key, the value from <paramref name="b"/> takes precedence
        /// (this way the common case "a = a | map<int, int> { 7 -> 13 };" would update an existing entry
        /// with key 7 to 13).
        /// </summary>
        /// <param name="a">A dictionary to change.</param>
        /// <param name="b">Another dictionary of compatible type to <paramref name="a"/>.</param>
        /// <param name="graph">The graph containing the node containing the attribute which gets changed.</param>
        /// <param name="owner">The node containing the attribute which gets changed.</param>
        /// <param name="attrType">The attribute type of the attribute which gets changed.</param>
        /// <returns>A truth value telling whether at least one element was changed in a</returns>
        public static bool UnionChanged <K, V>(Dictionary <K, V> a, Dictionary <K, V> b,
                                               IGraph graph, INode owner, AttributeType attrType)
        {
            bool changed = false;

            // Add all elements from b not contained in a (different values count as not contained, overwriting old value).
            foreach (KeyValuePair <K, V> entry in b)
            {
                if (!a.ContainsKey(entry.Key) || EqualityComparer <V> .Default.Equals(a[entry.Key], entry.Value))
                {
                    graph.ChangingNodeAttribute(owner, attrType, AttributeChangeType.PutElement, entry.Value, entry.Key);
                    a[entry.Key] = entry.Value;
                    graph.ChangedNodeAttribute(owner, attrType);
                    changed = true;
                }
            }

            return(changed);
        }