RazorDB.KeyValueStore.EnumerateFromKey C# (CSharp) Method

EnumerateFromKey() public method

public EnumerateFromKey ( byte startingKey ) : byte[]>>.IEnumerable
startingKey byte
return byte[]>>.IEnumerable
        public IEnumerable<KeyValuePair<byte[], byte[]>> EnumerateFromKey(byte[] startingKey) {

            foreach (var pair in InternalEnumerateFromKey(startingKey)) {
                if (pair.Key.SequenceNum == 0) { // only enumerate top-level keys (sequence zero)
                    byte[] result = AssembleGetResult(pair.Key, pair.Value);
                    if (result != null) {
                        yield return new KeyValuePair<byte[], byte[]>(pair.Key.KeyBytes, result);
                    }
                }
            }
        }

Usage Example

コード例 #1
0
ファイル: KeyValueStore.cs プロジェクト: lanicon/razordb
        public IEnumerable <KeyValuePair <byte[], byte[]> > Find(string indexName, byte[] lookupValue)
        {
            KeyValueStore indexStore = GetSecondaryIndex(indexName);

            // Loop over the values
            foreach (var pair in indexStore.EnumerateFromKey(lookupValue))
            {
                var key   = pair.Key;
                var value = pair.Value;
                // construct our index key pattern (lookupvalue | key)
                if (ByteArray.CompareMemCmp(key, 0, lookupValue, 0, lookupValue.Length) == 0)
                {
                    int    offset    = 0;
                    byte[] objectKey = null;
                    if (indexStore.RazorFormatVersion < 2)
                    {
                        if (ByteArray.CompareMemCmp(key, key.Length - value.Length, value, 0, value.Length) == 0)
                        {
                            objectKey = pair.Value;
                        }
                    }
                    else
                    {
                        int indexKeyLen = Helper.Decode7BitInt(pair.Value, ref offset);
                        if (lookupValue.Length == indexKeyLen)
                        {
                            // Lookup the value of the actual object using the key that was found
                            // get the object key from the index value tail
                            objectKey = ItemKeyFromIndex(pair, indexKeyLen);
                        }
                    }
                    if (objectKey != null)
                    {
                        var primaryValue = this.Get(objectKey);
                        if (primaryValue != null)
                        {
                            yield return(new KeyValuePair <byte[], byte[]>(objectKey, primaryValue));
                        }
                    }
                }
                else
                {
                    // if the above condition was not met then we must have enumerated past the end of the indexed value
                    yield break;
                }
            }
        }
All Usage Examples Of RazorDB.KeyValueStore::EnumerateFromKey