예제 #1
0
        /// <devdoc>
        /// Stores the given value in the key.
        /// </devdoc>
        public void SetInteger(int key, int value)
        {
            short entryKey = SplitKey(key, out short element);

            if (!LocateIntegerEntry(entryKey, out int index))
            {
                // We must allocate a new entry.
                if (s_intEntries != null)
                {
                    IntegerEntry[] newEntries = new IntegerEntry[s_intEntries.Length + 1];

                    if (index > 0)
                    {
                        Array.Copy(s_intEntries, 0, newEntries, 0, index);
                    }

                    if (s_intEntries.Length - index > 0)
                    {
                        Array.Copy(s_intEntries, index, newEntries, index + 1, s_intEntries.Length - index);
                    }

                    s_intEntries = newEntries;
                }
                else
                {
                    s_intEntries = new IntegerEntry[1];
                    Debug.Assert(index == 0, "LocateIntegerEntry should have given us a zero index.");
                }

                s_intEntries[index].Key = entryKey;
            }

            // Now determine which value to set.
            switch (element)
            {
            case 0:
                s_intEntries[index].Value1 = value;
                break;

            case 1:
                s_intEntries[index].Value2 = value;
                break;

            case 2:
                s_intEntries[index].Value3 = value;
                break;

            case 3:
                s_intEntries[index].Value4 = value;
                break;

            default:
                Debug.Fail("Invalid element obtained from LocateIntegerEntry");
                break;
            }

            s_intEntries[index].Mask = (short)((1 << element) | (ushort)(s_intEntries[index].Mask));
        }
예제 #2
0
        public void SetInteger(int key, int value)
        {
            int   num;
            short num2;
            short entryKey = this.SplitKey(key, out num2);

            if (!this.LocateIntegerEntry(entryKey, out num))
            {
                if (this.intEntries != null)
                {
                    IntegerEntry[] destinationArray = new IntegerEntry[this.intEntries.Length + 1];
                    if (num > 0)
                    {
                        Array.Copy(this.intEntries, 0, destinationArray, 0, num);
                    }
                    if ((this.intEntries.Length - num) > 0)
                    {
                        Array.Copy(this.intEntries, num, destinationArray, num + 1, this.intEntries.Length - num);
                    }
                    this.intEntries = destinationArray;
                }
                else
                {
                    this.intEntries = new IntegerEntry[1];
                }
                this.intEntries[num].Key = entryKey;
            }
            switch (num2)
            {
            case 0:
                this.intEntries[num].Value1 = value;
                break;

            case 1:
                this.intEntries[num].Value2 = value;
                break;

            case 2:
                this.intEntries[num].Value3 = value;
                break;

            case 3:
                this.intEntries[num].Value4 = value;
                break;
            }
            this.intEntries[num].Mask = (short)((((int)1) << num2) | ((ushort)this.intEntries[num].Mask));
        }
예제 #3
0
        public void RemoveInteger(int key)
        {
            int   num;
            short num2;
            short entryKey = this.SplitKey(key, out num2);

            if (this.LocateIntegerEntry(entryKey, out num) && (((((int)1) << num2) & this.intEntries[num].Mask) != 0))
            {
                this.intEntries[num].Mask = (short)(this.intEntries[num].Mask & ~((short)(((int)1) << num2)));
                if (this.intEntries[num].Mask == 0)
                {
                    IntegerEntry[] destinationArray = new IntegerEntry[this.intEntries.Length - 1];
                    if (num > 0)
                    {
                        Array.Copy(this.intEntries, 0, destinationArray, 0, num);
                    }
                    if (num < destinationArray.Length)
                    {
                        Array.Copy(this.intEntries, num + 1, destinationArray, num, (this.intEntries.Length - num) - 1);
                    }
                    this.intEntries = destinationArray;
                }
                else
                {
                    switch (num2)
                    {
                    case 0:
                        this.intEntries[num].Value1 = 0;
                        return;

                    case 1:
                        this.intEntries[num].Value2 = 0;
                        return;

                    case 2:
                        this.intEntries[num].Value3 = 0;
                        return;

                    case 3:
                        this.intEntries[num].Value4 = 0;
                        return;
                    }
                }
            }
        }
        public void SetInteger(int key, int value)
        {
            int num;
            short num2;
            short entryKey = this.SplitKey(key, out num2);
            if (!this.LocateIntegerEntry(entryKey, out num))
            {
                if (this.intEntries != null)
                {
                    IntegerEntry[] destinationArray = new IntegerEntry[this.intEntries.Length + 1];
                    if (num > 0)
                    {
                        Array.Copy(this.intEntries, 0, destinationArray, 0, num);
                    }
                    if ((this.intEntries.Length - num) > 0)
                    {
                        Array.Copy(this.intEntries, num, destinationArray, num + 1, this.intEntries.Length - num);
                    }
                    this.intEntries = destinationArray;
                }
                else
                {
                    this.intEntries = new IntegerEntry[1];
                }
                this.intEntries[num].Key = entryKey;
            }
            switch (num2)
            {
                case 0:
                    this.intEntries[num].Value1 = value;
                    break;

                case 1:
                    this.intEntries[num].Value2 = value;
                    break;

                case 2:
                    this.intEntries[num].Value3 = value;
                    break;

                case 3:
                    this.intEntries[num].Value4 = value;
                    break;
            }
            this.intEntries[num].Mask = (short) ((((int) 1) << num2) | ((ushort) this.intEntries[num].Mask));
        }
        public void RemoveInteger(int key)
        {
            int num;
            short num2;
            short entryKey = this.SplitKey(key, out num2);
            if (this.LocateIntegerEntry(entryKey, out num) && (((((int) 1) << num2) & this.intEntries[num].Mask) != 0))
            {
                this.intEntries[num].Mask = (short) (this.intEntries[num].Mask & ~((short) (((int) 1) << num2)));
                if (this.intEntries[num].Mask == 0)
                {
                    IntegerEntry[] destinationArray = new IntegerEntry[this.intEntries.Length - 1];
                    if (num > 0)
                    {
                        Array.Copy(this.intEntries, 0, destinationArray, 0, num);
                    }
                    if (num < destinationArray.Length)
                    {
                        Array.Copy(this.intEntries, num + 1, destinationArray, num, (this.intEntries.Length - num) - 1);
                    }
                    this.intEntries = destinationArray;
                }
                else
                {
                    switch (num2)
                    {
                        case 0:
                            this.intEntries[num].Value1 = 0;
                            return;

                        case 1:
                            this.intEntries[num].Value2 = 0;
                            return;

                        case 2:
                            this.intEntries[num].Value3 = 0;
                            return;

                        case 3:
                            this.intEntries[num].Value4 = 0;
                            return;
                    }
                }
            }
        }
예제 #6
0
        /// <devdoc>
        ///     Stores the given value in the key.
        /// </devdoc>
        public void SetInteger(int key, int value) {
            int   index;
            short element;
            short entryKey = SplitKey(key, out element);
            
            if (!LocateIntegerEntry(entryKey, out index)) {
                
                // We must allocate a new entry.
                //
                if (intEntries != null) {
                    IntegerEntry[] newEntries = new IntegerEntry[intEntries.Length + 1];
                    
                    if (index > 0) {
                        Array.Copy(intEntries, 0, newEntries, 0, index);
                    }
                    
                    if (intEntries.Length - index > 0) {
                        Array.Copy(intEntries, index, newEntries, index + 1, intEntries.Length - index);
                    }
                    
                    intEntries = newEntries;
                }
                else {
                    intEntries = new IntegerEntry[1];
                    Debug.Assert(index == 0, "LocateIntegerEntry should have given us a zero index.");
                }
            
                intEntries[index].Key = entryKey;
            }
        
            // Now determine which value to set.
            //
            switch(element) {
                case 0:
                    intEntries[index].Value1 = value;
                    break;
                    
                case 1:
                    intEntries[index].Value2 = value;
                    break;
                    
                case 2:
                    intEntries[index].Value3 = value;
                    break;
                    
                case 3:
                    intEntries[index].Value4 = value;
                    break;
                    
                default:
                    Debug.Fail("Invalid element obtained from LocateIntegerEntry");
                    break;
            }

            intEntries[index].Mask = (short)((1 << element) | (ushort)(intEntries[index].Mask));
        }
예제 #7
0
/*
        public Color RemoveColor(int key) {
            RemoveObject(key);
        }
*/
        /// <devdoc>
        ///     Removes the given key from the array
        /// </devdoc>
        public void RemoveInteger(int key) {
            int   index;
            short element;
            short entryKey = SplitKey(key, out element);
                
            if (LocateIntegerEntry(entryKey, out index)) {
                if (((1 << element) & intEntries[index].Mask) == 0) {
                    // this element is not being used - return right away
                    return;
                }

                // declare that the element is no longer used
                intEntries[index].Mask &= (short) (~((short)(1 << element)));

                if (intEntries[index].Mask == 0) {
                    // this object entry is no longer in use - let's remove it all together
                    // not great for perf but very simple and we don't expect to remove much
                    IntegerEntry[] newEntries = new IntegerEntry[intEntries.Length - 1];
                    if (index > 0) {
                        Array.Copy(intEntries, 0, newEntries, 0, index);
                    }
                    if (index < newEntries.Length) {
                        Debug.Assert(intEntries.Length - index - 1 > 0);
                        Array.Copy(intEntries, index + 1, newEntries, index, intEntries.Length - index - 1);
                    }
                    intEntries = newEntries;
                }
                else {
                    // this object entry is still in use - let's just clean up the deleted element
                    switch (element)
                    {
                        case 0:
                            intEntries[index].Value1 = 0;
                            break;

                        case 1:
                            intEntries[index].Value2 = 0;
                            break;

                        case 2:
                            intEntries[index].Value3 = 0;
                            break;

                        case 3:
                            intEntries[index].Value4 = 0;
                            break;

                        default:
                            Debug.Fail("Invalid element obtained from LocateIntegerEntry");
                            break;
                    }
                }
            }
        }
예제 #8
0
/*
 *      public Color RemoveColor(int key) {
 *          RemoveObject(key);
 *      }
 */
        /// <devdoc>
        ///     Removes the given key from the array
        /// </devdoc>
        public void RemoveInteger(int key)
        {
            int   index;
            short element;
            short entryKey = SplitKey(key, out element);

            if (LocateIntegerEntry(entryKey, out index))
            {
                if (((1 << element) & intEntries[index].Mask) == 0)
                {
                    // this element is not being used - return right away
                    return;
                }

                // declare that the element is no longer used
                intEntries[index].Mask &= (short)(~((short)(1 << element)));

                if (intEntries[index].Mask == 0)
                {
                    // this object entry is no longer in use - let's remove it all together
                    // not great for perf but very simple and we don't expect to remove much
                    IntegerEntry[] newEntries = new IntegerEntry[intEntries.Length - 1];
                    if (index > 0)
                    {
                        Array.Copy(intEntries, 0, newEntries, 0, index);
                    }
                    if (index < newEntries.Length)
                    {
                        Debug.Assert(intEntries.Length - index - 1 > 0);
                        Array.Copy(intEntries, index + 1, newEntries, index, intEntries.Length - index - 1);
                    }
                    intEntries = newEntries;
                }
                else
                {
                    // this object entry is still in use - let's just clean up the deleted element
                    switch (element)
                    {
                    case 0:
                        intEntries[index].Value1 = 0;
                        break;

                    case 1:
                        intEntries[index].Value2 = 0;
                        break;

                    case 2:
                        intEntries[index].Value3 = 0;
                        break;

                    case 3:
                        intEntries[index].Value4 = 0;
                        break;

                    default:
                        Debug.Fail("Invalid element obtained from LocateIntegerEntry");
                        break;
                    }
                }
            }
        }