public void SimilarityMatrixRawSerializationTest() { string[] sources = new string[] { "source1", "source2", "source3", "source4", "source5", "source6", "source7", "source8", "source9", "source10" }; string[] targets = new string[] { "target1", "target2", "target3", "target4", "target5", "target6", "target7", "target8", "target9", "target10" }; TLSimilarityMatrix matrixIn = new TLSimilarityMatrix(); for (int i = 0; i < sources.Length; i++) { matrixIn.AddLink(sources[i], targets[i], (double)i); } BinaryWriter binWriter = new BinaryWriter(new MemoryStream()); BinaryReader binReader = new BinaryReader(binWriter.BaseStream); matrixIn.WriteData(binWriter); binReader.BaseStream.Position = 0; TLSimilarityMatrix matrixOut = new TLSimilarityMatrix(); matrixOut.ReadData(binReader); Assert.AreEqual(matrixIn.Count, matrixOut.Count); StringHashSet setIn = matrixIn.SourceArtifactsIds; StringHashSet setOut = matrixOut.SourceArtifactsIds; foreach (string artifact in setIn) { Assert.IsTrue(setOut.Contains(artifact)); } }
static void Main(string[] args) { var timer = Stopwatch.StartNew(); StringHashSet names = new StringHashSet(); string input = Console.ReadLine(); while (input != "end") { names.Add(input); input = Console.ReadLine(); } Console.WriteLine(names.Contains("Ivan")); Console.WriteLine(names.Contains("Vivi")); Console.WriteLine(names.Contains("Mariq")); names.Print(); timer.Stop(); Console.WriteLine(timer.ElapsedMilliseconds); }
/// <summary> /// Get relevant links for source artifacts with score larger than threshold. /// </summary> /// <param name="sourceArtifactId">Id of source artifact for which the set of relevant/retrieved links is requested</param> /// <returns>Hashset of target artifacts ids that are retrieved or relevant to the given source artifact (depends on usage).</returns> public StringHashSet GetSetOfTargetArtifactIdsAboveThresholdForSourceArtifact(string sourceArtifactId) { StringHashSet linksForSourceArtifact; if (CacheOfSetsPerSourceArtifacts.TryGetValue(sourceArtifactId, out linksForSourceArtifact) == false) { linksForSourceArtifact = new StringHashSet(); Dictionary <string, double> links; if (m_matrix.TryGetValue(sourceArtifactId, out links)) { foreach (string targetArtifactId in links.Keys) { if (links[targetArtifactId] > Threshold) { linksForSourceArtifact.Add(targetArtifactId); } } } CacheOfSetsPerSourceArtifacts.Add(sourceArtifactId, linksForSourceArtifact); } return(linksForSourceArtifact); //return empty set }
/// <summary> /// Get relevant links for source artifacts with score larger than threshold. /// </summary> /// <param name="sourceArtifactId">Id of source artifact for which the set of relevant/retrieved links is requested</param> /// <returns>Hashset of target artifacts ids that are retrieved or relevant to the given source artifact (depends on usage).</returns> public StringHashSet GetSetOfTargetArtifactIdsAboveThresholdForSourceArtifact(string sourceArtifactId) { StringHashSet linksForSourceArtifact; if (CacheOfSetsPerSourceArtifacts.TryGetValue(sourceArtifactId, out linksForSourceArtifact) == false) { linksForSourceArtifact = new StringHashSet(); Dictionary<string, double> links; if (m_matrix.TryGetValue(sourceArtifactId, out links)) { foreach (string targetArtifactId in links.Keys) { if (links[targetArtifactId] > Threshold) { linksForSourceArtifact.Add(targetArtifactId); } } } CacheOfSetsPerSourceArtifacts.Add(sourceArtifactId, linksForSourceArtifact); } return linksForSourceArtifact; //return empty set }