Example #1
0
        public override void Put(uint index, BoxedValue value)
        {
            if (index == uint.MaxValue)
            {
                base.Put(index.ToString(), value);
                return;
            }

            if (this.isDense)
            {
                var denseLength = (uint)this.dense.Length;

                if (index < denseLength)
                {
                    this.dense[index].Value    = value;
                    this.dense[index].HasValue = true;
                    if (index >= this.length)
                    {
                        this.Length = index + 1;
                    }
                    return;
                }
                else if (index < (denseLength + 10))
                {
                    // We're above the currently allocated dense size
                    // but not far enough above to switch to sparse
                    // so we expand the dense array
                    this.ResizeDense(denseLength * 2 + 10);
                    this.dense[index].Value    = value;
                    this.dense[index].HasValue = true;
                    this.Length = index + 1;
                    return;
                }
                else
                {
                    // Switch to sparse array
                    this.sparse  = SparseArray.OfDense(this.dense);
                    this.dense   = null;
                    this.isDense = false;

                    // Fall through to the sparse handling below.
                }
            }

            sparse.Put(index, value);
            if (index >= length)
            {
                this.Length = index + 1;  //INFO: I changed this from setting the field to setting the property, like above.  This means that it stores the value on the base object as well.
            }
        }