[ https://issues.apache.org/jira/browse/MAHOUT-186?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12763172#action_12763172 ]
Ted Dunning commented on MAHOUT-186: ------------------------------------ You are right that I should code up an example before speaking. But it does seem that, against all odds, that what I was suggesting works. Here is a test case that illustrates what I meant. I am still not sure what everybody is saying: {noformat} package com.infovell.logging.test; import junit.framework.TestCase; import java.util.PriorityQueue; import java.util.Random; import java.util.List; import java.util.ArrayList; import java.util.Collections; public class FooTest extends TestCase { public void testQueue() { PriorityQueue<Double> pq = new PriorityQueue<Double>(10); Random gen = new Random(123L); for (int i = 0; i < 1000; i++) { double x = gen.nextDouble(); if (pq.size() < 10 || x > pq.peek()) { pq.add(x); while (pq.size() > 10) { pq.remove(); } } } List<Double> r = new ArrayList<Double>(pq); Collections.reverse(r); System.out.printf("%s\n", r); assertEquals(0.994991252160446, r.get(0), 1e-7); assertEquals(0.9881699208527764, r.get(9), 1e-7); } } {noformat} > Classifier PriorityQueue returns erroneous results > -------------------------------------------------- > > Key: MAHOUT-186 > URL: https://issues.apache.org/jira/browse/MAHOUT-186 > Project: Mahout > Issue Type: Bug > Affects Versions: 0.1, 0.2 > Reporter: Robin Anil > Assignee: Robin Anil > Fix For: 0.2 > > Attachments: MAHOUT-186.patch > > > A simple test fails > import org.apache.hadoop.util.PriorityQueue; > PriorityQueue<ClassifierResult> queue = new ClassifierResultPriorityQueue(3); > queue.insert(new ClassifierResult("label1", 5)); > queue.insert(new ClassifierResult("label2", 4)); > queue.insert(new ClassifierResult("label3", 3)); > queue.insert(new ClassifierResult("label4", 2)); > queue.insert(new ClassifierResult("label5", 1)); > > assertEquals("Incorrect Size", 3, queue.size()); > log.info(queue.pop().toString()); > log.info(queue.pop().toString()); > log.info(queue.pop().toString()); > 09/10/07 16:58:39 INFO common.ClassifierResultPriorityQueueTest: > ClassifierResult{category='label3', score=3.0} > 09/10/07 16:58:39 INFO common.ClassifierResultPriorityQueueTest: > ClassifierResult{category='label4', score=2.0} > 09/10/07 16:58:39 INFO common.ClassifierResultPriorityQueueTest: > ClassifierResult{category='label5', score=1.0} > Expected label1 and label2 at the top -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.