4 instantiations of BDD
System.Text.RegularExpressions (4)
System\Text\RegularExpressions\Symbolic\BDD.cs (3)
37
public static readonly BDD True = new
BDD
(TrueOrdinal, null, null);
42
public static readonly BDD False = new
BDD
(FalseOrdinal, null, null);
384
nodes[i] = new
BDD
(ord, nodes[oneId], nodes[zeroId]);
System\Text\RegularExpressions\Symbolic\CharSetSolver.cs (1)
391
return bdd ??= new
BDD
(ordinal, one, zero);
227 references to BDD
System.Text.RegularExpressions (227)
System\Text\RegularExpressions\Symbolic\BDD.cs (31)
22
internal sealed class BDD : IComparable<
BDD
>, IEquatable<
BDD
>
37
public static readonly
BDD
True = new BDD(TrueOrdinal, null, null);
42
public static readonly
BDD
False = new BDD(FalseOrdinal, null, null);
48
public readonly
BDD
? One;
54
public readonly
BDD
? Zero;
66
internal BDD(int ordinal,
BDD
? one,
BDD
? zero)
111
BDD
set = this;
144
public override bool Equals(object? obj) => Equals(obj as
BDD
);
147
public bool Equals(
BDD
? bdd) =>
172
BDD
[] nodes = TopologicalSort();
202
var idmap = new Dictionary<
BDD
, long>
211
BDD
node = nodes[i];
239
private
BDD
[] TopologicalSort()
248
var nonterminals = new List<
BDD
>[Ordinal + 1];
249
var sorted = new List<
BDD
>();
250
var toVisit = new Stack<
BDD
>();
251
var visited = new HashSet<
BDD
>();
257
BDD
node = toVisit.Pop();
271
(nonterminals[node.Ordinal] ??= new List<
BDD
>()).Add(node);
342
public static
BDD
Deserialize(ReadOnlySpan<byte> bytes)
365
BDD
[] nodes = new
BDD
[n];
425
BDD
bdd = this;
443
public bool IsEssentiallyBoolean([NotNullWhen(true)] out
BDD
? terminalActingAsTrue)
457
var toVisit = new Stack<
BDD
>();
458
var visited = new HashSet<
BDD
>();
463
BDD
? leaf = null;
467
BDD
node = toVisit.Pop();
514
public int CompareTo(
BDD
? other)
System\Text\RegularExpressions\Symbolic\BDDRangeConverter.cs (4)
17
private readonly Dictionary<
BDD
, (uint, uint)[]> _rangeCache = new Dictionary<
BDD
, (uint, uint)[]>();
25
public static (uint, uint)[] ToRanges(
BDD
set)
97
private (uint, uint)[] ToRangesFromOrdinal(
BDD
set)
System\Text\RegularExpressions\Symbolic\BitVectorSolver.cs (7)
9
private readonly
BDD
[] _minterms;
13
public BitVectorSolver(
BDD
[] minterms)
49
public BitVector ConvertFromBDD(
BDD
set, CharSetSolver solver)
51
BDD
[] partition = _minterms;
71
public
BDD
ConvertToBDD(BitVector set, CharSetSolver solver)
73
BDD
[] partition = _minterms;
76
BDD
result = solver.Empty;
System\Text\RegularExpressions\Symbolic\CharSetSolver.cs (98)
13
/// Provides functionality to build character sets represented as <see cref="
BDD
"/>s
16
internal sealed class CharSetSolver : ISolver<
BDD
>
20
private static readonly
BDD
?[] s_asciiCache = new
BDD
[128];
23
private static
BDD
? s_nonAscii;
33
private readonly Dictionary<(int ordinal,
BDD
? one,
BDD
? zero),
BDD
> _bddCache = new();
39
private readonly Dictionary<(int op,
BDD
a,
BDD
? b),
BDD
> _operationCache = new(); // op is BooleanOperation; using int to reuse generic instantiation with _bddCache
42
public
BDD
NonAscii =>
48
public
BDD
CreateBDDFromChar(char c)
50
BDD
?[] ascii = s_asciiCache;
63
BDD
CreateBdd(ushort c)
65
BDD
bdd =
BDD
.True;
69
GetOrCreateBDD(k, bdd,
BDD
.False) :
70
GetOrCreateBDD(k,
BDD
.False, bdd);
77
/// <summary>Identity function for <paramref name="set"/>, since <paramref name="set"/> is already a <see cref="
BDD
"/>.</summary>
78
public
BDD
ConvertFromBDD(
BDD
set, CharSetSolver _) => set;
81
BDD
[]? ISolver<
BDD
>.GetMinterms() => null;
84
/// <summary>Identity function for <paramref name="set"/>, since <paramref name="set"/> is already a <see cref="
BDD
"/>.</summary>
85
public
BDD
ConvertToBDD(
BDD
set, CharSetSolver _) => set;
88
internal
BDD
CreateBDDFromRanges(List<(char Lower, char Upper)> ranges)
90
BDD
bdd = Empty;
100
string ISolver<
BDD
>.PrettyPrint(
BDD
characterClass, CharSetSolver solver) => PrettyPrint(characterClass);
103
public string PrettyPrint(
BDD
set)
116
BDD
w = UnicodeCategoryConditions.WordLetter(this);
126
BDD
s = UnicodeCategoryConditions.WhiteSpace;
136
BDD
d = UnicodeCategoryConditions.GetCategory(UnicodeCategory.DecimalDigitNumber);
156
/// <summary>Unions two <see cref="
BDD
"/>s to produce a new <see cref="
BDD
"/>.</summary>
157
public
BDD
Or(
BDD
set1,
BDD
set2) => ApplyBinaryOp(BooleanOperation.Or, set1, set2);
159
/// <summary>Unions <see cref="
BDD
"/>s to produce a new <see cref="
BDD
"/>.</summary>
160
public
BDD
Or(ReadOnlySpan<
BDD
> sets)
167
BDD
result = sets[0];
175
/// <summary>Intersects two <see cref="
BDD
"/>s to produce a new <see cref="
BDD
"/>.</summary>
176
public
BDD
And(
BDD
a,
BDD
b) => ApplyBinaryOp(BooleanOperation.And, a, b);
178
/// <summary>Intersects <see cref="
BDD
"/>s to produce a new <see cref="
BDD
"/>.</summary>
179
public
BDD
And(ReadOnlySpan<
BDD
> sets)
186
BDD
result = sets[0];
194
/// <summary>Negates a <see cref="
BDD
"/> to produce a new complement <see cref="
BDD
"/>.</summary>
195
public
BDD
Not(
BDD
set)
208
(int,
BDD
set,
BDD
?) key = ((int)BooleanOperation.Not, set, null);
209
if (!_operationCache.TryGetValue(key, out
BDD
? result))
219
/// <see cref="
BDD
"/> recursively from <paramref name="set1"/> and <paramref name="set2"/>.
221
private
BDD
ApplyBinaryOp(BooleanOperation op,
BDD
set1,
BDD
set2)
258
if (!_operationCache.TryGetValue(((int)op, set1, set2), out
BDD
? result))
260
BDD
one, two;
289
public
BDD
Full =>
BDD
.True;
292
public
BDD
Empty =>
BDD
.False;
295
public bool IsFull(
BDD
set) => ApplyBinaryOp(BooleanOperation.Xor, set, Full) == Empty;
298
public bool IsEmpty(
BDD
set) => set == Empty;
301
/// Create a <see cref="
BDD
"/> representing the set of values in the range
304
public
BDD
CreateBDDFromRange(char lower, char upper)
312
BDD
CreateBDDFromRangeImpl(uint lower, uint upper, int maxBit)
338
BDD
zero = CreateBDDFromRangeImpl(lower, upper, maxBit - 1);
344
BDD
one = CreateBDDFromRangeImpl(lower & ~mask, upper & ~mask, maxBit - 1);
350
BDD
zero = CreateBDDFromRangeImpl(lower, mask - 1, maxBit - 1);
352
BDD
one = CreateBDDFromRangeImpl(0, upper & ~mask, maxBit - 1);
362
public
BDD
ReplaceTrue(
BDD
bdd, int terminal)
366
BDD
leaf = GetOrCreateBDD(terminal, null, null);
367
return ReplaceTrueImpl(bdd, leaf, new Dictionary<
BDD
,
BDD
>());
369
BDD
ReplaceTrueImpl(
BDD
bdd,
BDD
leaf, Dictionary<
BDD
,
BDD
> cache)
377
if (!cache.TryGetValue(bdd, out
BDD
? result))
379
BDD
one = ReplaceTrueImpl(bdd.One, leaf, cache);
380
BDD
zero = ReplaceTrueImpl(bdd.Zero, leaf, cache);
388
private
BDD
GetOrCreateBDD(int ordinal,
BDD
? one,
BDD
? zero)
390
ref
BDD
? bdd = ref CollectionsMarshal.GetValueRefOrAddDefault(_bddCache, (ordinal, one, zero), out _);
System\Text\RegularExpressions\Symbolic\ISolver.cs (5)
8
/// <see cref="
BDD
"/> representations of those sets, and determining whether an element is in the set.
12
/// <summary>Creates a set from a <see cref="
BDD
"/> representation.</summary>
13
TSet ConvertFromBDD(
BDD
set, CharSetSolver solver);
46
/// <summary>Converts the set into a <see cref="
BDD
"/> representation.</summary>
47
BDD
ConvertToBDD(TSet set, CharSetSolver solver);
System\Text\RegularExpressions\Symbolic\MintermClassifier.cs (2)
35
public MintermClassifier(
BDD
[] minterms)
80
static T[] CreateLookup<T>(
BDD
[] minterms, ReadOnlySpan<object> charRangesPerMinterm, int _maxChar) where T : IBinaryInteger<T>
System\Text\RegularExpressions\Symbolic\MintermGenerator.cs (1)
11
/// <typeparam name="TSet">The type of set of elements (typically <see cref="
BDD
"/>, <see cref="BitVector"/> for more than 64 elements, or <see cref="ulong"/> for 64 or fewer elements).</typeparam>
System\Text\RegularExpressions\Symbolic\RegexNodeConverter.cs (39)
15
internal sealed class RegexNodeConverter(SymbolicRegexBuilder<
BDD
> builder, Hashtable? captureSparseMapping)
20
internal readonly SymbolicRegexBuilder<
BDD
> _builder = builder;
24
private Dictionary<string,
BDD
>? _setBddCache;
29
internal SymbolicRegexNode<
BDD
> ConvertToSymbolicRegexNode(RegexNode root)
34
DoublyLinkedList<SymbolicRegexNode<
BDD
>> rootResult = new();
37
Stack<(RegexNode Node, DoublyLinkedList<SymbolicRegexNode<
BDD
>> Result, DoublyLinkedList<SymbolicRegexNode<
BDD
>>[]? ChildResults)> stack = new();
42
while (stack.TryPop(out (RegexNode Node, DoublyLinkedList<SymbolicRegexNode<
BDD
>> Result, DoublyLinkedList<SymbolicRegexNode<
BDD
>>[]? ChildResults) popped))
45
DoublyLinkedList<SymbolicRegexNode<
BDD
>> result = popped.Result;
46
DoublyLinkedList<SymbolicRegexNode<
BDD
>>[]? childResults = popped.ChildResults;
98
childResults[i] = new DoublyLinkedList<SymbolicRegexNode<
BDD
>>();
112
BDD
bdd = _builder._charSetSolver.CreateBDDFromChar(node.Ch);
127
BDD
setBdd = CreateBDDFromSetString(set);
214
foreach (DoublyLinkedList<SymbolicRegexNode<
BDD
>> childResult in childResults)
226
SymbolicRegexNode<
BDD
> or = _builder._nothing;
231
DoublyLinkedList<SymbolicRegexNode<
BDD
>> childResult = childResults[i];
234
SymbolicRegexNode<
BDD
> elem = childResult.Count == 1 ?
244
SymbolicRegexNode<
BDD
>.CreateAlternate(_builder, elem, or);
254
DoublyLinkedList<SymbolicRegexNode<
BDD
>> childResult = childResults[0];
257
SymbolicRegexNode<
BDD
> body = childResult.Count == 1 ?
270
DoublyLinkedList<SymbolicRegexNode<
BDD
>> childResult = childResults[0];
310
SymbolicRegexNode<
BDD
> ConvertSet(RegexNode node)
320
DoublyLinkedList<SymbolicRegexNode<
BDD
>>[]? CreateChildResultArray(int k) => k == 0 ? null : new DoublyLinkedList<SymbolicRegexNode<
BDD
>>[k];
326
private
BDD
CreateBDDFromSetString(string set)
335
_setBddCache ??= new Dictionary<string,
BDD
>();
339
ref
BDD
? result = ref CollectionsMarshal.GetValueRefOrAddDefault(_setBddCache, set, out _);
343
BDD
Compute(string set)
345
List<
BDD
> conditions = new();
366
BDD
bdd = charSetSolver.CreateBDDFromRange(first, last);
400
BDD
cond = MapCategoryCodeToCondition((UnicodeCategory)(Math.Abs(categoryCode) - 1));
436
BDD
bdd = MapCategoryCodeSetToCondition(categoryCodes);
445
BDD
? subtractorCond = null;
459
BDD
result = conditions.Count == 0 ?
477
BDD
MapCategoryCodeSetToCondition(Span<bool> catCodes)
483
BDD
? result = null;
511
BDD
cond = MapCategoryCodeToCondition((UnicodeCategory)i);
521
BDD
MapCategoryCodeToCondition(UnicodeCategory code)
System\Text\RegularExpressions\Symbolic\SymbolicRegexMatcher.cs (4)
144
/// <param name="bddBuilder">The <see cref="
BDD
"/>-based builder.</param>
145
/// <param name="rootBddNode">The root <see cref="
BDD
"/>-based node from the pattern.</param>
150
SymbolicRegexBuilder<
BDD
> bddBuilder, SymbolicRegexNode<
BDD
> rootBddNode, ISolver<TSet> solver,
System\Text\RegularExpressions\Symbolic\SymbolicRegexMatcher.Sample.cs (7)
42
BDD
asciiWordCharacters = charSetSolver.Or(
50
BDD
ascii = charSetSolver.CreateBDDFromRange('\x20', '\x7E');
51
BDD
asciiNonWordCharacters = charSetSolver.And(ascii, charSetSolver.Not(asciiWordCharacters));
170
static
BDD
ToBDD(TSet set, ISolver<TSet> solver, CharSetSolver charSetSolver) => solver.ConvertToBDD(set, charSetSolver);
174
static char ChooseChar(Random random,
BDD
bdd,
BDD
ascii, CharSetSolver charSetSolver)
178
BDD
bdd1 = charSetSolver.And(bdd, ascii);
System\Text\RegularExpressions\Symbolic\SymbolicRegexRunnerFactory.cs (3)
20
var bddBuilder = new SymbolicRegexBuilder<
BDD
>(charSetSolver, charSetSolver);
23
SymbolicRegexNode<
BDD
> rootNode = converter.ConvertToSymbolicRegexNode(regexTree.Root);
40
BDD
[] minterms = rootNode.ComputeMinterms(bddBuilder);
System\Text\RegularExpressions\Symbolic\UInt64Solver.cs (8)
12
private readonly
BDD
[] _minterms;
15
public UInt64Solver(
BDD
[] minterms)
61
public ulong ConvertFromBDD(
BDD
set, CharSetSolver solver)
63
BDD
[] partition = _minterms;
96
public
BDD
ConvertToBDD(ulong set, CharSetSolver solver)
98
BDD
[] partition = _minterms;
101
BDD
result =
BDD
.False;
System\Text\RegularExpressions\Symbolic\UnicodeCategoryConditions.cs (16)
10
/// <summary>Utility class providing singleton <see cref="
BDD
"/>s for evaluating whether a character is part of a particular Unicode category.</summary>
17
private static readonly
BDD
?[] s_categories = new
BDD
[UnicodeCategoryValueCount];
19
private static volatile
BDD
? s_whiteSpace;
21
private static volatile
BDD
? s_wordLetter;
23
private static volatile
BDD
? s_wordLetterForAnchors;
34
/// <summary>Gets a <see cref="
BDD
"/> that represents the specified <see cref="UnicodeCategory"/>.</summary>
35
public static
BDD
GetCategory(UnicodeCategory category) =>
37
Interlocked.CompareExchange(ref s_categories[(int)category],
BDD
.Deserialize(UnicodeCategoryRanges.GetSerializedCategory(category)), null) ??
40
/// <summary>Gets a <see cref="
BDD
"/> that represents the \s character class.</summary>
41
public static
BDD
WhiteSpace =>
43
Interlocked.CompareExchange(ref s_whiteSpace,
BDD
.Deserialize(UnicodeCategoryRanges.SerializedWhitespaceBDD), null) ??
46
/// <summary>Gets a <see cref="
BDD
"/> that represents the \w character class.</summary>
48
public static
BDD
WordLetter(CharSetSolver solver) =>
66
/// Gets a <see cref="
BDD
"/> that represents <see cref="WordLetter"/> together with the characters
70
public static
BDD
WordLetterForAnchors(CharSetSolver solver) =>
System\Text\RegularExpressions\Symbolic\UnicodeCategoryRangesGenerator.cs (2)
67
BDD
[] catBDDs = new
BDD
[catMap.Count];