Пример #1
0
        /// <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);
        }
Пример #2
0
 // convenience helper function for firing the changing node/edge attribute event (for an attribute of map type, contains graph element type dispatching and fixes the change type to element removal)
 public static void ChangingMapAttributeRemoveElement(IGraph graph, IGraphElement elem, AttributeType attrType, object keyToRemove)
 {
     if (elem is INode)
     {
         graph.ChangingNodeAttribute((INode)elem, attrType, AttributeChangeType.RemoveElement, null, keyToRemove);
     }
     else
     {
         graph.ChangingEdgeAttribute((IEdge)elem, attrType, AttributeChangeType.RemoveElement, null, keyToRemove);
     }
 }
Пример #3
0
 // convenience helper function for firing the changing node/edge attribute event (for an attribute of map type, contains graph element type dispatching and fixes the change type to element addition)
 public static void ChangingMapAttributePutElement(IGraph graph, IGraphElement elem, AttributeType attrType, object key, object value)
 {
     if (elem is INode)
     {
         graph.ChangingNodeAttribute((INode)elem, attrType, AttributeChangeType.PutElement, value, key);
     }
     else
     {
         graph.ChangingEdgeAttribute((IEdge)elem, attrType, AttributeChangeType.PutElement, value, key);
     }
 }
Пример #4
0
 // convenience helper function for firing the changing node/edge attribute event (contains graph element type dispatching and fixes the change type to assignment)
 public static void ChangingAttributeAssign(IGraph graph, IGraphElement elem, AttributeType attrType, object value)
 {
     if (elem is INode)
     {
         graph.ChangingNodeAttribute((INode)elem, attrType, AttributeChangeType.Assign, value, null);
     }
     else
     {
         graph.ChangingEdgeAttribute((IEdge)elem, attrType, AttributeChangeType.Assign, value, null);
     }
 }
Пример #5
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);
        }
Пример #6
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);
        }
Пример #7
0
 // convenience helper function for firing the changing node/edge/object attribute event (for an attribute of map type, contains type dispatching and fixes the change type to element removal)
 public static void ChangingMapAttributeRemoveElement(IGraph graph, IAttributeBearer owner, AttributeType attrType, object keyToRemove)
 {
     if (owner is INode)
     {
         graph.ChangingNodeAttribute((INode)owner, attrType, AttributeChangeType.RemoveElement, null, keyToRemove);
     }
     else if (owner is IEdge)
     {
         graph.ChangingEdgeAttribute((IEdge)owner, attrType, AttributeChangeType.RemoveElement, null, keyToRemove);
     }
     else
     {
         graph.ChangingObjectAttribute((IObject)owner, attrType, AttributeChangeType.RemoveElement, null, keyToRemove);
     }
 }
Пример #8
0
 // convenience helper function for firing the changing node/edge/object attribute event (for an attribute of map type, contains type dispatching and fixes the change type to element addition)
 public static void ChangingMapAttributePutElement(IGraph graph, IAttributeBearer owner, AttributeType attrType, object key, object value)
 {
     if (owner is INode)
     {
         graph.ChangingNodeAttribute((INode)owner, attrType, AttributeChangeType.PutElement, value, key);
     }
     else if (owner is IEdge)
     {
         graph.ChangingEdgeAttribute((IEdge)owner, attrType, AttributeChangeType.PutElement, value, key);
     }
     else
     {
         graph.ChangingObjectAttribute((IObject)owner, attrType, AttributeChangeType.PutElement, value, key);
     }
 }
Пример #9
0
 // convenience helper function for firing the changing node/edge/object attribute event (contains type dispatching and fixes the change type to assignment)
 public static void ChangingAttributeAssign(IGraph graph, IAttributeBearer owner, AttributeType attrType, object value)
 {
     if (owner is INode)
     {
         graph.ChangingNodeAttribute((INode)owner, attrType, AttributeChangeType.Assign, value, null);
     }
     else if (owner is IEdge)
     {
         graph.ChangingEdgeAttribute((IEdge)owner, attrType, AttributeChangeType.Assign, value, null);
     }
     else
     {
         graph.ChangingObjectAttribute((IObject)owner, attrType, AttributeChangeType.Assign, value, null);
     }
 }
Пример #10
0
        /// <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);
        }