<commit_before>﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.PooledObjects;

namespace Microsoft.CodeAnalysis.FindSymbols
{
    internal partial class FindReferencesSearchEngine
    {
        /// <summary>
        /// Symbol set used when <see cref="FindReferencesSearchOptions.UnidirectionalHierarchyCascade"/> is <see
        /// langword="true"/>.
        /// </summary>
        private sealed class UnidirectionalSymbolSet : SymbolSet
        {
            /// <summary>
            /// When we're doing a unidirectional find-references, the initial set of up-symbols can never change.
            /// That's because we have computed the up set entirely up front, and no down symbols can produce new
            /// up-symbols (as going down then up would not be unidirectional).
            /// </summary>
            private readonly ImmutableHashSet<ISymbol> _upSymbols;
            private readonly HashSet<ISymbol> _initialAndDownSymbols;

            public UnidirectionalSymbolSet(FindReferencesSearchEngine engine, HashSet<ISymbol> upSymbols, HashSet<ISymbol> initialSymbols)
                : base(engine)
            {
                _upSymbols = upSymbols.ToImmutableHashSet();
                _initialAndDownSymbols = initialSymbols;
            }

            public override ImmutableArray<ISymbol> GetAllSymbols()
            {
                using var _ = ArrayBuilder<ISymbol>.GetInstance(out var result);
                result.AddRange(_upSymbols);
                result.AddRange(_initialAndDownSymbols);
                result.RemoveDuplicates();
                return result.ToImmutable();
            }

            public override async Task InheritanceCascadeAsync(Project project, CancellationToken cancellationToken)
            {
                // Start searching using the existing set of symbols found at the start (or anything found below that).
                var workQueue = new Stack<ISymbol>();
                PushAll(workQueue, _initialAndDownSymbols);

                var projects = ImmutableHashSet.Create(project);

                while (workQueue.Count > 0)
                {
                    var current = workQueue.Pop();

                    // Keep adding symbols downwards in this project as long as we keep finding new symbols.
                    await AddDownSymbolsAsync(current, _initialAndDownSymbols, workQueue, projects, cancellationToken).ConfigureAwait(false);
                }
            }
        }
    }
}
<commit_msg>All passing<commit_after>﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.PooledObjects;

namespace Microsoft.CodeAnalysis.FindSymbols
{
    internal partial class FindReferencesSearchEngine
    {
        /// <summary>
        /// Symbol set used when <see cref="FindReferencesSearchOptions.UnidirectionalHierarchyCascade"/> is <see
        /// langword="true"/>.
        /// </summary>
        private sealed class UnidirectionalSymbolSet : SymbolSet
        {
            private readonly HashSet<ISymbol> _initialAndDownSymbols;

            /// <summary>
            /// When we're doing a unidirectional find-references, the initial set of up-symbols can never change.
            /// That's because we have computed the up set entirely up front, and no down symbols can produce new
            /// up-symbols (as going down then up would not be unidirectional).
            /// </summary>
            private readonly ImmutableHashSet<ISymbol> _upSymbols;

            public UnidirectionalSymbolSet(FindReferencesSearchEngine engine, HashSet<ISymbol> initialSymbols, HashSet<ISymbol> upSymbols)
                : base(engine)
            {
                _initialAndDownSymbols = initialSymbols;
                _upSymbols = upSymbols.ToImmutableHashSet();
            }

            public override ImmutableArray<ISymbol> GetAllSymbols()
            {
                using var _ = ArrayBuilder<ISymbol>.GetInstance(out var result);
                result.AddRange(_upSymbols);
                result.AddRange(_initialAndDownSymbols);
                result.RemoveDuplicates();
                return result.ToImmutable();
            }

            public override async Task InheritanceCascadeAsync(Project project, CancellationToken cancellationToken)
            {
                // Start searching using the existing set of symbols found at the start (or anything found below that).
                var workQueue = new Stack<ISymbol>();
                PushAll(workQueue, _initialAndDownSymbols);

                var projects = ImmutableHashSet.Create(project);

                while (workQueue.Count > 0)
                {
                    var current = workQueue.Pop();

                    // Keep adding symbols downwards in this project as long as we keep finding new symbols.
                    await AddDownSymbolsAsync(current, _initialAndDownSymbols, workQueue, projects, cancellationToken).ConfigureAwait(false);
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.07274023890176502, 'fraction_numerical': 0.00035656979853806385, 'mean_word_length': 2.16056338028169, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1122434', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1295, 'n_words': 411}