Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Table"/> class.
 /// </summary>
 /// <param name="owner">The owner script.</param>
 public Table(Script owner)
 {
     _values          = new LinkedList <TablePair>();
     _stringMap       = new LinkedListIndex <string, TablePair>(_values);
     _arrayMap        = new LinkedListIndex <int, TablePair>(_values);
     _valueMap        = new LinkedListIndex <DynValue, TablePair>(_values);
     this.OwnerScript = owner;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Table"/> class.
 /// </summary>
 /// <param name="owner">The owner script.</param>
 public Table(Script owner)
 {
     m_Values    = new LinkedList <TablePair>();
     m_StringMap = new LinkedListIndex <string, TablePair>(m_Values);
     m_ArrayMap  = new LinkedListIndex <int, TablePair>(m_Values);
     m_ValueMap  = new LinkedListIndex <DynValue, TablePair>(m_Values);
     m_Owner     = owner;
 }
Пример #3
0
        private void PerformTableSet <T>(LinkedListIndex <T, TablePair> listIndex, T key, DynValue keyDynValue, DynValue value, bool isNumber, int appendKey)
        {
            if (!_isAlive)
            {
                throw new InvalidOperationException(string.Format("Attempting to PerformTableSet on dead Table"));
            }
            TablePair prev = listIndex.Set(key, new TablePair(keyDynValue, value));

            // If this is an insert, we can invalidate all iterators and collect dead keys
            if (m_ContainsNilEntries && value.IsNotNil() && (prev.Value.IsNil()))
            {
                CollectDeadKeys();
            }
            // If this value is nil (and we didn't collect), set that there are nil entries, and invalidate array len cache
            else if (value.IsNil())
            {
                m_ContainsNilEntries = true;

                if (isNumber)
                {
                    m_CachedLength = -1;
                }
            }
            else if (isNumber)
            {
                // If this is an array insert, we might have to invalidate the array length
                if (prev.Value.IsNilOrNan())
                {
                    // If this is an array append, let's check the next element before blindly invalidating
                    if (appendKey >= 0)
                    {
                        if (m_ArrayMap == null)
                        {
                            m_CachedLength += 1;
                        }
                        else
                        {
                            LinkedListNode <TablePair> next = m_ArrayMap.Find(appendKey + 1);
                            if (next == null || next.Value.Value.IsNil())
                            {
                                m_CachedLength += 1;
                            }
                            else
                            {
                                m_CachedLength = -1;
                            }
                        }
                    }
                    else
                    {
                        m_CachedLength = -1;
                    }
                }
            }
        }
        private bool PerformTableRemove <T>(LinkedListIndex <T, TablePair> listIndex, T key, bool isNumber)
        {
            var removed = listIndex.Remove(key);

            if (removed && isNumber)
            {
                m_CachedLength = -1;
            }

            return(removed);
        }
Пример #5
0
        /// <summary>
        /// Sets the value associated to the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public void Set(int key, DynValue value)
        {
            if (!_isAlive)
            {
                throw new InvalidOperationException(string.Format("Attempting to Set on dead Table"));
            }
            this.CheckScriptOwnership(value);

            if (m_ArrayMap == null)
            {
                m_ArrayMap = new LinkedListIndex <int, TablePair>(ValuesList);
            }
            PerformTableSet(m_ArrayMap, key, DynValue.NewNumber(key), value, true, -1);
        }
Пример #6
0
        private bool PerformTableRemove <T>(LinkedListIndex <T, TablePair> listIndex, T key, bool isNumber)
        {
            if (!_isAlive)
            {
                throw new InvalidOperationException(string.Format("Attempting to PerformTableRemove on dead Table"));
            }
            var removed = listIndex.Remove(key);

            if (removed && isNumber)
            {
                m_CachedLength = -1;
            }

            return(removed);
        }
Пример #7
0
        static SessionMonitor()
        {
            linkedListIndex = new LinkedListIndex <SessionData>("LinkedList");
            idIndex         = new UniqueIndex <String, SessionData>(
                "Id",
                delegate(SessionData sessionData, out String sessionId)
            {
                sessionId = sessionData.SessionId;
                return(true);
            },
                false);

            sessions = new IndexableCollection <SessionData>(linkedListIndex);
            sessions.Indexes.Add(idIndex);
        }
Пример #8
0
        /// <summary>
        /// Sets the value associated to the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public void Set(DynValue key, DynValue value)
        {
            if (!_isAlive)
            {
                throw new InvalidOperationException(string.Format("Attempting to Set on dead Table"));
            }
            if (key.IsNilOrNan())
            {
                if (key.IsNil())
                {
                    throw ScriptRuntimeException.TableIndexIsNil();
                }
                else
                {
                    throw ScriptRuntimeException.TableIndexIsNaN();
                }
            }

            if (key.Type == DataType.String)
            {
                Set(key.String, value);
                return;
            }

            if (key.Type == DataType.Number)
            {
                int idx = GetIntegralKey(key.Number);

                if (idx > 0)
                {
                    Set(idx, value);
                    return;
                }
            }

            this.CheckScriptOwnership(key);
            this.CheckScriptOwnership(value);

            if (m_ValueMap == null)
            {
                m_ValueMap = new LinkedListIndex <DynValue, TablePair>(ValuesList);
            }
            PerformTableSet(m_ValueMap, key, key, value, false, -1);
        }
Пример #9
0
        /// <summary>
        /// Sets the value associated to the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public void Set(string key, DynValue value)
        {
            if (!_isAlive)
            {
                throw new InvalidOperationException(string.Format("Attempting to Set on dead Table"));
            }
            if (key == null)
            {
                throw ScriptRuntimeException.TableIndexIsNil();
            }

            this.CheckScriptOwnership(value);

            if (m_StringMap == null)
            {
                m_StringMap = new LinkedListIndex <string, TablePair>(ValuesList);
            }
            PerformTableSet(m_StringMap, key, DynValue.NewString(key), value, false, -1);
        }
Пример #10
0
        private void PerformTableSet <T>(LinkedListIndex <T, TablePair> listIndex, T key, DynValue keyDynValue, DynValue value, bool isNumber)
        {
            TablePair prev = listIndex.Set(key, new TablePair(keyDynValue, value));

            if (prev.Value == null || prev.Value.IsNil())
            {
                CollectDeadKeys();

                if (isNumber)
                {
                    m_CachedLength = -1;
                }
            }

            if (isNumber && value.IsNil())
            {
                m_CachedLength = -1;
            }
        }