/// <summary> /// Returns the set of <see cref="OptionPosition"/> with the specified <paramref name="strike"/> /// </summary> public IEnumerable <OptionPosition> ForStrike(decimal strike) { ImmutableHashSet <Symbol> symbols; return(_strikes.TryGetValue(strike, out symbols) ? ForSymbols(symbols) : Enumerable.Empty <OptionPosition>()); }
/// <summary> /// Returns the set of <see cref="OptionPosition"/> with the specified <paramref name="expiration"/> /// </summary> public IEnumerable <OptionPosition> ForExpiration(DateTime expiration) { ImmutableHashSet <Symbol> symbols; return(_expirations.TryGetValue(expiration, out symbols) ? ForSymbols(symbols) : Enumerable.Empty <OptionPosition>()); }
public IPackageInfo GetOrFetch(string packageId) { if (packages.TryGetValue(packageId, out IPackageInfo package)) { return(package); } return(Fetch(packageId)); }
public IConfig Get(string configPath) { string key = configPath.GetFullConsolidatedPath(); configs.TryGetValue(key, out IConfig config); return(config); }
public DataModelType GetTypeByG4Name(string g4Name) { DataModelType answer; _g4Lookup.TryGetValue(g4Name, out answer); return(answer); }
public static ImmutableSortedDictionary <int, int> .Builder Increase(this ImmutableSortedDictionary <int, int> .Builder b, int f) { if (!b.TryGetValue(f, out var newCount)) { newCount = 0; } b[f] = ++newCount; return(b); }
public static TypeSymbol?TryGetDeclarationType(string?typeName) { if (typeName != null && DeclarationTypes.TryGetValue(typeName, out TypeSymbol primitiveType)) { return(primitiveType); } return(null); }
private ImmutableArray <TExtension> GetLanguageSpecificAnalyzers(Assembly analyzerAssembly, ImmutableSortedDictionary <string, ImmutableSortedSet <string> > analyzerTypeNameMap, string language, ref bool reportedError) { ImmutableSortedSet <string>?languageSpecificAnalyzerTypeNames; if (!analyzerTypeNameMap.TryGetValue(language, out languageSpecificAnalyzerTypeNames)) { return(ImmutableArray <TExtension> .Empty); } return(this.GetAnalyzersForTypeNames(analyzerAssembly, languageSpecificAnalyzerTypeNames, ref reportedError)); }
public bool ImmutableSortedDictionary() { bool result = default; ImmutableSortedDictionary <TKey, TValue> collection = _immutableSortedDictionary; TKey[] notFound = _notFound; for (int i = 0; i < notFound.Length; i++) { result ^= collection.TryGetValue(notFound[i], out _); } return(result); }
private static ImmutableSortedDictionary <DateTime, State> AddOrUpdateStatesDictAndCleanOld( ImmutableSortedDictionary <DateTime, State> states, State newState, DateTime now) { var minEventTime = now - TimeSpan.FromMinutes(1); var old = states.Keys.SkipWhile(e => e < minEventTime); states = states.RemoveRange(old); if (states.TryGetValue(now, out var oldState)) { newState = new State(oldState, newState); } return(states.SetItem(now, newState)); }
/// <summary> /// Filters the provided <paramref name="values"/> according to this <see cref="BinaryComparison"/> /// and the specified <paramref name="reference"/> value. The <paramref name="reference"/> value is /// used as the RIGHT side of the binary comparison. Consider the binary comparison is LessThan and /// we call Filter(values, 42). We're looking for keys that are less than 42. /// </summary> public static Tuple <ImmutableSortedDictionary <TKey, TValue>, ImmutableSortedDictionary <TKey, TValue> > SplitBy <TKey, TValue>( this BinaryComparison comparison, ImmutableSortedDictionary <TKey, TValue> values, TKey reference ) { var matches = ImmutableSortedDictionary <TKey, TValue> .Empty; var removed = ImmutableSortedDictionary <TKey, TValue> .Empty; if (comparison.Type == ExpressionType.NotEqual) { var match = values.Remove(reference); removed = BinaryComparison.Equal.Filter(values, reference); return(Tuple.Create(match, removed)); } if (comparison.Type == ExpressionType.Equal) { TValue value; if (values.TryGetValue(reference, out value)) { matches = matches.Add(reference, value); removed = BinaryComparison.NotEqual.Filter(values, reference); return(Tuple.Create(matches, removed)); } // no matches return(Tuple.Create(ImmutableSortedDictionary <TKey, TValue> .Empty, values)); } var evaluator = comparison.GetEvaluator <TKey>(); foreach (var kvp in values) { if (evaluator(kvp.Key, reference)) { matches = matches.Add(kvp.Key, kvp.Value); } else { removed = removed.Add(kvp.Key, kvp.Value); } } return(Tuple.Create(matches, removed)); }
/// <summary> /// Filters the provided <paramref name="values"/> according to this <see cref="BinaryComparison"/> /// and the specified <paramref name="reference"/> value. The <paramref name="reference"/> value is /// used as the RIGHT side of the binary comparison. Consider the binary comparison is LessThan and /// we call Filter(values, 42). We're looking for keys that are less than 42. /// </summary> public static ImmutableSortedDictionary <TKey, TValue> Filter <TKey, TValue>( this BinaryComparison comparison, ImmutableSortedDictionary <TKey, TValue> values, TKey reference ) { if (comparison.Type == ExpressionType.NotEqual) { return(values.Remove(reference)); } var result = ImmutableSortedDictionary <TKey, TValue> .Empty; if (comparison.Type == ExpressionType.Equal) { TValue value; if (values.TryGetValue(reference, out value)) { result = result.Add(reference, value); } return(result); } // since we're enumerating a sorted collection, once we receive // a mismatch it means we'll never again receive a match var breakAfterFailure = comparison == BinaryComparison.LessThanOrEqual || comparison == BinaryComparison.LessThanOrEqual; var evaluator = comparison.GetEvaluator <TKey>(); foreach (var kvp in values) { if (evaluator(kvp.Key, reference)) { result = result.Add(kvp.Key, kvp.Value); } else if (breakAfterFailure) { break; } } return(result); }
public static ImmutableSortedDictionary <string, HoistAction> RemoveCycles(ImmutableSortedDictionary <string, HoistAction> edges) { ImmutableSortedDictionary <string, HoistAction> .Builder builder = edges.ToBuilder(); foreach (KeyValuePair <string, HoistAction> currentEdge in edges) { string targetKey = FindCycle(builder, currentEdge); if (targetKey != null) { HoistAction nextKey; while (builder.TryGetValue(targetKey, out nextKey)) { builder.Remove(targetKey); targetKey = nextKey.Becomes; } } } return(builder.ToImmutable()); }
public static ImmutableSortedDictionary <string, HoistAction> ApplyTransitiveProperty(ImmutableSortedDictionary <string, HoistAction> edges) { ImmutableSortedDictionary <string, HoistAction> .Builder builder = edges.ToBuilder(); var keys = new List <KeyValuePair <string, HoistAction> >(); foreach (string startingKey in edges.Keys) { keys.Clear(); string currentKey = startingKey; HoistAction currentValue; while (builder.TryGetValue(currentKey, out currentValue)) { keys.Add(Pair.Make(currentKey, currentValue)); currentKey = currentValue.Becomes; } Debug.Assert(keys.Count > 0); if (keys.Count <= 1) { // No transitive behavior to apply continue; } string becomes = keys[keys.Count - 1].Value.Becomes; int addedRanks = keys[keys.Count - 1].Value.AddedRanks; for (int idx = keys.Count - 2; idx >= 0; --idx) { KeyValuePair <string, HoistAction> key = keys[idx]; addedRanks += key.Value.AddedRanks; builder[key.Key] = new HoistAction(becomes, addedRanks); } } return(builder.ToImmutable()); }
internal bool TryGetDocument(DocumentReference docRef, out DocumentSnapshot document) => _keyIndex.TryGetValue(docRef, out document);
/// <summary> /// Converts string literal text into its value. Returns null if the specified string token is malformed due to lexer error recovery. /// </summary> /// <param name="stringToken">the string token</param> public static string?TryGetStringValue(Token stringToken) { var(start, end) = stringToken.Type switch { TokenType.StringComplete => (LanguageConstants.StringDelimiter, LanguageConstants.StringDelimiter), TokenType.StringLeftPiece => (LanguageConstants.StringDelimiter, LanguageConstants.StringHoleOpen), TokenType.StringMiddlePiece => (LanguageConstants.StringHoleClose, LanguageConstants.StringHoleOpen), TokenType.StringRightPiece => (LanguageConstants.StringHoleClose, LanguageConstants.StringDelimiter), _ => (null, null), }; if (start == null || end == null) { return(null); } if (stringToken.Text.Length < start.Length + end.Length || stringToken.Text.Substring(0, start.Length) != start || stringToken.Text.Substring(stringToken.Text.Length - end.Length) != end) { // any lexer-generated token should not hit this problem as the start & end are already verified return(null); } var contents = stringToken.Text.Substring(start.Length, stringToken.Text.Length - start.Length - end.Length); var window = new SlidingTextWindow(contents); // the value of the string will be shorter because escapes are longer than the characters they represent var buffer = new StringBuilder(contents.Length); while (!window.IsAtEnd()) { var nextChar = window.Next(); if (nextChar == '\'') { return(null); } if (nextChar == '\\') { // escape sequence begins if (window.IsAtEnd()) { return(null); } char escapeChar = window.Next(); if (escapeChar == 'u') { // unicode escape char openCurly = window.Next(); if (openCurly != '{') { return(null); } var codePointText = ScanHexNumber(window); if (!TryParseCodePoint(codePointText, out uint codePoint)) { // invalid codepoint return(null); } char closeCurly = window.Next(); if (closeCurly != '}') { return(null); } char charOrHighSurrogate = CodepointToString(codePoint, out char lowSurrogate); buffer.Append(charOrHighSurrogate); if (lowSurrogate != SlidingTextWindow.InvalidCharacter) { // previous char was a high surrogate // also append the low surrogate buffer.Append(lowSurrogate); } continue; } if (SingleCharacterEscapes.TryGetValue(escapeChar, out char escapeCharValue) == false) { // invalid escape character return(null); } buffer.Append(escapeCharValue); // continue to next iteration continue; } // regular string char - append to buffer buffer.Append(nextChar); } return(buffer.ToString()); }
public static IReadOnlyList <MorseSymbol> ToMorse(char c) => _alphabet.TryGetValue(char.ToUpper(c), out MorseSymbol[]? code) ? code : _alphabet[' '];
/// <summary> /// Converts string literal text into its value. Returns null if the specified string token is malformed due to lexer error recovery. /// </summary> /// <param name="stringToken">the string token</param> public static string?TryGetStringValue(Token stringToken) { var(start, end) = stringToken.Type switch { TokenType.StringComplete => (LanguageConstants.StringDelimiter, LanguageConstants.StringDelimiter), TokenType.StringLeftPiece => (LanguageConstants.StringDelimiter, LanguageConstants.StringHoleOpen), TokenType.StringMiddlePiece => (LanguageConstants.StringHoleClose, LanguageConstants.StringHoleOpen), TokenType.StringRightPiece => (LanguageConstants.StringHoleClose, LanguageConstants.StringDelimiter), _ => (null, null), }; if (start == null || end == null) { return(null); } if (stringToken.Text.Length < start.Length + end.Length || stringToken.Text.Substring(0, start.Length) != start || stringToken.Text.Substring(stringToken.Text.Length - end.Length) != end) { // any lexer-generated token should not hit this problem as the start & end are already verified return(null); } var contents = stringToken.Text.Substring(start.Length, stringToken.Text.Length - start.Length - end.Length); var window = new SlidingTextWindow(contents); // the value of the string will be shorter because escapes are longer than the characters they represent var buffer = new StringBuilder(contents.Length); while (!window.IsAtEnd()) { var nextChar = window.Next(); if (nextChar == '\'') { return(null); } if (nextChar == '\\') { // escape sequence begins if (window.IsAtEnd()) { return(null); } char escapeChar = window.Next(); if (CharacterEscapes.TryGetValue(escapeChar, out char escapeCharValue) == false) { // invalid escape character return(null); } buffer.Append(escapeCharValue); // continue to next iteration continue; } // regular string char - append to buffer buffer.Append(nextChar); } return(buffer.ToString()); }
public bool TryGetValue(string path, out TreeEntry entry) => _items.TryGetValue(path, out entry);
public static DataModel HoistTypes(DataModel source) { ImmutableSortedDictionary <string, HoistAction> hoistMap = GetViableHoistEdgeList(source); if (hoistMap.Count == 0) { return(source); } hoistMap = RemoveCycles(hoistMap); hoistMap = ApplyTransitiveProperty(hoistMap); var newTypes = new List <DataModelType>(); foreach (DataModelType sourceType in source.Types) { if (hoistMap.ContainsKey(sourceType.G4DeclaredName)) { // This type is being eliminated continue; } bool anythingDifferent = false; ImmutableArray <DataModelMember> .Builder newMembers = ImmutableArray.CreateBuilder <DataModelMember>(); foreach (DataModelMember sourceMember in sourceType.Members) { HoistAction todo; if (hoistMap.TryGetValue(sourceMember.DeclaredName, out todo)) { anythingDifferent = true; newMembers.Add(new DataModelMember( todo.Becomes, sourceMember.CSharpName, sourceMember.SerializedName, sourceMember.SummaryText, sourceMember.ArgumentName, sourceMember.Pattern, sourceMember.Minimum, sourceMember.MinItems, sourceMember.UniqueItems, sourceMember.Default, sourceMember.Rank + todo.AddedRanks, sourceMember.Required )); } else { newMembers.Add(sourceMember); } } if (anythingDifferent) { newTypes.Add(new DataModelType( sourceType.RootObject, sourceType.SummaryText, sourceType.RemarksText, sourceType.G4DeclaredName, sourceType.CSharpName, sourceType.InterfaceName, newMembers.ToImmutable(), ImmutableArray <string> .Empty, ImmutableArray <string> .Empty, ImmutableArray <ToStringEntry> .Empty, sourceType.Base, sourceType.Kind )); } else { newTypes.Add(sourceType); } } return(new DataModel(source.SourceFilePath, source.MetaData, newTypes)); }
public static IHandlerTypeDescriptor GetHandlerTypeDescriptor(string method) { return(KnownHandlers.TryGetValue(method, out var descriptor) ? descriptor : null); }
public IProject Get(string projectPath) { projects.TryGetValue(projectPath, out IProject result); return(result); }