コード例 #1
0
        public IKeyValueEnumerator <Bytes, byte[]> All(bool forward)
        {
            var iterator = db.NewIterator(columnFamilyHandle);

            if (forward)
            {
                iterator.SeekToFirst();
            }
            else
            {
                iterator.SeekToLast();
            }
            return(new RocksDbEnumerator(iterator, name, forward));
        }
コード例 #2
0
ファイル: RocksDbStorage.cs プロジェクト: ocoanet/Zebus
        private void UpdateNonAckedCounts(IGrouping <PeerId, MatcherEntry> entry)
        {
            var nonAcked = entry.Aggregate(0, (s, e) => s + (e.IsAck ? -1 : 1));
            var peerKey  = GetPeerKey(entry.Key);

            using (var iterator = _db.NewIterator(_peersColumnFamily))//, new ReadOptions().SetTotalOrderSeek(true)))
            {
                // TODO: figure out why Seek() returns true for a different key
                var alreadyExists   = iterator.Seek(peerKey).Valid() && CompareStart(iterator.Key(), peerKey, peerKey.Length);
                var currentNonAcked = alreadyExists ? BitConverter.ToInt32(iterator.Value(), 0) : 0;

                var value = currentNonAcked + nonAcked;
                _db.Put(peerKey, BitConverter.GetBytes(value), _peersColumnFamily);
            }
        }
コード例 #3
0
        public static IEnumerable <KeyValuePair <byte[], byte[]> > Search(this RocksDbSharp.RocksDb database, byte[] indexKey, bool distinct, bool isSubKey)
        {
            Dictionary <ByteArray, bool> dictionary = new Dictionary <ByteArray, bool>();

            using (var iterator = database.NewIterator())
            {
                var it = iterator.Seek(indexKey);
                while (it.Valid())
                {
                    var iterKey = it.Key();
                    if (!iterKey.ContainsSequence32(indexKey))
                    {
                        break;
                    }

                    if (isSubKey)
                    {
                        var key = it.Value();

                        if (key == null || key.Length == 0)
                        {
                            continue;
                        }

                        if (distinct)
                        {
                            var bKey = new ByteArray(key);
                            if (dictionary.ContainsKey(bKey))
                            {
                                continue;
                            }
                            dictionary[bKey] = true;
                        }

                        var value = database.Get(key);
                        if (value == null || value.Length == 0)
                        {
                            continue;
                        }

                        yield return(new KeyValuePair <byte[], byte[]>(key, value));
                    }
                    else
                    {
                        if (distinct)
                        {
                            var bKey = new ByteArray(iterKey);
                            if (dictionary.ContainsKey(bKey))
                            {
                                continue;
                            }
                            dictionary[bKey] = true;
                        }

                        var value = it.Value();
                        if (value == null || value.Length == 0)
                        {
                            continue;
                        }

                        yield return(new KeyValuePair <byte[], byte[]>(iterKey, value));
                    }

                    it = it.Next();
                }
            }
        }