Пример #1
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="other">The ArrayCoreMap to copy. It may not be null.</param>
 public ArrayCoreMap(ArrayCoreMap other)
 {
     psize = other.psize;
     keys = other.keys.Take(psize).ToArray();
     values = other.values.Take(psize).ToArray();
 }
Пример #2
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="other">The ArrayCoreMap to copy. It may not be null.</param>
 public ArrayCoreMap(ArrayCoreMap other)
 {
     psize  = other.psize;
     keys   = other.keys.Take(psize).ToArray();
     values = other.values.Take(psize).ToArray();
 }
Пример #3
0
        private bool Equals(ArrayCoreMap other)
        {
            Dictionary<Tuple<ICoreMap, ICoreMap>, Boolean> calledMap = EqualsCalled.Value;
            bool createdCalledMap = (calledMap == null);
            if (createdCalledMap)
            {
                calledMap = new Dictionary<Tuple<ICoreMap, ICoreMap>, bool>();
                EqualsCalled.Value = calledMap;
            }

            // Note that for the purposes of recursion, we assume the two maps
            // are equals.  The two maps will therefore be equal if they
            // encounter each other again during the recursion unless there is
            // some other key that causes the equality to fail.
            // We do not need to later put false, as the entire call to equals
            // will unwind with false if any one equality check returns false.
            // TODO: since we only ever keep "true", we would rather use a
            // TwoDimensionalSet, but no such thing exists
            if (calledMap.ContainsKey(new Tuple<ICoreMap, ICoreMap>(this, other)))
            {
                return true;
            }
            bool result = true;
            calledMap.Add(new Tuple<ICoreMap, ICoreMap>(this, other), true);
            calledMap.Add(new Tuple<ICoreMap, ICoreMap>(other, this), true);

            if (this.psize != other.psize)
            {
                result = false;
            }
            else
            {
                for (int i = 0; i < this.psize; i++)
                {
                    // test if other contains this key,value pair
                    bool matched = false;
                    for (int j = 0; j < other.psize; j++)
                    {
                        if (this.keys[i] == other.keys[j])
                        {
                            if ((this.values[i] == null && other.values[j] != null) ||
                                (this.values[i] != null && other.values[j] == null))
                            {
                                matched = false;
                                break;
                            }

                            if ((this.values[i] == null && other.values[j] == null) ||
                                (this.values[i].Equals(other.values[j])))
                            {
                                matched = true;
                                break;
                            }
                        }
                    }

                    if (!matched)
                    {
                        result = false;
                        break;
                    }
                }
            }

            if (createdCalledMap)
            {
                EqualsCalled.Value = null;
            }
            return result;
        }
Пример #4
0
        private bool Equals(ArrayCoreMap other)
        {
            Dictionary <Tuple <ICoreMap, ICoreMap>, Boolean> calledMap = EqualsCalled.Value;
            bool createdCalledMap = (calledMap == null);

            if (createdCalledMap)
            {
                calledMap          = new Dictionary <Tuple <ICoreMap, ICoreMap>, bool>();
                EqualsCalled.Value = calledMap;
            }

            // Note that for the purposes of recursion, we assume the two maps
            // are equals.  The two maps will therefore be equal if they
            // encounter each other again during the recursion unless there is
            // some other key that causes the equality to fail.
            // We do not need to later put false, as the entire call to equals
            // will unwind with false if any one equality check returns false.
            // TODO: since we only ever keep "true", we would rather use a
            // TwoDimensionalSet, but no such thing exists
            if (calledMap.ContainsKey(new Tuple <ICoreMap, ICoreMap>(this, other)))
            {
                return(true);
            }
            bool result = true;

            calledMap.Add(new Tuple <ICoreMap, ICoreMap>(this, other), true);
            calledMap.Add(new Tuple <ICoreMap, ICoreMap>(other, this), true);

            if (this.psize != other.psize)
            {
                result = false;
            }
            else
            {
                for (int i = 0; i < this.psize; i++)
                {
                    // test if other contains this key,value pair
                    bool matched = false;
                    for (int j = 0; j < other.psize; j++)
                    {
                        if (this.keys[i] == other.keys[j])
                        {
                            if ((this.values[i] == null && other.values[j] != null) ||
                                (this.values[i] != null && other.values[j] == null))
                            {
                                matched = false;
                                break;
                            }

                            if ((this.values[i] == null && other.values[j] == null) ||
                                (this.values[i].Equals(other.values[j])))
                            {
                                matched = true;
                                break;
                            }
                        }
                    }

                    if (!matched)
                    {
                        result = false;
                        break;
                    }
                }
            }

            if (createdCalledMap)
            {
                EqualsCalled.Value = null;
            }
            return(result);
        }