public static void AddNewRange <T>(this HashSet <T> hashSet, IEnumerable <T> iEnumerable) { foreach (T t in iEnumerable) { hashSet.AddNew(t); } }
public Component MakePatchAComponent(Patch aPatch) { RemovePatchFromTables(aPatch); VaccineAsString.AddComponent(aPatch.PatchPattern()); Component aComponent = Component.GetInstance(aPatch); Components.AddNew(aComponent); UpdateComponentTables(aComponent); return(aComponent); }
static private HashSet <T> IntersectionInternal <T>(HashSet <T> hashSet1, HashSet <T> other) { HashSet <T> intersection = new HashSet <T>(); foreach (T item1 in hashSet1) { if (other.Contains(item1)) { intersection.AddNew(item1); } } return(intersection); }
private void ParseEndpoint(IEndpoint endpoint) { var relatedSchemas = new HashSet <ISchema>(); var parameters = new Dictionary <string, string>(); var responses = new Dictionary <int, string>(); var returnTypes = new List <string>(); foreach (var parameter in endpoint.GetParameters()) { var parameterTemplates = GeneratorContext.GetTemplateFactory().CreateParameterTemplate( parameter.GetName(), parameter.GetSchema().GetName(), parameter.IsRequired(), parameter.AllowEmptyValue(), parameter.GetSchema().GetSchemaType(), parameter.GetParameterType() ); parameters.Add(parameterTemplates.signature.TransformText(), parameterTemplates.parser.TransformText()); relatedSchemas.AddNew(GetRelatedImportableSchema(parameter.GetSchema())); } var hasBody = false; if (endpoint.GetRequestBody() != null) { hasBody = true; var body = endpoint.GetRequestBody(); var schema = body.GetSchemaForType("application/json"); // todo: handle other types var requestTemplates = GeneratorContext.GetTemplateFactory() .CreateRequestTemplate(schema.GetName(), body.IsRequired()); parameters.Add(requestTemplates.signature.TransformText(), requestTemplates.parser.TransformText()); relatedSchemas.AddNew(GetRelatedImportableSchema(schema)); } foreach (var response in endpoint.GetResponses()) { var schema = response.GetSchemaForType("application/json"); // todo: handle other types; if (schema != null) { var responseParser = GeneratorContext.GetTemplateFactory() .CreateResponseParserTemplate(response.GetStatus(), schema.GetName()); responses.Add(response.GetStatus(), responseParser.TransformText()); relatedSchemas.AddNew(GetRelatedImportableSchema(schema)); if (response.GetStatus().WasSuccessful()) { returnTypes.Add(schema.GetName()); } } } if (returnTypes.Count == 0) { returnTypes.Add("void"); } var endPointTemplate = GeneratorContext.GetTemplateFactory() .CreateEndpointTemplate(endpoint.GetPath(), endpoint.GetId(), parameters.Select(x => x.Key), returnTypes, parameters.Select(x => x.Value), endpoint.GetEndpointType(), hasBody, responses); GeneratorContext.AddFunction(endpoint.GetId(), endPointTemplate.TransformText(), relatedSchemas); }
private IEnumerable <KeyValuePair <HlaMsr1, double> > ExpandHla(TableInfo tableInfo, HlaMsr1 hlaAbstractOrGround, LinkedList1 <HlaMsr1> linkedList1) { HashSet <HlaMsr1> groundSet = new HashSet <HlaMsr1>(); foreach (HlaMsr1 term in hlaAbstractOrGround.TermList(tableInfo.HlaMsr1Factory)) { List <HlaMsr1> groundHlaList; if (tableInfo.AbstractHlaToGroundHlaList.TryGetValue(term, out groundHlaList)) { if (groundHlaList.Count == 1 && groundHlaList.First().Equals(term)) { groundSet.AddNew(term); } else { foreach (HlaMsr1 ground in groundHlaList) { groundSet.AddNew(ground); } } } } if (groundSet.Count == 0) { yield break; } List <Dictionary <HlaMsr1, double> > rowsOfInterest = tableInfo.PullOutTheRowsOfInterest(linkedList1); //!!!for each list of rowsOfInterest we could cache the sum of exp's to speed things up //!!!This could be made faster by giving a serial number to each HLA and then doing the calcuations in arrays in which the serial number is the index. Dictionary <HlaMsr1, double> hlaToTotal = new Dictionary <HlaMsr1, double>(); foreach (Dictionary <HlaMsr1, double> hlaToWeight in rowsOfInterest) { foreach (KeyValuePair <HlaMsr1, double> hlaAndWeight in hlaToWeight) { hlaToTotal[hlaAndWeight.Key] = hlaToTotal.GetValueOrDefault(hlaAndWeight.Key) + hlaAndWeight.Value; } } Dictionary <HlaMsr1, double> hlaToExpTotal = new Dictionary <HlaMsr1, double>(); double totalOfExpsPlus1 = 1; foreach (KeyValuePair <HlaMsr1, double> hlaAndTotal in hlaToTotal) { double exp = Math.Exp(hlaAndTotal.Value); totalOfExpsPlus1 += Math.Exp(hlaAndTotal.Value); hlaToExpTotal.Add(hlaAndTotal.Key, exp); } foreach (HlaMsr1 hlaGround in groundSet) { double prob = hlaToExpTotal[hlaGround] / totalOfExpsPlus1; yield return(new KeyValuePair <HlaMsr1, double>(hlaGround, prob)); } }