// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
usingSystem;
usingSystem.Collections;
usingSystem.Collections.Generic;
usingSystem.Collections.Immutable;
usingSystem.Diagnostics;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingMicrosoft.CodeAnalysis;
usingMicrosoft.CodeAnalysis.Text;
...
...
@@ -19,8 +16,18 @@ private class Builder
{
privateconstintCompactEdgeAllocationSize=4;
privatereadonlychar[]_allLowerCaseCharacters;
privatereadonlyTextSpan[]_characterSpans;
// Instead of producing a char[] for each string we're building a node for, we instead
// have one long char[] with all the chracters of each string concatenated. i.e.
// "foo" "bar" and "baz" becomes { f, o, o, b, a, r, b, a, z }. Then in _wordSpans
// we have the text spans for each of those words in this array. This gives us only
// two allocations instead of as many allocations as the number of strings we have.
//
// Once we are done building, we pass this to the BKTree and its nodes also state the
// span of this array that corresponds to the word they were created for. This works
// well as other dependent facilities (like EditDistance) can work on sub-arrays without
// any problems.
privatereadonlychar[]_concatenatedLowerCaseWords;
privatereadonlyTextSpan[]_wordSpans;
// Note: while building a BKTree we have to store children with parents, keyed by the
// edit distance between the two. Naive implementations might store a list or dictionary
...
...
@@ -83,18 +90,18 @@ public Builder(IEnumerable<string> values)
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.