Пример #1
0
        protected override TValue TryGetInternal(TKey key)
        {
            var val = snapshot.GetValue(new byte[] { }, (new byte[] { prefix }).Concat(key.ToArray()).ToArray())?.value;

            if (val == null || val.Length == 0)
            {
                return(null);
            }
            return(val.AsSerializable <TValue>());
        }
Пример #2
0
        public static IEnumerable <T> Find <T>(this DB db, LTISnapshot snapshot, Slice prefix, Func <Slice, Slice, T> resultSelector)
        {
            LTIKeyIterator it = snapshot.CreateKeyIterator(new byte[] { }, prefix.buffer);
            {
                while (it.MoveNext())
                {
                    byte[] key = it.Current;
                    byte[] y   = prefix.ToArray();
                    if (key.Length < y.Length)
                    {
                        break;
                    }
                    if (!key.Take(y.Length).SequenceEqual(y))
                    {
                        break;
                    }

                    byte[] value = snapshot.GetValue(new byte[] { }, key).value;

                    yield return(resultSelector(new Slice(key), new Slice(value)));
                }
            }
        }