Ejemplo n.º 1
0
        internal bool AddNew(T item, double start, double end)
        {
            var weightRange = new WeightRange(start, end);

            this._buckets.Add(new KeyValuePair <WeightRange, T>(weightRange, item));

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="SearchType">Type of searchValue.</typeparam>
        /// <param name="hash">Value to be checked if it falls under any element range.</param>
        /// <param name="searchValue">Look up value in bucket.</param>
        /// <param name="searchValueSelector">Func of T Type which returns a value to be compared with passed searchValue.</param>
        /// <returns></returns>
        //internal T Find<SearchType>(double hash, SearchType searchKey, Func<T, SearchType> searchKeySelector)
        //{
        //    foreach (var pair in this._buckets)
        //    {
        //        if (pair.Key.IsInRange(hash) && searchKey.Equals(searchKeySelector(pair.Value)))
        //        {
        //            return pair.Value;
        //        }
        //    }
        //    return default(T);
        //}

        /// <summary>
        /// Add elements to bucket and out start and end range of added elements.
        /// </summary>
        /// <param name="weight">Weight of provided value within the bucket.</param>
        /// <param name="item">Value to be added.</param>
        /// <param name="start">Out Start range of item.</param>
        /// <param name="end">Out End range of item.</param>
        internal bool Add(double weight, T item, out double start, out double end)
        {
            if (_resetRange)
            {
                this._currentWeight = 0;
            }

            weight *= this._maxWeight / 100;

            end   = this._currentWeight + Math.Floor(weight);
            start = this._currentWeight + _seed;

            var weightRange = new WeightRange(start, end);

            this._buckets.Add(new KeyValuePair <WeightRange, T>(weightRange, item));

            this._currentWeight = end;
            return(true);
        }