lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "DIGY" <>
Subject RE: Question(problem?) about PriorityQueue
Date Mon, 24 Sep 2007 19:38:04 GMT
I checked the java and .net code and they look the same. It seems like it is
a coding preference not to use the index 0.

		protected internal void  Initialize(int maxSize)
			size = 0;
			int heapSize = maxSize + 1; <<<<<<<<<
			heap = new System.Object[heapSize];
			this.maxSize = maxSize;

Can you send a sample code where "some top results are missing"?


-----Original Message-----
From: Hongwei Shen [] 
Sent: Monday, September 24, 2007 9:06 PM
Subject: Question(problem?) about PriorityQueue

Hello there,

The problem we have is that some top results are missing. My debugging led
me to the following piece of code in the PriorityQueue.cs file(line 69). I
simply cannot believe this might be wrong, so I'd like somebody to verify

                public virtual bool Insert(System.Object element)
                        if (size < maxSize)
                                return true;
                        else if (size > 0 && !LessThan(element, Top()))
                                heap[1] = element;
                                return true;
                                return false;

Let's assume that maxSize is 100, when size is larger or equal to 100, the
element is compared with the top element which is heap[1], if it is not less
than the top, then the top is being replaced by the element instead of being
bumped down. It seems to me that this is not the right logic here.

If maxSize is 100, the actual heap size is 101 and the document collector
will collect top docs starting from index 1, so index 0 is never used. I
suspect that the original design of the queue is to insert the new element
in the index 0 and then sort it down.

Please let me know what do you think.


View raw message