예제 #1
0
 private static KeysList LoadSpace(string space)
 {
     return(new KeysList(Sizes[space],
                         ValuesStorage.GetStringList(space)
                         .Select(y => y.Split(new[] { '\n' }, 2))
                         .Select(y => new KeyValue(Storage.Decode(y[0]), y[1]))));
 }
예제 #2
0
            private void SaveInner()
            {
                if (!_isDirty)
                {
                    return;
                }
                _isDirty = false;

                var l         = _values;
                var delimiter = Storage.Encode("\n");
                var sb        = new StringBuilder(l.Length * 4);

                for (var i = 0; i < l.Length; i++)
                {
                    var x = l[i];
                    if (x.Key == null)
                    {
                        break;
                    }

                    if (i > 0)
                    {
                        sb.Append('\n');
                    }
                    sb.Append(Storage.Encode(Storage.Encode(x.Key)));
                    sb.Append(delimiter);
                    sb.Append(Storage.Encode(x.Value));
                }

                ValuesStorage.Set(_key, sb.ToString());
            }
예제 #3
0
        private void Save(string space)
        {
            KeysList l;

            if (!_storage.TryGetValue(space, out l))
            {
                throw new Exception("Unsupported space: " + space);
            }

            ValuesStorage.Set(space, l.Select(x => Storage.Encode(x.Item1) + "\n" + x.Item2));
        }
예제 #4
0
            public Space(string key, int size)
            {
                var s = Stopwatch.StartNew();

                _key    = key;
                _values = new KeyValue[size];
                var i = 0;

                foreach (var line in ValuesStorage.GetStringList(key))
                {
                    var split = line.Split(new[] { '\n' }, 2);
                    if (split.Length < 2 || string.IsNullOrWhiteSpace(split[0]))
                    {
                        continue;
                    }
                    _values[i++] = new KeyValue(Storage.Decode(split[0]), split[1]);
                }

                if (s.Elapsed.TotalMilliseconds > 2)
                {
                    Logging.Debug($"{_key}, loaded {i} values : {s.Elapsed.TotalMilliseconds:F2} ms");
                }
            }