public List<Counter<T>> topK(int k) { List<Counter<T>> topK = new ArrayList<Counter<T>>(k); for (ListNode2<Bucket> bNode = bucketList.head(); bNode != null; bNode = bNode.getPrev()) { Bucket b = bNode.getValue(); for (Counter<T> c : b.counterList) { if (topK.size() == k) { return topK; } topK.add(c); } } return topK; }
@Override public List<T> peek(int k) { List<T> topK = new ArrayList<T>(k); for (ListNode2<Bucket> bNode = bucketList.head(); bNode != null; bNode = bNode.getPrev()) { Bucket b = bNode.getValue(); for (Counter<T> c : b.counterList) { if (topK.size() == k) { return topK; } topK.add(c.item); } } return topK; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append('['); for (ListNode2<Bucket> bNode = bucketList.head(); bNode != null; bNode = bNode.getPrev()) { Bucket b = bNode.getValue(); sb.append('{'); sb.append(b.count); sb.append(":["); for (Counter<T> c : b.counterList) { sb.append('{'); sb.append(c.item); sb.append(':'); sb.append(c.error); sb.append("},"); } if (b.counterList.size() > 0) { sb.deleteCharAt(sb.length() - 1); } sb.append("]},"); } if (bucketList.size() > 0) { sb.deleteCharAt(sb.length() - 1); } sb.append(']'); return sb.toString(); }
private <T> void assertIsEmpty(DoublyLinkedList<T> list) { assertNull(list.tail()); assertNull(list.head()); assertNull(list.first()); assertNull(list.last()); assertTrue(list.isEmpty()); assertEquals(0, list.size()); for (T i : list) { fail("What is this: " + i + " ?"); } }
@Test public void testAddAfter() { DoublyLinkedList<Integer> list = new DoublyLinkedList<Integer>(); list.add(1); ListNode2<Integer> node2 = list.add(2); ListNode2<Integer> node4 = list.add(4); list.addAfter(node2, 3); assertEquals(4, list.size()); assertArrayEquals(new Integer[]{1, 2, 3, 4}, list.toArray()); ListNode2<Integer> node5 = list.addAfter(node4, 5); assertEquals(5, list.size()); assertArrayEquals(new Integer[]{1, 2, 3, 4, 5}, list.toArray()); assertEquals(new Integer(5), list.last()); assertEquals(node5, list.head()); }
assertEquals(1, list.size()); assertEquals(new Integer(2), list.first()); assertEquals(node2, list.head()); assertArrayEquals(new Integer[]{2}, list.toArray()); list.remove(node2); assertEquals(1, list.size()); assertEquals(new Integer(1), list.first()); assertEquals(node1, list.head()); assertArrayEquals(new Integer[]{1}, list.toArray());
public List<Counter<T>> topK(int k) { List<Counter<T>> topK = new ArrayList<Counter<T>>(k); for (ListNode2<Bucket> bNode = bucketList.head(); bNode != null; bNode = bNode.getPrev()) { Bucket b = bNode.getValue(); for (Counter<T> c : b.counterList) { if (topK.size() == k) { return topK; } topK.add(c); } } return topK; }
public List<Counter<T>> topK(int k) { List<Counter<T>> topK = new ArrayList<>(k); for (ListNode2<Bucket> bNode = bucketList.head(); bNode != null; bNode = bNode.getPrev()) { Bucket b = bNode.getValue(); for (Counter<T> c : b.counterList) { if (topK.size() == k) { return topK; } topK.add(c); } } return topK; }
@Override public List<T> peek(int k) { List<T> topK = new ArrayList<T>(k); for (ListNode2<Bucket> bNode = bucketList.head(); bNode != null; bNode = bNode.getPrev()) { Bucket b = bNode.getValue(); for (Counter<T> c : b.counterList) { if (topK.size() == k) { return topK; } topK.add(c.item); } } return topK; }
@Override public List<T> peek(int k) { List<T> topK = new ArrayList<>(k); for (ListNode2<Bucket> bNode = bucketList.head(); bNode != null; bNode = bNode .getPrev()) { Bucket b = bNode.getValue(); for (Counter<T> c : b.counterList) { if (topK.size() == k) { return topK; } topK.add(c.item); } } return topK; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append('['); for (ListNode2<Bucket> bNode = bucketList.head(); bNode != null; bNode = bNode.getPrev()) { Bucket b = bNode.getValue(); sb.append('{'); sb.append(b.count); sb.append(":["); for (Counter<T> c : b.counterList) { sb.append('{'); sb.append(c.item); sb.append(':'); sb.append(c.error); sb.append("},"); } if (b.counterList.size() > 0) { sb.deleteCharAt(sb.length() - 1); } sb.append("]},"); } if (bucketList.size() > 0) { sb.deleteCharAt(sb.length() - 1); } sb.append(']'); return sb.toString(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append('['); for (ListNode2<Bucket> bNode = bucketList.head(); bNode != null; bNode = bNode.getPrev()) { Bucket b = bNode.getValue(); sb.append('{'); sb.append(b.count); sb.append(":["); for (Counter<T> c : b.counterList) { sb.append('{'); sb.append(c.item); sb.append(':'); sb.append(c.error); sb.append("},"); } if (b.counterList.size() > 0) { sb.deleteCharAt(sb.length() - 1); } sb.append("]},"); } if (bucketList.size() > 0) { sb.deleteCharAt(sb.length() - 1); } sb.append(']'); return sb.toString(); }