示例#1
0
        public GenericFindOperation(IFindStrategy ifs, ProgressCallback pc,
                                    AsyncCallback ac) : base(pc, ac, true)
        {
            strategy = ifs;

            strategy.Cancelled = false;
            match = null;
        }
        public PatternHighlighter(DataBook db)
        {
            dataBook     = db;
            findStrategy = new BMFindStrategy();

            foreach (DataViewDisplay dvd in dataBook.Children)
            {
                OnDataViewAdded(dvd.View);
            }

            dataBook.PageAdded += new DataView.DataViewEventHandler(OnDataViewAdded);
            dataBook.Removed   += new RemovedHandler(OnDataViewRemoved);
        }
        /// <summary>
        /// Creates an instance of an integer based <see cref="UnionFind"/> data structure
        /// </summary>
        /// <param name="size">The number of elements to initialize the <see cref="UnionFind"/> instance with</param>
        /// <param name="findStrategy">The find strategy to use when <see cref="Find(int)"/> is called</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if the inputted <paramref name="size"/> is less than or equal to 0</exception>
        public UnionFind(int size, IFindStrategy findStrategy)
        {
            if (size <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(size), Resource.SizeMustBeGreaterThanZero);
            }

            this.elements       = new int[size];
            this.componentSizes = new int[size];
            this.findStrategy   = findStrategy;

            for (var i = 0; i < size; i++)
            {
                this.elements[i]       = i;
                this.componentSizes[i] = 1;
            }

            this.ComponentCount = size;
        }
        /// <summary>
        /// Creates an instance of the generic <see cref="GenericUnionFind{T}"/> with any <see cref="IFindStrategy"/>
        /// </summary>
        /// <exception cref="ArgumentNullException">Thrown if the inputted <paramref name="elements"/> array is null</exception>"
        /// <exception cref="ArgumentException">Thrown if the inputted <paramref name="elements"/> array is empty</exception>
        public UnionFind(T[] elements, IFindStrategy findStrategy)
        {
            if (elements == null)
            {
                throw new ArgumentNullException(nameof(elements));
            }

            if (elements.Length == 0)
            {
                throw new ArgumentException("Argument cannot be an empty array", nameof(elements));
            }

            this.unionFind            = new UnionFind(elements.Length, findStrategy);
            this.indexToElementLookup = new Dictionary <int, T>();
            this.elementToIndexLookup = new Dictionary <T, int>();

            for (var i = 0; i < elements.Length; i++)
            {
                this.indexToElementLookup.Add(i, elements[i]);
                this.elementToIndexLookup.Add(elements[i], i);
            }
        }
示例#5
0
 public FindNextOperation(IFindStrategy ifs, ProgressCallback pc,
                          AsyncCallback ac) : base(ifs, pc, ac)
 {
 }
示例#6
0
 public ReplaceAllOperation(IFindStrategy ifs, ProgressCallback pc,
                            AsyncCallback ac, byte[] repPat) : base(ifs, pc, ac)
 {
     replacePattern = repPat;
 }
        public void TestFind(IFindStrategy findStrategy, int indexToFind, int expectedOutput)
        {
            var elements = new[] { 4, 1, 2, 0, 1, 5 };

            Assert.That(findStrategy.Find(indexToFind, elements), Is.EqualTo(expectedOutput));
        }
 public InvalidStrategyArgumentTypeException(Type argType, IFindStrategy <T> strategy) : base()
 {
     ArgumentType = argType;
     Strategy     = strategy;
 }