I've got small problem with implementing SortedDictionary class in my aggregate.
In the first version I took simple List<t> class and it works fine, but it consumes a lot of memory to store
and sort all values. So I considered using a SortedDictionary instead of a List and track the number of occurrences instead of storing each element, it should significantly reduce memory consumption.
I added condition where source value is stored as a key and number of occurrence as a value in Accumulate():
public void Accumulate(SqlDouble value, SqlDouble percentile)
this.SrtDict[value.Value] = this.SrtDict[value.Value] + 1;
Everything looks fine but it doesn't work, I check the sum of all occurrences in Terminate method and
when I test it with five different values, it returns result:5
SELECT [dbo].[aggTest](inp.ins,0.5) AS Result
FROM ( SELECT 20.37 AS ins UNION ALL
SELECT 15.45 AS ins UNION ALL
SELECT 1007.23 AS ins UNION ALL
SELECT 11.03 AS ins UNION ALL
) AS inp
But when I duplicate one or more values (eg. 15.45 instead of 12.25), it returns result: 4 (or less).
I built small console app to checked it, works perfectly, so where I screwed up something in the aggregate?
P.S. Script attached.