public static Graph Build(IEnumerable <DVD> collection, bool considerCast = true, bool considerCrew = false) { var graph = new Graph(); var duplicateChecker = new Dictionary <string, HashSet <string> >(); //for multiple movies with the same people we con't want to add multiple connections foreach (var profile in collection) { if (!graph.TryGetDistanceNode(ProfileNode.BuildNodeName(profile), out var profileNode)) { profileNode = new ProfileNode(profile); graph.AddNode(profileNode); duplicateChecker.Add(profileNode.Name, new HashSet <string>()); } if (considerCast) { var castMembers = profile.CastList?.OfType <IPerson>() ?? Enumerable.Empty <IPerson>(); AddPersonNodes(graph, profileNode, castMembers, duplicateChecker[profileNode.Name]); } if (considerCrew) { var crewMembers = profile.CrewList?.OfType <IPerson>() ?? Enumerable.Empty <IPerson>(); AddPersonNodes(graph, profileNode, crewMembers, duplicateChecker[profileNode.Name]); } } return(graph); }
public IEnumerable <IPerson> GetJobs(ProfileNode profile) { if (_profiles.TryGetValue(profile.Name, out var jobs)) { foreach (var job in jobs.JobList) { yield return(job); } } }
public void AddJob(ProfileNode profile, IPerson person) { if (!_profiles.TryGetValue(profile.Name, out var jobs)) { jobs = new Jobs(); _profiles.Add(profile.Name, jobs); } jobs.AddJob(person); }