Beispiel #1
0
        public void SetByKey(object key, object value)
        {
            key = FixKey(key);

            // Update heap use throwing an exception on failure
            // before making any changes to the array.
            int    keysize    = HeapTrackerObject.Size(key);
            int    newheapuse = heapUse;
            object oldval;

            if (dnary.TryGetValue(key, out oldval))
            {
                newheapuse -= keysize + HeapTrackerObject.Size(oldval);
            }
            if (value != null)
            {
                newheapuse += keysize + HeapTrackerObject.Size(value);
            }
            heapUse = inst.UpdateArraysHeapUse(heapUse, newheapuse);

            // Save new value in array, replacing one of same key if there.
            // null means remove the value, ie, script did array[key] = undef.
            if (value != null)
            {
                dnary[key] = value;
            }
            else
            {
                dnary.Remove(key);

                // Shrink the enumeration array, but always leave at least one element.
                if ((array != null) && (dnary.Count < array.Length / 2))
                {
                    Array.Resize <KeyValuePair <object, object> >(ref array, array.Length / 2);
                }
            }

            // The enumeration array is invalid because the dictionary has been modified.
            // Next time a ForEach() call happens, it will repopulate 'array' as elements are retrieved.
            arrayValid = 0;
        }
Beispiel #2
0
 public XMR_Array(XMRInstAbstract inst)
 {
     this.inst = inst;
     dnary     = new SortedDictionary <object, object>(XMRArrayKeyComparer.singleton);
     heapUse   = inst.UpdateArraysHeapUse(0, EMPTYHEAP);
 }