コード例 #1
0
        public T Search(ICountable <T> array, T item)
        {
            var arr   = array.GetEnumerable().OrderBy(x => x).ToList();
            var lower = 0;
            var upper = arr.Count - 1;
            var mid   = -1;

            while (lower < upper)
            {
                mid = lower + (upper - lower) /
                      (Math.Abs(arr[upper].GetHashCode()) - Math.Abs(arr[lower].GetHashCode())) *
                      (Math.Abs(item.GetHashCode()) - Math.Abs(arr[lower].GetHashCode()));
                if (arr[mid].CompareTo(item) < 0)
                {
                    lower = mid + 1;
                }
                else if (arr[mid].CompareTo(item) > 0)
                {
                    upper = mid - 1;
                }
                else
                {
                    return(arr[mid]);
                }
            }

            if (lower == upper && arr[lower].CompareTo(item) == 0)
            {
                return(arr[lower]);
            }
            return(default(T));
        }
コード例 #2
0
ファイル: ShellSort.cs プロジェクト: amuratgencay/DSA
        public ICountable <T> Sort(ICountable <T> array)
        {
            var arr = (ICountable <T>)array.Clone();
            var gap = arr.Count / 2;

            while (gap > 0)
            {
                for (var i = 0; i + gap < arr.Count; i++)
                {
                    var j   = i + gap;
                    var tmp = arr[j];
                    while (j - gap >= 0 && tmp.CompareTo(arr[j - gap]) < 0)
                    {
                        arr[j] = arr[j - gap];
                        j     -= gap;
                    }

                    arr[j] = tmp;
                }

                gap /= 2;
            }

            return(arr);
        }
コード例 #3
0
 public static void Count(ICountable c, int maxCount)
 {
     for (int i = 0; i < maxCount; i++)
     {
         c.IncrementCount();
         Console.WriteLine($"{c.GetCountString()}");
     }
 }
コード例 #4
0
ファイル: CountUtil.cs プロジェクト: mphern/GrandCircusLab14
 public static void Count(ICountable c, int MaxCount)
 {
     while (c.GetCount() <= MaxCount)
     {
         Console.WriteLine(c.GetCountString() + " " + c.Name);
         c.IncrementCount();
     }
 }
コード例 #5
0
 public static void count(ICountable c, int maxCount)
 {
     for (int i = 0; i < maxCount; i++)
     {
         c.incrementCount();
         Console.WriteLine(c.getCountString() + " " + c.GetType().ToString().Split('.')[1]);
     }
 }
コード例 #6
0
 public static void Count(ICountable c, int MaxCount)
 {
     Console.WriteLine("");
     for (; c.GetCount() <= MaxCount; c.IncrementCount())
     {
         Console.WriteLine(c.ToString());
     }
     c.ResetCount();
 }
コード例 #7
0
        public static CountCommand Count(this ICountable countable)
        {
            var countCommand = new CountCommand(countable.Client)
            {
                ParentSelector = countable
            };

            return(countCommand);
        }
コード例 #8
0
ファイル: CountUntil.cs プロジェクト: linksdeity/Lab14
        public static void Count(ICountable c, int maxCount)
        {
            for (int i = 1; i <= maxCount; i++)
            {
                c.IncrementCount();
                Console.WriteLine(c.GetCountString() + " " + c.Name + "\n");
            }

            c.ResetCount();
        }
コード例 #9
0
 public static void Count(ICountable c, int maxCount)
 {//counts up to the specified max and prints each count
     while (c.GetCount() < maxCount)
     {
         c.IncrementCount();
         c.FormatCount();
         Thread.Sleep(500);
     }
     Console.WriteLine();
 }
コード例 #10
0
ファイル: CountUtil.cs プロジェクト: mmhilty/GCLab14
 public void Count(ICountable c, int MaxCount)
 {
     Console.WriteLine($"Counting {c.GetType().Name}s:\n");
     for (int i = 0; i < MaxCount; i++)
     {
         c.IncrementCount();
         Console.WriteLine($"{c.GetCount()}. {c.ReturnName()}");
     }
     c.ResetCount();
     Console.WriteLine("");
 }
コード例 #11
0
 public T Search(ICountable <T> array, T item)
 {
     for (var i = 0; i < array.Count; i++)
     {
         if (array[i].Equals(item))
         {
             return(array[i]);
         }
     }
     return(default(T));
 }
コード例 #12
0
        private void IncrementCreatedInstanceCount(ICountable instance)
        {
            var className = instance.GetType().Name;

            if (!CreatedInstancesCount.ContainsKey(className))
            {
                CreatedInstancesCount.Add(className, new List <ICountable>());
            }

            CreatedInstancesCount[className].Add(instance);
        }
コード例 #13
0
 public static void Count(ICountable c, int maxCount)
 {
     //use while to count the number of Countable objects
     while (maxCount != 0)
     {
         c.IncrementCount();
         Console.WriteLine(c.GetCountString());
         maxCount--;
     }
     Console.WriteLine();
     //reset the count
     c.ResetCount();
 }
コード例 #14
0
ファイル: CountUtil.cs プロジェクト: linzchang/GC_Lab14
        public static void Count(ICountable e, int MaxCount)
        {
            int delay = 1000;

            for (int i = 0; i < MaxCount; i++)
            {
                e.IncrementCount();
                Console.WriteLine(e.GetCountString());
                Thread.Sleep(delay);
            }
            CountChuckle.AhAhAh();
            Console.WriteLine(" ");
        }
コード例 #15
0
ファイル: CountableExample.cs プロジェクト: amuratgencay/DSA
 public CountableExample(ICountable <T> countable, T searchItem, T containsItem, T indexOfItem, T lastIndexOfItem, int setIndex, T setValue, int getIndex, Action beforeStep = null, Action afterStep = null)
 {
     _searchItem      = searchItem;
     Countable        = countable;
     _containsItem    = containsItem;
     _indexOfItem     = indexOfItem;
     _lastIndexOfItem = lastIndexOfItem;
     _setIndex        = setIndex;
     _setValue        = setValue;
     _getIndex        = getIndex;
     BeforeStep       = beforeStep;
     AfterStep        = afterStep;
 }
コード例 #16
0
ファイル: CountStream.cs プロジェクト: Yitzchok/PublicDomain
 /// <summary>
 /// Initializes a new instance of the <see cref="CountStream"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="location">The location.</param>
 public CountStream(CountStreamType type, string location)
 {
     m_type = type;
     m_location = location;
     switch (type)
     {
         case CountStreamType.Directory:
             m_first = new CountableDirectory(location);
             break;
         case CountStreamType.VSSolution2005:
             m_first = new DotNetSolution(location);
             break;
         default:
             throw new NotImplementedException();
     }
 }
コード例 #17
0
        /// <summary>
        /// Reads this instance.
        /// </summary>
        /// <returns></returns>
        public override ICountable Read()
        {
            if (m_finished)
            {
                return(null);
            }

            // If current is NULL, then this is the first ICountable to read
            if (m_current == null)
            {
                m_current           = m_first;
                m_currentChildIndex = -1;
                m_stack.Push(new Pair <ICountable, int>(m_current, 0));
            }

            // If the current index is -1, we return the current item and
            // increment the current child index
            if (m_currentChildIndex == -1)
            {
                m_currentChildIndex++;
                return(m_current);
            }

            // Check if we have read all children, recursively
            while (m_current.Children.Count == 0 || m_current.Children.Count == m_currentChildIndex)
            {
                Pair <ICountable, int> last = m_stack.Pop();
                m_current           = last.First;
                m_currentChildIndex = last.Second;

                if (m_current == m_first && m_current.Children.Count == m_currentChildIndex)
                {
                    m_finished = true;
                    return(null);
                }
            }

            ICountable result = m_current.Children[m_currentChildIndex];

            m_stack.Push(new Pair <ICountable, int>(m_current, m_currentChildIndex + 1));
            m_currentChildIndex = 0;
            m_current           = result;

            return(result);
        }
コード例 #18
0
        /// <summary>
        /// Reads this instance.
        /// </summary>
        /// <returns></returns>
        public override ICountable Read()
        {
            if (m_finished)
            {
                return null;
            }

            // If current is NULL, then this is the first ICountable to read
            if (m_current == null)
            {
                m_current = m_first;
                m_currentChildIndex = -1;
                m_stack.Push(new Pair<ICountable, int>(m_current, 0));
            }

            // If the current index is -1, we return the current item and
            // increment the current child index
            if (m_currentChildIndex == -1)
            {
                m_currentChildIndex++;
                return m_current;
            }

            // Check if we have read all children, recursively
            while (m_current.Children.Count == 0 || m_current.Children.Count == m_currentChildIndex)
            {
                Pair<ICountable, int> last = m_stack.Pop();
                m_current = last.First;
                m_currentChildIndex = last.Second;

                if (m_current == m_first && m_current.Children.Count == m_currentChildIndex)
                {
                    m_finished = true;
                    return null;
                }
            }

            ICountable result = m_current.Children[m_currentChildIndex];

            m_stack.Push(new Pair<ICountable, int>(m_current, m_currentChildIndex + 1));
            m_currentChildIndex = 0;
            m_current = result;

            return result;
        }
コード例 #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CountStream"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="location">The location.</param>
        public CountStream(CountStreamType type, string location)
        {
            m_type     = type;
            m_location = location;
            switch (type)
            {
            case CountStreamType.Directory:
                m_first = new CountableDirectory(location);
                break;

            case CountStreamType.VSSolution2005:
                m_first = new DotNetSolution(location);
                break;

            default:
                throw new NotImplementedException();
            }
        }
コード例 #20
0
ファイル: BubbleSort.cs プロジェクト: amuratgencay/DSA
        public ICountable <T> Sort(ICountable <T> array)
        {
            var arr = (ICountable <T>)array.Clone();

            for (var i = 0; i < arr.Count - 1; i++)
            {
                for (var j = 0; j < arr.Count - 1; j++)
                {
                    if (arr[j].CompareTo(arr[j + 1]) > 0)
                    {
                        var tmp = arr[j];
                        arr[j]     = arr[j + 1];
                        arr[j + 1] = tmp;
                    }
                }
            }

            return(arr);
        }
コード例 #21
0
        public ICountable <T> Sort(ICountable <T> array)
        {
            var arr = (ICountable <T>)array.Clone();

            for (var i = 1; i < arr.Count; i++)
            {
                var insert = arr[i];
                var pos    = i;
                while (pos > 0 && arr[pos - 1].CompareTo(insert) > 0)
                {
                    arr[pos] = arr[pos - 1];
                    pos--;
                }

                arr[pos] = insert;
            }

            return(arr);
        }
コード例 #22
0
        public ICountable <T> Sort(ICountable <T> array)
        {
            var arr = (ICountable <T>)array.Clone();

            for (var i = 0; i < arr.Count - 1; i++)
            {
                var min = i;
                for (var j = i + 1; j < arr.Count; j++)
                {
                    if (arr[j].CompareTo(arr[min]) < 0)
                    {
                        min = j;
                    }
                }

                var tmp = arr[i];
                arr[i]   = arr[min];
                arr[min] = tmp;
            }

            return(arr);
        }
コード例 #23
0
        public IEnumerator Setup()
        {
            var scene = SceneManager.LoadSceneAsync("CollisionPlayerController");

            while (!scene.isDone)
            {
                yield return(null);
            }

            sut = GameObject.FindGameObjectWithTag("Player");
            Assert.That(sut != null, "There must be tagged player in the scene");
            Assert.That(sut.transform.position, Is.EqualTo(Vector3.zero), "Player shoudl be at the center of the scene");

            var rigidbody = sut.GetComponent <Rigidbody>();

            Assert.That(rigidbody != null, "Player must have a rigidbody component");
            Assert.That(rigidbody.useGravity, Is.False, "Player must not be using gravity");

            var collider = sut.GetComponent <Collider>();

            Assert.That(collider != null, "Player must have a collider");
            Assert.That(collider.isTrigger, Is.True, "Player must have a triggerable collider");

            audio = sut.GetComponent <AudioSourceMockController>();
            Assert.That(audio != null, "The player must have audio mock");

            var text = GameObject.Find("DisplayManager");

            Assert.That(text != null, "There should be a display available");

            display = text.GetComponent <TextMeshProUGUI>();
            Assert.That(display != null, "There must be text in the display");
            Assert.That(display.text, Is.EqualTo("0"), "Display should be zero");

            counter = sut.GetComponent <ICountable>();
            Assert.That(counter != null, "The player must be countable");
            Assert.That(counter.Count, Is.EqualTo(0), "Counter must start at zero");
        }
コード例 #24
0
 public DeadLetterTestProcessor(ICountable countable)
 {
     _countable = countable;
 }
コード例 #25
0
 public DiTestCommandHandler(ICountable countable)
 {
     _countable = countable;
 }
コード例 #26
0
ファイル: Program.cs プロジェクト: MikeyTeal23/CounterApp
 static int CountItem(int total, ICountable item)
 {
     total += item.Count();
     return(total);
 }
コード例 #27
0
ファイル: ArrayExample.cs プロジェクト: amuratgencay/DSA
 public ArrayExample(ICountable <int> array) : base(array, 5, 8, 13, 13, 1, 21, 2, FirstInit, SecondInit)
 {
     _array = array;
 }
コード例 #28
0
 public HomeController(ICountable countPlz)
 {
     this.countPlz = countPlz;
 }
コード例 #29
0
 public MultipleCommandProcessor(ICountable countable)
 {
     _countable = countable;
 }
コード例 #30
0
ファイル: EventProcessor.cs プロジェクト: viktor-h/knightbus
 public EventProcessor(ICountable countable)
 {
     _countable = countable;
 }
コード例 #31
0
 public SagaDuplicateWithDuplicate(ICountable countable, bool throwOnProcess = false)
 {
     _countable      = countable;
     _throwOnProcess = throwOnProcess;
     MessageMapper.MapStartMessage <SagaStartMessage>(m => "b");
 }
コード例 #32
0
 public NumberCounterController(ICountable countable)
 {
     numberCounter = countable;
 }