Ejemplo n.º 1
0
 /// <summary>Copy constructor.</summary>
 /// <param name="other">The ArrayCoreMap to copy. It may not be null.</param>
 public ArrayCoreMap(Edu.Stanford.Nlp.Util.ArrayCoreMap other)
 {
     // size starts at 0
     size   = other.size;
     keys   = Arrays.CopyOf(other.keys, size);
     values = Arrays.CopyOf(other.values, size);
 }
Ejemplo n.º 2
0
        private bool Equals(Edu.Stanford.Nlp.Util.ArrayCoreMap other)
        {
            TwoDimensionalMap <ICoreMap, ICoreMap, bool> calledMap = equalsCalled.Get();
            bool createdCalledMap = (calledMap == null);

            if (createdCalledMap)
            {
                calledMap = TwoDimensionalMap.IdentityHashMap();
                equalsCalled.Set(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.Contains(this, other))
            {
                return(true);
            }
            bool result = true;

            calledMap.Put(this, other, true);
            calledMap.Put(other, this, true);
            if (this.size != other.size)
            {
                result = false;
            }
            else
            {
                for (int i = 0; i < this.size; i++)
                {
                    // test if other contains this key,value pair
                    bool matched = false;
                    for (int j = 0; j < other.size; 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.Set(null);
            }
            return(result);
        }