Example #1
0
        public void Add(IPDist p, int k)
        {
            if(p==null || k<=0) return;

            var dist = p.Distance;

            if(_count<k) _count++;
            else
            {
                var max = _set.Max;
                if(dist >= max) return; // Don't add

                // Remove old
                var bag = _lookup[max];
                bag.RemoveLast();
                if(bag.Count==0)
                {
                    _lookup.Remove(max);
                    _set.Remove(max);
                }
            }

            if (_set.Contains(dist)) _lookup[dist].AddLast(p); // Append
            else
            {
                // Insert new
                _set.Add(dist);
                var ps = new LinkedList<IPDist>();
                ps.AddLast(p);
                _lookup.Add(dist, ps);
            }
        }
        public void Add(IPDist p, int k)
        {
            if (p == null || k <= 0)
            {
                return;
            }

            var dist = p.Distance;

            if (_count < k)
            {
                _count++;
            }
            else
            {
                var max = _set.Max;
                if (dist >= max)
                {
                    return;             // Don't add
                }
                // Remove old
                var bag = _lookup[max];
                bag.RemoveLast();
                if (bag.Count == 0)
                {
                    _lookup.Remove(max);
                    _set.Remove(max);
                }
            }

            if (_set.Contains(dist))
            {
                _lookup[dist].AddLast(p);                      // Append
            }
            else
            {
                // Insert new
                _set.Add(dist);
                var ps = new LinkedList <IPDist>();
                ps.AddLast(p);
                _lookup.Add(dist, ps);
            }
        }