public Dictionary <string, string> Find(ReadOptions options, Slice prefix) { var result = new Dictionary <string, string>(); using (Iterator it = NewIterator(options)) { for (it.Seek(prefix); it.Valid(); it.Next()) { Slice key = it.Key(); byte[] x = key.ToArray(); byte[] y = prefix.ToArray(); if (x.Length < y.Length) { break; } if (!x.Take(y.Length).SequenceEqual(y)) { break; } var v = it.Value(); var c = ((Slice)(v)).ToString(); result.Add(((Slice)key).ToString(), ((Slice)v).ToString()); } } return(result); }
/// <summary> /// /// </summary> /// <returns></returns> public IEnumerator <KeyValuePair <Byte[], Byte[]> > GetEnumerator() { using SnapShot sn = this.CreateSnapshot(); using Iterator iterator = this.CreateIterator(new ReadOptions { Snapshot = sn }); iterator.SeekToFirst(); while (iterator.Valid()) { yield return(new KeyValuePair <Byte[], Byte[]>(iterator.Key(), iterator.Value())); iterator.Next(); } }
public static IEnumerable <T> Find <T>(this DB db, ReadOptions options, Slice prefix, Func <Slice, Slice, T> resultSelector) { using (Iterator it = db.NewIterator(options)) { for (it.Seek(prefix); it.Valid(); it.Next()) { Slice key = it.Key(); byte[] x = key.ToArray(); byte[] y = prefix.ToArray(); if (x.Length < y.Length) { break; } if (!x.Take(y.Length).SequenceEqual(y)) { break; } yield return(resultSelector(key, it.Value())); } } }