/// <summary> /// Lookup/create a key set for a single key scheme. /// </summary> /// <param name="scheme"></param> /// <returns></returns> private DualKeySet NewKeysetFor(DualKeyScheme scheme) { IKeySet keys; if (!keySets.TryGetValue(scheme, out keys)) { keys = new DualKeySet(); keySets.Add(scheme, keys); } return (DualKeySet)keys; }
/// <summary> /// Remove a key for dual key scheme. /// </summary> /// <param name="scheme">The key scheme.</param> /// <param name="subset">The key subset (PRODUCER or CONSUMER) to remove the key from.</param> /// <param name="key">The key to remove.</param> public virtual void Remove(DualKeyScheme scheme, DualKeyScheme.Subset subset, Key key) { IKeySet keySet; if (keySets.TryGetValue(scheme, out keySet)) { ((DualKeySet)keySet).KeysFor(subset).Remove(key); if (keySet.IsEmpty) keySets.Remove(scheme); } }
/// <summary> /// Add a key for dual key scheme. /// </summary> /// <param name="scheme">The key scheme.</param> /// <param name="subset">The key subset (PRODUCER or CONSUMER) to add the key to. </param> /// <param name="key"> The key to add.</param> public virtual void Add(DualKeyScheme scheme, DualKeyScheme.Subset subset, Key key) { NewKeysetFor(scheme).KeysFor(subset).Add(key); }
/// <summary> /// Get the key set for a dual scheme. This set should not be modified. /// </summary> /// <param name="scheme">The scheme.</param> /// <returns>The key set for the scheme. Will be empty if no keys are defined for the scheme.</returns> public DualKeySet KeysetFor(DualKeyScheme scheme) { IKeySet keys; if (!keySets.TryGetValue(scheme, out keys)) return EmptyDualKeyset; else return (DualKeySet)keys; }
/// <summary> /// Get the keys for a producer or consumer. /// </summary> /// <param name="subset"></param> /// <returns></returns> public HashSet<Key> KeysFor(DualKeyScheme.Subset subset) { if (subset == DualKeyScheme.Subset.Producer) return ProducerKeys; else return ConsumerKeys; }