Example #1
0
        protected void AddRemoveRandomDataTestHelper(IImmutableDictionary <double, GenericParameterHelper> map)
        {
            Contract.Requires(map != null);

            double[] inputs = GenerateDummyFillData();
            for (int i = 0; i < inputs.Length; i++)
            {
                map = this.AddTestHelper(map, inputs[i], new GenericParameterHelper());
            }

            Assert.Equal(inputs.Length, map.Count);
            for (int i = 0; i < inputs.Length; i++)
            {
                Assert.True(map.ContainsKey(inputs[i]));
            }

            for (int i = 0; i < inputs.Length; i++)
            {
                map = map.Remove(inputs[i]);
                this.VerifyAvlTreeState(map);
            }

            Assert.Equal(0, map.Count);
        }
Example #2
0
            public void SetProperties(IImmutableDictionary <string, string> properties)
            {
                Requires.NotNull(properties, nameof(properties));

                Name    = properties.ContainsKey(MetadataKeys.Name) ? properties[MetadataKeys.Name] : string.Empty;
                Version = properties.ContainsKey(MetadataKeys.Version)
                                    ? properties[MetadataKeys.Version] : string.Empty;
                var dependencyTypeString = properties.ContainsKey(MetadataKeys.Type)
                                    ? properties[MetadataKeys.Type] : string.Empty;
                DependencyType dependencyType = DependencyType.Unknown;

                if (Enum.TryParse(dependencyTypeString ?? string.Empty, /*ignoreCase */ true, out dependencyType))
                {
                    DependencyType = dependencyType;
                }

                Path = properties.ContainsKey(MetadataKeys.Path) ? properties[MetadataKeys.Path] : string.Empty;

                bool resolved = true;

                bool.TryParse(properties.ContainsKey(MetadataKeys.Resolved)
                                ? properties[MetadataKeys.Resolved] : "true", out resolved);
                Resolved = resolved;

                var dependenciesHashSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

                if (properties.ContainsKey(MetadataKeys.Dependencies) && properties[MetadataKeys.Dependencies] != null)
                {
                    var dependencyIds = properties[MetadataKeys.Dependencies].Split(new[] { ';' },
                                                                                    StringSplitOptions.RemoveEmptyEntries);

                    // store only unique dependency IDs
                    foreach (var dependencyId in dependencyIds)
                    {
                        // store full ids for dependencies to simplify search in DependenciesWorld later
                        dependenciesHashSet.Add($"{Target}/{dependencyId}");
                    }
                }

                DependenciesItemSpecs = dependenciesHashSet;
                Properties            = properties;
            }
 bool IReadOnlyDictionary <MemberInfo, MemberMetadata> .ContainsKey(MemberInfo key)
 {
     return(_metadata.ContainsKey(key));
 }
 public bool ContainsKey(K key) =>
 Immutable.ContainsKey(key) || Adaptee.ContainsKey(key);
Example #5
0
 protected void ContainsKeyTestHelper <TKey, TValue>(IImmutableDictionary <TKey, TValue> map, TKey key, TValue value)
 {
     Assert.False(map.ContainsKey(key));
     Assert.True(map.Add(key, value).ContainsKey(key));
 }
Example #6
0
 public virtual IFacet GetFacet(Type facetType)
 {
     return(facetsByClass.ContainsKey(facetType) ? facetsByClass[facetType] : null);
 }
            public State Updated(IDomainEvent e)
            {
                if (e is ShardRegionRegistered)
                {
                    var message = e as ShardRegionRegistered;
                    if (Regions.ContainsKey(message.Region))
                    {
                        throw new ArgumentException(string.Format("Region {0} is already registered", message.Region));
                    }

                    return(Copy(regions: Regions.SetItem(message.Region, ImmutableList <ShardId> .Empty)));
                }
                else if (e is ShardRegionProxyRegistered)
                {
                    var message = e as ShardRegionProxyRegistered;
                    if (RegionProxies.Contains(message.RegionProxy))
                    {
                        throw new ArgumentException(string.Format("Region proxy {0} is already registered", message.RegionProxy));
                    }

                    return(Copy(regionProxies: RegionProxies.Add(message.RegionProxy)));
                }
                else if (e is ShardRegionTerminated)
                {
                    IImmutableList <ShardId> shardRegions;
                    var message = e as ShardRegionTerminated;
                    if (!Regions.TryGetValue(message.Region, out shardRegions))
                    {
                        throw new ArgumentException(string.Format("Region {0} not registered", message.Region));
                    }

                    return(Copy(
                               regions: Regions.Remove(message.Region),
                               shards: Shards.RemoveRange(shardRegions),
                               unallocatedShards: shardRegions.Aggregate(UnallocatedShards, (set, shard) => set.Add(shard))));
                }
                else if (e is ShardRegionProxyTerminated)
                {
                    var message = e as ShardRegionProxyTerminated;
                    if (!RegionProxies.Contains(message.RegionProxy))
                    {
                        throw new ArgumentException(string.Format("Region proxy {0} not registered", message.RegionProxy));
                    }

                    return(Copy(regionProxies: RegionProxies.Remove(message.RegionProxy)));
                }
                else if (e is ShardHomeAllocated)
                {
                    IImmutableList <ShardId> shardRegions;
                    var message = e as ShardHomeAllocated;
                    if (!Regions.TryGetValue(message.Region, out shardRegions))
                    {
                        throw new ArgumentException(string.Format("Region {0} not registered", message.Region));
                    }
                    if (Shards.ContainsKey(message.Shard))
                    {
                        throw new ArgumentException(string.Format("Shard {0} is already allocated", message.Shard));
                    }

                    return(Copy(
                               shards: Shards.SetItem(message.Shard, message.Region),
                               regions: Regions.SetItem(message.Region, shardRegions.Add(message.Shard)),
                               unallocatedShards: UnallocatedShards.Remove(message.Shard)));
                }
                else if (e is ShardHomeDeallocated)
                {
                    IActorRef region;
                    IImmutableList <ShardId> shardRegions;
                    var message = e as ShardHomeDeallocated;
                    if (!Shards.TryGetValue(message.Shard, out region))
                    {
                        throw new ArgumentException(string.Format("Shard {0} not allocated", message.Shard));
                    }
                    if (!Regions.TryGetValue(region, out shardRegions))
                    {
                        throw new ArgumentException(string.Format("Region {0} for shard {1} not registered", region, message.Shard));
                    }

                    return(Copy(
                               shards: Shards.Remove(message.Shard),
                               regions: Regions.SetItem(region, shardRegions.Where(s => s != message.Shard).ToImmutableList()),
                               unallocatedShards: UnallocatedShards.Add(message.Shard)));
                }
                else
                {
                    return(this);
                }
            }
        /// <summary>
        /// Fetch messages for this consumer group's current assignment.
        /// Messages are collected together in a batch per assignment. Each batch can be used to get available messages,
        /// commit offsets and get subsequent batches on the given topic/partition. Once the topic/partition is reassigned, the batch will be disposed.
        ///
        /// Subsequent calls to this function will result in new batches for each assignment. Once all active assignments have been given,
        /// the <see cref="MessageBatch.Empty"/> result will be used as an indication of nothing being currently available.
        /// </summary>
        public async Task <IMessageBatch> FetchAsync(CancellationToken cancellationToken, int?batchSize = null)
        {
            return(await _fetchSemaphore.LockAsync(
                       async() => {
                if (_disposeCount > 0)
                {
                    throw new ObjectDisposedException($"Consumer {{GroupId:{GroupId},MemberId:{MemberId}}} is no longer valid");
                }

                var generationId = GenerationId;
                var partition = _syncSemaphore.Lock(() => _assignment?.PartitionAssignments.FirstOrDefault(p => !_batches.ContainsKey(p)), _disposeToken.Token);

                if (partition == null)
                {
                    return MessageBatch.Empty;
                }
                var currentOffset = await Router.GetOffsetsAsync(GroupId, partition.topic, partition.partition_id, cancellationToken).ConfigureAwait(false);
                var offset = currentOffset.offset + 1;
                var messages = await Router.FetchMessagesAsync(ImmutableList <Message> .Empty, partition.topic, partition.partition_id, offset, Configuration, cancellationToken, batchSize).ConfigureAwait(false);
                var batch = new MessageBatch(messages, partition, offset, Router, Configuration, AutoConsume, batchSize, GroupId, MemberId, generationId);
                _syncSemaphore.Lock(() => _batches = _batches.Add(partition, batch), cancellationToken);
                return batch;
            }, cancellationToken).ConfigureAwait(false));
        }
Example #9
0
 public bool Contains(IGremlinqOption option)
 {
     return(_dictionary.ContainsKey(option));
 }
Example #10
0
 /// <summary>
 ///   True when the attribute is known by this HtmlTag
 /// </summary>
 /// <param name="attribute">The attribute</param>
 /// <returns>True if the attribute was present in the attributes dictionary or false otherwise</returns>
 public bool HasAttribute(string attribute)
 {
     return(_attributes.ContainsKey(attribute));
 }
Example #11
0
 public bool ContainsKey(PackageIdentity key) => _dictionary.ContainsKey(key);
Example #12
0
 public static bool containsKey <K, V>(IImmutableDictionary <K, V> map, K key) =>
 map.ContainsKey(key);
 private T?GetAttributeValue <T>(string key, Func <AttributeValue, T> parse)
 {
     return(_attributes.ContainsKey(key) ? parse(_attributes[key]) : default);
Example #14
0
 public Task <bool> ContainsKeyAsync(TKey key)
 {
     return(Task.FromResult(Cache.ContainsKey(key)));
 }
Example #15
0
 public bool ContainsKey(K key)
 {
     return(_dictionary.ContainsKey(key));
 }
 public bool IsClosed(Vector location)
 {
     return(_closedList.ContainsKey(location));
 }
Example #17
0
 public bool ContainsKey(string key)
 {
     return(_data.ContainsKey(key));
 }
Example #18
0
 public bool Contains(IGremlinqOption option)
 {
     return((_dictionary?.ContainsKey(option)).GetValueOrDefault());
 }
Example #19
0
 /// <summary>
 /// Checks if provided <paramref name="key"/> can be found inside current <see cref="ORDictionary{TKey,TValue}"/>
 /// </summary>
 public bool ContainsKey(TKey key) => ValueMap.ContainsKey(key);
Example #20
0
        public static IImmutableList <Seq> GetSequences(
            this Board board,
            IImmutableDictionary <Coord, Team> chips,
            IImmutableSet <Coord> coordsInSequences,
            Coord coord,
            Team team)
        {
            var row = coord.Row;
            var col = coord.Column;

            bool IsSequence(IEnumerable <Coord> cs)
            {
                int shared = 0;

                foreach (var c in cs)
                {
                    var isCorner =
                        (c.Row >= 0 && c.Row < board.Length) &&
                        (c.Column >= 0 && c.Column < board[c.Row].Length) &&
                        board[c.Row][c.Column] == null;

                    var teamOwnsCoord = chips.TryGetValue(c, out var t) && team == t;

                    if (isCorner || teamOwnsCoord)
                    {
                        var isPartOfAnotherSequence =
                            coordsInSequences.Contains(c) &&
                            chips.ContainsKey(c) && // 'chips' won't contain c is it's a corner.
                            chips[c] == team;

                        if (isPartOfAnotherSequence)
                        {
                            shared++;
                        }
                    }
                    else
                    {
                        // This is not a valid sequence. Exit early.
                        return(false);
                    }
                }

                // This is a valid sequence if all coords of 'cs' are owned by 'team' and only 1
                // other coord is part of a sequence.
                return(shared < 2);
            }

            IEnumerable <Seq> TrySequence(IEnumerable <Coord> cs)
            {
                int i = 0;

                while (true)
                {
                    var seq = cs
                              .Skip(i++)
                              .Take(Seq.DefaultLength)
                              .ToImmutableList();

                    if (seq.Count < Seq.DefaultLength)
                    {
                        // Not enough coordinates to form a sequence, stop.
                        yield break;
                    }

                    if (IsSequence(seq))
                    {
                        yield return(new Seq(team, seq));

                        // One coordinate can be shared so we jump forward to that one in the next
                        // iteration. Since 'i' has already been incremented once, we add only
                        // N - 2, not N - 1.
                        i += Seq.DefaultLength - 2;
                    }
                }
            }

            var range = Enumerable.Range(-5, 11);

            return(new[]
            {
                range.Select(d => new Coord(col, row + d)),     // Vertical
                range.Select(d => new Coord(col + d, row)),     // Horizontal
                range.Select(d => new Coord(col + d, row + d)), // (0, 0) -> (9, 9) diagonal
                range.Select(d => new Coord(col + d, row - d)), // (0, 9) -> (9, 0) diagonal
            }.AsParallel()
                   .SelectMany(TrySequence)
                   .ToImmutableList());
        }
Example #21
0
 public bool ContainsKey(Address key)
 {
     return(_impl.ContainsKey(key));
 }
Example #22
0
        public static Seq?GetSequence(
            this Board board,
            IImmutableDictionary <Coord, Team> chips,
            IImmutableSet <Coord> coordsInSequences,
            Coord coord,
            Team team)
        {
            var row = coord.Row;
            var col = coord.Column;

            bool IsSequence(IEnumerable <Coord> cs)
            {
                int shared = 0;

                foreach (var c in cs)
                {
                    var isCorner =
                        (c.Row >= 0 && c.Row < board.Length) &&
                        (c.Column >= 0 && c.Column < board[c.Row].Length) &&
                        board[c.Row][c.Column] == null;

                    var teamOwnsCoord = chips.TryGetValue(c, out var t) && team == t;

                    if (isCorner || teamOwnsCoord)
                    {
                        var isPartOfAnotherSequence =
                            coordsInSequences.Contains(c) &&
                            chips.ContainsKey(c) && // 'chips' won't contain c is it's a corner.
                            chips[c] == team;

                        if (isPartOfAnotherSequence)
                        {
                            shared++;
                        }
                    }
                    else
                    {
                        // This is not a valid sequence. Exit early.
                        return(false);
                    }
                }

                // This is a valid sequence if all coords of 'cs' are owned by 'team' and only 1
                // other coord is part of a sequence.
                return(shared < 2);
            }

            bool TrySequence(IEnumerable <Coord> cs, out IImmutableList <Coord> seq)
            {
                int i = 0;

                while (true)
                {
                    seq = cs
                          .Skip(i++)
                          .Take(Seq.DefaultLength)
                          .ToImmutableList();

                    if (seq.Count < Seq.DefaultLength)
                    {
                        break;
                    }

                    if (IsSequence(seq))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            var range      = Enumerable.Range(-5, 11);
            var vertical   = range.Select(d => new Coord(col, row + d));
            var horizontal = range.Select(d => new Coord(col + d, row));
            var diagonal1  = range.Select(d => new Coord(col + d, row + d));
            var diagonal2  = range.Select(d => new Coord(col + d, row - d));

#pragma warning disable IDE0018
            IImmutableList <Coord> coords;

            if (TrySequence(vertical, out coords) ||
                TrySequence(horizontal, out coords) ||
                TrySequence(diagonal1, out coords) ||
                TrySequence(diagonal2, out coords))
            {
                return(new Seq(team, coords));
            }
#pragma warning restore IDE0018

            return(null);
        }
Example #23
0
        public static void CollectRoslynReferences(
            ref IImmutableDictionary <AssemblyShortName, AssemblyDetails> usedRoslynAssemblies,
            IImmutableDictionary <AssemblyShortName, string> roslynAssemblyPaths,
            ref IImmutableDictionary <AssemblyShortName, AssemblyDetails> mainAssemblies,
            IImmutableDictionary <AssemblyShortName, IImmutableSet <PackageInfo> > roslynPackageMap,
            out IImmutableDictionary <AssemblyShortName, AssemblyDetails> othersReferencedByRoslyn
            )
        {
            var othersReferencedByRoslynBuilder = ImmutableSortedDictionary.CreateBuilder <AssemblyShortName, AssemblyDetails>();

            FluentConsole.White.Line("Analyzing Roslyn references…");
            var seen  = new HashSet <AssemblyShortName>();
            var queue = new Queue <AssemblyDetails>(usedRoslynAssemblies.Values);

            while (queue.Count > 0)
            {
                var assembly = queue.Dequeue();
                FluentConsole.Gray.Line($"  {assembly.Definition.Name.Name}");
                seen.Add(assembly.Definition.Name.Name);
                foreach (var reference in assembly.Definition.MainModule.AssemblyReferences)
                {
                    if (!seen.Add(reference.Name))
                    {
                        continue;
                    }

                    FluentConsole.Gray.Line($"    {reference.FullName}");

                    var mainAssembly = mainAssemblies.GetValueOrDefault(reference.Name);
                    var mainVersion  = mainAssembly?.Definition.Name.Version;
                    if (mainAssembly != null)
                    {
                        mainAssemblies = mainAssemblies.Remove(reference.Name);
                    }

                    if (usedRoslynAssemblies.ContainsKey(reference.Name))
                    {
                        FluentConsole.Gray.Line("      [roslyn assembly, already used]");
                        continue;
                    }

                    var roslynAssemblyPath = roslynAssemblyPaths.GetValueOrDefault(reference.Name);
                    if (roslynAssemblyPath != null)
                    {
                        FluentConsole.Gray.Line("      [roslyn assembly, queued]");
                        var roslynAssembly = AssemblyDetails.ReadFrom(roslynAssemblyPath, readSymbolsIfExist: true);
                        usedRoslynAssemblies = usedRoslynAssemblies.Add(roslynAssembly.Definition.Name.Name, roslynAssembly);
                        queue.Enqueue(roslynAssembly);
                        continue;
                    }

                    if (InGlobalAssemblyCache(reference))
                    {
                        FluentConsole.Gray.Line("      [gac]");
                        continue;
                    }

                    var referencedAssembly = GetAssemblyDetailsFromNuGetCache(reference.Name, roslynPackageMap);
                    if (referencedAssembly == null)
                    {
                        FluentConsole.Gray.Line("      [system?]");
                        continue;
                    }

                    if (mainVersion > reference.Version)
                    {
                        FluentConsole.Gray.Line($"      [main assembly is newer, queued using version {mainVersion} instead of {reference.Version}]");
                        othersReferencedByRoslynBuilder.Add(reference.Name, mainAssembly);
                        queue.Enqueue(mainAssembly);
                        continue;
                    }
                    othersReferencedByRoslynBuilder.Add(reference.Name, referencedAssembly);
                    queue.Enqueue(referencedAssembly);
                }
            }
            othersReferencedByRoslyn = othersReferencedByRoslynBuilder.ToImmutable();
        }
            /// <summary>
            /// TBD
            /// </summary>
            /// <param name="e">TBD</param>
            /// <exception cref="ArgumentException">TBD</exception>
            /// <returns>TBD</returns>
            public State Updated(IDomainEvent e)
            {
                switch (e)
                {
                case ShardRegionRegistered message:
                    if (Regions.ContainsKey(message.Region))
                    {
                        throw new ArgumentException($"Region {message.Region} is already registered", nameof(e));
                    }

                    return(Copy(regions: Regions.SetItem(message.Region, ImmutableList <ShardId> .Empty)));

                case ShardRegionProxyRegistered message:
                    if (RegionProxies.Contains(message.RegionProxy))
                    {
                        throw new ArgumentException($"Region proxy {message.RegionProxy} is already registered", nameof(e));
                    }

                    return(Copy(regionProxies: RegionProxies.Add(message.RegionProxy)));

                case ShardRegionTerminated message:
                {
                    if (!Regions.TryGetValue(message.Region, out var shardRegions))
                    {
                        throw new ArgumentException($"Terminated region {message.Region} not registered", nameof(e));
                    }

                    var newUnallocatedShards = RememberEntities ? UnallocatedShards.Union(shardRegions) : UnallocatedShards;
                    return(Copy(
                               regions: Regions.Remove(message.Region),
                               shards: Shards.RemoveRange(shardRegions),
                               unallocatedShards: newUnallocatedShards));
                }

                case ShardRegionProxyTerminated message:
                    if (!RegionProxies.Contains(message.RegionProxy))
                    {
                        throw new ArgumentException($"Terminated region proxy {message.RegionProxy} not registered", nameof(e));
                    }

                    return(Copy(regionProxies: RegionProxies.Remove(message.RegionProxy)));

                case ShardHomeAllocated message:
                {
                    if (!Regions.TryGetValue(message.Region, out var shardRegions))
                    {
                        throw new ArgumentException($"Region {message.Region} not registered", nameof(e));
                    }
                    if (Shards.ContainsKey(message.Shard))
                    {
                        throw new ArgumentException($"Shard {message.Shard} is already allocated", nameof(e));
                    }

                    var newUnallocatedShards = RememberEntities ? UnallocatedShards.Remove(message.Shard) : UnallocatedShards;
                    return(Copy(
                               shards: Shards.SetItem(message.Shard, message.Region),
                               regions: Regions.SetItem(message.Region, shardRegions.Add(message.Shard)),
                               unallocatedShards: newUnallocatedShards));
                }

                case ShardHomeDeallocated message:
                {
                    if (!Shards.TryGetValue(message.Shard, out var region))
                    {
                        throw new ArgumentException($"Shard {message.Shard} not allocated", nameof(e));
                    }
                    if (!Regions.TryGetValue(region, out var shardRegions))
                    {
                        throw new ArgumentException($"Region {region} for shard {message.Shard} not registered", nameof(e));
                    }

                    var newUnallocatedShards = RememberEntities ? UnallocatedShards.Add(message.Shard) : UnallocatedShards;
                    return(Copy(
                               shards: Shards.Remove(message.Shard),
                               regions: Regions.SetItem(region, shardRegions.Where(s => s != message.Shard).ToImmutableList()),
                               unallocatedShards: newUnallocatedShards));
                }
                }

                return(this);
            }
Example #25
0
        private void DeliverMessage(object message, IActorRef sender)
        {
            var restart = message as RestartShard;

            if (restart != null)
            {
                var       shardId = restart.ShardId;
                IActorRef regionRef;
                if (RegionByShard.TryGetValue(shardId, out regionRef))
                {
                    if (Self.Equals(regionRef))
                    {
                        GetShard(shardId);
                    }
                }
                else
                {
                    IImmutableList <KeyValuePair <Msg, IActorRef> > buffer;
                    if (!ShardBuffers.TryGetValue(shardId, out buffer))
                    {
                        buffer = ImmutableList <KeyValuePair <object, IActorRef> > .Empty;
                        Log.Debug("Request shard [{0}] home", shardId);
                        if (_coordinator != null)
                        {
                            _coordinator.Tell(new PersistentShardCoordinator.GetShardHome(shardId));
                        }
                    }

                    Log.Debug("Buffer message for shard [{0}]. Total [{1}] buffered messages.", shardId, buffer.Count + 1);
                    ShardBuffers = ShardBuffers.SetItem(shardId, buffer.Add(new KeyValuePair <object, IActorRef>(message, sender)));
                }
            }
            else
            {
                IActorRef region;
                var       shardId = ShardResolver(message);
                if (RegionByShard.TryGetValue(shardId, out region))
                {
                    if (region.Equals(Self))
                    {
                        var sref = GetShard(shardId);
                        if (Equals(sref, ActorRefs.Nobody))
                        {
                            BufferMessage(shardId, message, sender);
                        }
                        else
                        {
                            IImmutableList <KeyValuePair <Msg, IActorRef> > buffer;
                            if (ShardBuffers.TryGetValue(shardId, out buffer))
                            {
                                // Since now messages to a shard is buffered then those messages must be in right order
                                BufferMessage(shardId, message, sender);
                                DeliverBufferedMessage(shardId, sref);
                            }
                            else
                            {
                                sref.Tell(message, sender);
                            }
                        }
                    }
                    else
                    {
                        Log.Debug("Forwarding request for shard [{0}] to [{1}]", shardId, region);
                        region.Tell(message, sender);
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(shardId))
                    {
                        Log.Warning("Shard must not be empty, dropping message [{0}]", message.GetType());
                        Context.System.DeadLetters.Tell(message);
                    }
                    else
                    {
                        if (!ShardBuffers.ContainsKey(shardId))
                        {
                            Log.Debug("Request shard [{0}] home", shardId);
                            if (_coordinator != null)
                            {
                                _coordinator.Tell(new PersistentShardCoordinator.GetShardHome(shardId));
                            }
                        }

                        BufferMessage(shardId, message, sender);
                    }
                }
            }
        }
Example #26
0
 public bool IsCovered(Point point)
 {
     return(_covers.ContainsKey(point));
 }
Example #27
0
 /// <summary>
 /// Returns true if there is a value assigned to the specified variable.
 /// </summary>
 ///
 /// <param name="variable">the variable</param>
 ///
 /// <returns>true if the variable has been assigned a value</returns>
 public bool HasValue(Variable <TVar, TVal> variable)
 {
     return(assignments.ContainsKey(variable));
 }
        private static IDictionary<ISymbol, IDictionary<SyntaxNode, ISymbol>> GetReferencesByEnclosingSymbol(
            SyntaxNode node,
            IImmutableDictionary<ISymbol, PrivateField> privateFields,
            SemanticModel semanticModel)
        {
            var privateFieldNames = privateFields.Keys.Select(s => s.Name).ToImmutableHashSet();

            var potentialReferences = node.DescendantNodes()
                .Where(n => n.IsKind(SyntaxKind.IdentifierName))
                .Cast<IdentifierNameSyntax>()
                .Where(id => privateFieldNames.Contains(id.Identifier.ValueText));

            var builder = new Dictionary<ISymbol, IDictionary<SyntaxNode, ISymbol>>();
            foreach (var potentialReference in potentialReferences)
            {
                var referencedSymbol = semanticModel.GetSymbolInfo(potentialReference).Symbol;
                if (referencedSymbol == null || !privateFields.ContainsKey(referencedSymbol))
                {
                    continue;
                }

                SyntaxNode referenceSyntax = potentialReference;
                while (referenceSyntax.Parent != null && referencedSymbol.Equals(semanticModel.GetSymbolInfo(referenceSyntax.Parent).Symbol))
                {
                    referenceSyntax = referenceSyntax.Parent;
                }

                if (referenceSyntax.Parent != null && referenceSyntax.Parent.IsKind(SyntaxKind.ConditionalAccessExpression))
                {
                    referenceSyntax = referenceSyntax.Parent;
                }


                var enclosingSymbol = semanticModel.GetEnclosingSymbol(potentialReference.SpanStart);
                if (!builder.ContainsKey(enclosingSymbol))
                {
                    builder.Add(enclosingSymbol, new Dictionary<SyntaxNode, ISymbol>());
                }

                builder[enclosingSymbol].Add(referenceSyntax, referencedSymbol);
            }

            return builder;
        }