Exemple #1
0
        public UintSet Occurances(IEnumerable <char> sequence)
        {
            if (!sequence.Any())
            {
                return(new UintSet());
            }
            if (!chars.ContainsKey(sequence.First()))
            {
                return(new UintSet());
            }
            UintSet locations = chars[sequence.First()];
            int     i         = 1;

            foreach (var c in sequence.Skip(1))
            {
                if (!chars.ContainsKey(c))
                {
                    return(new UintSet());
                }
                var next = chars[c];
                locations = locations.Intersect(next << i++);
                if (locations.Count == 0)
                {
                    break;
                }
            }
            return(locations);
        }
Exemple #2
0
        public void Immutable64FasterIntersectionThanSetT()
        {
            var hash_set_a = ImmutableHashSet <uint> .Empty;
            var hash_set_b = ImmutableHashSet <uint> .Empty;
            var simd_set_a = new UintSet();
            var simd_set_b = new UintSet();

            for (uint i = 0; i < 1000; i++)
            {
                if (i % 3 == 0)
                {
                    hash_set_a = hash_set_a.Add(i);
                }
                if (i % 2 == 0)
                {
                    hash_set_b = hash_set_b.Add(i);
                }
            }

            for (uint i = 0; i < 1000; i++)
            {
                if (i % 3 == 0)
                {
                    simd_set_a = simd_set_a.Add(i);
                }
                if (i % 2 == 0)
                {
                    simd_set_b = simd_set_b.Add(i);
                }
            }

            var timer = new Stopwatch();

            timer.Start();
            for (int i = 0; i < 100_000; i++)
            {
                _ = hash_set_a.Intersect(hash_set_b);
            }
            timer.Stop();
            double time1 = timer.Elapsed.TotalMilliseconds;

            timer.Restart();
            for (int i = 0; i < 100_000; i++)
            {
                _ = simd_set_a.Intersect(simd_set_b);
            }
            timer.Stop();
            double time2 = timer.Elapsed.TotalMilliseconds;

            double ratio = time1 / time2;

            time2.Should().BeLessThan(time1);
            hash_set_a.Intersect(hash_set_b).ToList().Should().BeEquivalentTo(simd_set_a.Intersect(simd_set_b).ToList());
        }
Exemple #3
0
        public SubstringCollection(IEnumerable <char> value, bool caseSensitive = false)
        {
            CaseSensative = caseSensitive;
            uint i = 0;

            foreach (var character in value)
            {
                char c = character;
                if (!CaseSensative && char.IsLetter(c))
                {
                    c = char.ToUpperInvariant(c);
                }
                if (!chars.ContainsKey(c))
                {
                    chars[c] = new UintSet();
                }
                chars[c] = chars[c].Add(i++);
            }
        }
Exemple #4
0
        public UintSet Occurances(IEnumerable <char> sequence, UintSet starts)
        {
            if (!sequence.Any())
            {
                return(starts);
            }
            UintSet locations = starts;
            int     i         = 0;

            foreach (var c in sequence)
            {
                if (!chars.ContainsKey(c))
                {
                    return(new UintSet());
                }
                var next = chars[c];
                locations = locations.Intersect(next << i++);
                if (locations.Count == 0)
                {
                    break;
                }
            }
            return(locations);
        }