Dev2.Data.Binary_Objects.IndexList.SetMaxValue C# (CSharp) Method

SetMaxValue() public method

public SetMaxValue ( int idx, bool isEmpty ) : void
idx int
isEmpty bool
return void
        public void SetMaxValue(int idx, bool isEmpty)
        {
            var currMax = MaxValue;

            if(idx > MaxValue && idx > 0)
            {
                MaxValue = idx;

                // set to zero so we populate gaps correctly ;)
                if(isEmpty)
                {
                    currMax = 0;
                }

                // now fill in the gaps?!
                for(int i = (currMax + 1); i < idx; i++)
                {
                    Gaps.Add(i);
                }
            }

        }

Usage Example

Example #1
0
        public void IndexList_UnitTest_CanSetMaxValueWhenInGaps()
        {

            HashSet<int> gaps = new HashSet<int> { 1, 5 };
            IndexList il = new IndexList(gaps, 5);

            il.SetMaxValue(5, false);

            Assert.AreEqual(1, il.MinValue);
            Assert.AreEqual(5, il.MaxValue);
            Assert.AreEqual(3, il.Count());
        }