示例#1
0
        public ArrayItem Shift()
        {
            if (_data.Count == 0)
            {
                return(null);
            }

            ArrayItem first         = _data [0];
            var       old_remaining = _data.Skip(1).ToArray();

            Clear();
            foreach (var old_item in old_remaining)
            {
                ArrayKey        key   = old_item.Key;
                FinalExpression value = old_item.Value;
                if (key.IsDigitsOnly())
                {
                    key = new ArrayKey((_highest_integer_key + 1).ToString());
                }

                _data.Add(new ArrayItem(key, value));
                _keys.Add(key);
            }
            return(first);
        }
示例#2
0
        public void Set(ArrayItem item)
        {
            if (item == null)
            {
                return;
            }

            ArrayKey key = item.Key;

            if (key.Value.Length == 0)
            {
                key  = new ArrayKey((_highest_integer_key + 1).ToString());
                item = new ArrayItem(key, item.Value);
            }

            if (TryGetValue(key, out ArrayItem item_old))
            {
                _data.Remove(item_old);
            }

            _data.Add(item);
            _keys.Add(key);

            Log.Debug($"set array value: arr = {_id}, key = {item.Key}, value = {item.Value}");

            if (key.IsDigitsOnly())
            {
                long k = key.Value.ToLong();
                _highest_integer_key = k > _highest_integer_key ? k : _highest_integer_key;
            }
        }
示例#3
0
 public bool TryGetValue(ArrayKey key, out ArrayItem res)
 {
     if (_keys.Contains(key))
     {
         foreach (ArrayItem value in _data)
         {
             if (value.Key.Equals(key))
             {
                 Log.Debug($"get array value: arr = {_id}, key = {key}, value = {value}");
                 res = value;
                 return(true);
             }
         }
     }
     res = null;
     return(false);
 }