public static TLink DeleteIfExists <TLink>(this ILinks <TLink> links, TLink source, TLink target) { var link = links.SearchOrDefault(source, target); if (!EqualityComparer <TLink> .Default.Equals(link, default)) { links.Delete(link); return(link); } return(default);
public static TLink GetOrCreate <TLink>(this ILinks <TLink> links, TLink source, TLink target) { var link = links.SearchOrDefault(source, target); if (EqualityComparer <TLink> .Default.Equals(link, default)) { link = links.CreateAndUpdate(source, target); } return(link); }
public static void RunRandomSearches <TLink>(this ILinks <TLink> links, ulong amountOfSearches) { var random = RandomHelpers.Default; var addressToUInt64Converter = UncheckedConverter <TLink, ulong> .Default; var uInt64ToAddressConverter = UncheckedConverter <ulong, TLink> .Default; for (var i = 0UL; i < amountOfSearches; i++) { var linksAddressRange = new Range <ulong>(0, addressToUInt64Converter.Convert(links.Count())); var source = uInt64ToAddressConverter.Convert(random.NextUInt64(linksAddressRange)); var target = uInt64ToAddressConverter.Convert(random.NextUInt64(linksAddressRange)); links.SearchOrDefault(source, target); } }
public static TLink UpdateOrCreateOrGet <TLink>(this ILinks <TLink> links, TLink source, TLink target, TLink newSource, TLink newTarget) { var equalityComparer = EqualityComparer <TLink> .Default; var link = links.SearchOrDefault(source, target); if (equalityComparer.Equals(link, default)) { return(links.CreateAndUpdate(newSource, newTarget)); } if (equalityComparer.Equals(newSource, source) && equalityComparer.Equals(newTarget, target)) { return(link); } return(links.Update(link, newSource, newTarget)); }
public bool IsMatched(TLink sequenceCandidate) => _equalityComparer.Equals(_links.GetSource(sequenceCandidate), _sequenceMarkerLink) || !_equalityComparer.Equals(_links.SearchOrDefault(_sequenceMarkerLink, sequenceCandidate), _links.Constants.Null);
private ulong GetFrequency(ulong source, ulong target) { return(GetFrequency(_links.SearchOrDefault(source, target), source, target)); }