public IEnumerable <KeyValuePair <byte[], byte[]> > Find(string indexName, byte[] lookupValue) // Find the specified indexName and lookupValue. { KeyValueStore indexStore = GetSecondaryIndex(indexName); foreach (var pair in indexStore.EnumerateFromKey(lookupValue)) // Loop over the values { var key = pair.Key; var value = pair.Value; // construct our index key pattern (lookupvalue | key), then lookup the value of the actual object using the key that was found; if the previous condition was not met, then we must have enumerated past the end of the indexed value if (ByteArray.CompareMemCmp(key, 0, lookupValue, 0, lookupValue.Length) == 0) { if (key.Length == (value.Length + lookupValue.Length) && ByteArray.CompareMemCmp(key, lookupValue.Length, value, 0, value.Length) == 0) { if (Get(value) != null) { yield return(new KeyValuePair <byte[], byte[]> (value, Get(value))); } else { yield break; } } } } }
public IEnumerable <KeyValuePair <byte[], byte[]> > FindStartsWith(string indexName, byte[] lookupValue) { KeyValueStore indexStore = GetSecondaryIndex(indexName); foreach (var pair in indexStore.EnumerateFromKey(lookupValue)) // Loops over the values. { var key = pair.Key; var value = pair.Value; // Constructs the index key pattern (lookupvalue | key), then looks up the value of the actual object using the discovered key: If the previous condition was not met, then we must have enumerated past the end of the indexed value. if (ByteArray.CompareMemCmp(key, 0, lookupValue, 0, lookupValue.Length) == 0) { if (key.Length >= (value.Length + lookupValue.Length)) { if (Get(value) != null) { yield return(new KeyValuePair <byte[], byte[]> (value, Get(value))); } else { yield break; } } } } }
public void RemoveIndexRangeForValue(string indexName, byte[] startAt, byte[] value) { KeyValueStore indexStore = GetSecondaryIndex(indexName); var pairs = indexStore.EnumerateFromKey(startAt); foreach (var pair in pairs) { if (ByteArray.CompareMemCmp(pair.Value, value) == 0) { indexStore.Delete(pair.Key); } if (ByteArray.CompareMemCmp(startAt, 0, pair.Key, 0, startAt.Length) == 0) { continue; // Exit index removal only when the projectID in the index key changes. } break; } }