public override bool DeleteEdge(T v1, T v2)
        {
            if (v1 is null)
            {
                throw new ArgumentNullException(nameof(v1));
            }

            if (v2 is null)
            {
                throw new ArgumentNullException(nameof(v2));
            }

            IPairValue <T> pair_1 = new PairValueI <T>(v1, v2);
            IPairValue <T> pair_2 = new PairValueI <T>(v2, v1);

            if (EdgeSet.Contains(pair_1) || EdgeSet.Contains(pair_2))
            {
                EdgeSet.Remove(pair_1);
                Weights.Remove(pair_1);

                EdgeSet.Remove(pair_2);
                Weights.Remove(pair_2);
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        public override bool AddEdge(T v1, T v2, K weight)
        {
            if (v1 is null)
            {
                throw new ArgumentNullException(nameof(v1));
            }

            if (v2 is null)
            {
                throw new ArgumentNullException(nameof(v2));
            }

            if (weight is null)
            {
                throw new ArgumentNullException(nameof(weight));
            }

            if (!VertexSet.Contains(v1) || !VertexSet.Contains(v2))
            {
                return(false);
            }

            IPairValue <T> pair = new PairValueI <T>(v1, v2);

            if (EdgeSet.Contains(pair))
            {
                return(false);
            }

            EdgeSet.Add(pair);
            Weights[pair] = weight;
            return(true);
        }
Esempio n. 3
0
        public override bool Equals(object o) // Returns true if, passed another object, it has the same type (PairValueImplementation)
        //And its left-reght members are equal to those of the object in consideration.
        {
            if (o == null || o.GetType() != typeof(PairValueI <T>))
            {
                return(false);
            }

            PairValueI <T> casted = (PairValueI <T>)o;

            return(casted._t1.Equals(_t1) && casted._t2.Equals(_t2));
        }
        public override K GetWeight(T v1, T v2)
        {
            if (v1 is null)
            {
                throw new ArgumentNullException(nameof(v1));
            }

            if (v2 is null)
            {
                throw new ArgumentNullException(nameof(v2));
            }

            IPairValue <T> pair = new PairValueI <T>(v1, v2);

            if (!Weights.ContainsKey(pair))
            {
                throw new ArgumentException();
            }
            return(Weights[pair]);
        }