Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <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();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        IEnumerator <KeyValuePair <String, String> > IEnumerable <KeyValuePair <String, String> > .GetEnumerator()
        {
            using SnapShot sn       = this.CreateSnapshot();
            using Iterator iterator = this.CreateIterator(new ReadOptions { Snapshot = sn });

            iterator.SeekToFirst();
            while (iterator.Valid())
            {
                yield return(new KeyValuePair <String, String>(iterator.StringKey(), iterator.StringValue()));

                iterator.Next();
            }
        }
Ejemplo n.º 4
0
        public string AllDocs()
        {
            string result = "";

            LevelDB.Iterator sequenceList = sequenceStore.NewIterator(ReadOptions.Default);

            while (sequenceList.Valid())
            {
                result += sequenceList.Value();
            }

            // We have to close the iterator
            sequenceList = null;

            return(result);
        }
Ejemplo n.º 5
0
 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()));
         }
     }
 }