/// <summary>
        /// Returns the <c>Bucket</c> that contains the <c>value</c>.
        /// </summary>
        public Bucket GetContainerOf(double value)
        {
            LazySort();
            int index = Searching.BinaryMapSearch(_buckets, value);

            if (index < 0)
            {
                throw new ArgumentException(Properties.LocalStrings.ArgumentHistogramContainsNot(value));
            }

            return(_buckets[index]);
        }
Exemple #2
0
        public void TestBinaryMapSearchOnArray()
        {
            int[]         intData = { -2, 3, 5, 20, 21, 1000, 2500 };
            ItemWithMap[] data    = new ItemWithMap[intData.Length];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = new ItemWithMap(intData[i]);
            }

            Assert.That(Searching.BinaryMapSearch(data, -100), Is.LessThan(0));
            Assert.That(Searching.BinaryMapSearch(data, 0), Is.LessThan(0));
            Assert.That(Searching.BinaryMapSearch(data, 100000), Is.LessThan(0));

            for (int i = 0; i < data.Length; i++)
            {
                Assert.That(Searching.BinaryMapSearch(data, intData[i]), Is.EqualTo(i));
            }
        }
 /// <summary>
 /// Returns the index in the <c>Histogram</c> of the <c>Bucket</c>
 /// that contains the <c>value</c>.
 /// </summary>
 public int GetContainerIndexOf(double value)
 {
     LazySort();
     return(Searching.BinaryMapSearch(_buckets, value));
 }