Ejemplo n.º 1
0
 public override AbstractEdgeMap <T> PutAll(IEdgeMap <T> m)
 {
     if (m.IsEmpty)
     {
         return(this);
     }
     if (m is Antlr4.Runtime.Dfa.ArrayEdgeMap <T> )
     {
         Antlr4.Runtime.Dfa.ArrayEdgeMap <T> other = (Antlr4.Runtime.Dfa.ArrayEdgeMap <T>)m;
         int minOverlap = Math.Max(minIndex, other.minIndex);
         int maxOverlap = Math.Min(maxIndex, other.maxIndex);
         for (int i = minOverlap; i <= maxOverlap; i++)
         {
             T target = other.arrayData[i - other.minIndex];
             if (target != null)
             {
                 T current = this.arrayData[i - this.minIndex];
                 this.arrayData[i - this.minIndex] = target;
                 size += (current != null ? 0 : 1);
             }
         }
         return(this);
     }
     else
     {
         if (m is SingletonEdgeMap <T> )
         {
             SingletonEdgeMap <T> other = (SingletonEdgeMap <T>)m;
             System.Diagnostics.Debug.Assert(!other.IsEmpty);
             return((Antlr4.Runtime.Dfa.ArrayEdgeMap <T>)Put(other.GetKey(), other.GetValue())
                    );
         }
         else
         {
             if (m is SparseEdgeMap <T> )
             {
                 SparseEdgeMap <T> other  = (SparseEdgeMap <T>)m;
                 int[]             keys   = other.GetKeys();
                 IList <T>         values = other.GetValues();
                 Antlr4.Runtime.Dfa.ArrayEdgeMap <T> result = this;
                 for (int i = 0; i < values.Count; i++)
                 {
                     result = ((Antlr4.Runtime.Dfa.ArrayEdgeMap <T>)result.Put(keys[i], values[i]));
                 }
                 return(result);
             }
             else
             {
                 throw new NotSupportedException(string.Format("EdgeMap of type {0} is supported yet."
                                                               , m.GetType().FullName));
             }
         }
     }
 }
Ejemplo n.º 2
0
 public override AbstractEdgeMap <T> PutAll(IEdgeMap <T> m)
 {
     if (m.IsEmpty)
     {
         return(this);
     }
     if (m is Antlr4.Runtime.Dfa.ArrayEdgeMap <T> )
     {
         Antlr4.Runtime.Dfa.ArrayEdgeMap <T> other = (Antlr4.Runtime.Dfa.ArrayEdgeMap <T>)m;
         int minOverlap = Math.Max(minIndex, other.minIndex);
         int maxOverlap = Math.Min(maxIndex, other.maxIndex);
         Antlr4.Runtime.Dfa.ArrayEdgeMap <T> result = this;
         for (int i = minOverlap; i <= maxOverlap; i++)
         {
             result = ((Antlr4.Runtime.Dfa.ArrayEdgeMap <T>)result.Put(i, m[i]));
         }
         return(result);
     }
     else
     {
         if (m is SingletonEdgeMap <T> )
         {
             SingletonEdgeMap <T> other = (SingletonEdgeMap <T>)m;
             System.Diagnostics.Debug.Assert(!other.IsEmpty);
             return(Put(other.Key, other.Value));
         }
         else
         {
             if (m is SparseEdgeMap <T> )
             {
                 SparseEdgeMap <T> other = (SparseEdgeMap <T>)m;
                 lock (other)
                 {
                     int[]     keys   = other.Keys;
                     IList <T> values = other.Values;
                     Antlr4.Runtime.Dfa.ArrayEdgeMap <T> result = this;
                     for (int i = 0; i < values.Count; i++)
                     {
                         result = ((Antlr4.Runtime.Dfa.ArrayEdgeMap <T>)result.Put(keys[i], values[i]));
                     }
                     return(result);
                 }
             }
             else
             {
                 throw new NotSupportedException(string.Format("EdgeMap of type {0} is supported yet.", m.GetType().FullName));
             }
         }
     }
 }