Beispiel #1
0
        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);
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
 public bool IsMatched(TLink sequenceCandidate)
 => _equalityComparer.Equals(_links.GetSource(sequenceCandidate), _sequenceMarkerLink) ||
 !_equalityComparer.Equals(_links.SearchOrDefault(_sequenceMarkerLink, sequenceCandidate), _links.Constants.Null);
Beispiel #6
0
 private ulong GetFrequency(ulong source, ulong target)
 {
     return(GetFrequency(_links.SearchOrDefault(source, target), source, target));
 }