// Path: src/main/java/com/asher_stern/crf/utilities/TopK_DateStructure.java
// public class TopK_DateStructure<T>
// {
// 	public TopK_DateStructure(int k)
// 	{
// 		this(k, null);
// 	}
// 	
// 	
// 	@SuppressWarnings("unchecked")
// 	public TopK_DateStructure(int k, Comparator<T> comparator)
// 	{
// 		super();
// 		this.k = k;
// 		this.comparator = comparator;
// 		
// 		this.array_length = k*k + k;
// 		this.storage = (T[]) Array.newInstance(Object.class, array_length);
// 		
// 		if (k<=0) {throw new CrfException("k <= 0");}
// 		
// 		index = 0;
// 	}
// 
// 
// 
// 	/**
// 	 * Insert an item to this data-structure. This item might be discarded later when it is absolutely sure that it is not
// 	 * one of the top-k items that were inserted to this data-structure.
// 	 * @param item
// 	 */
// 	public void insert(T item)
// 	{
// 		storage[index] = item;
// 		++index;
// 		
// 		if (index>array_length) {throw new CrfException("BUG");}
// 		if (index==array_length)
// 		{
// 			sortAndShrink();
// 		}
// 	}
// 	
// 	/**
// 	 * Get the top-k items among all the items that were inserted to this data-structure so far.
// 	 * <B>Note that this method has time complexity of O(k*log(k)).</B>
// 	 * @return
// 	 */
// 	public ArrayList<T> getTopK()
// 	{
// 		if (index>k)
// 		{
// 			sortAndShrink();
// 		}
// 		
// 		ArrayList<T> topKAsList = new ArrayList<T>();
// 		for (int i=0;i<k;++i)
// 		{
// 			topKAsList.add(storage[i]);
// 		}
// 		return topKAsList;
// 	}
// 	
// 	
// 	private void sortAndShrink()
// 	{
// 		if (null==comparator)
// 		{
// 			Arrays.sort(storage, 0, index, Collections.reverseOrder());
// 		}
// 		else
// 		{
// 			Arrays.sort(storage, 0, index, Collections.reverseOrder(comparator));
// 		}
// 		
// 		index = k;
// 	}
// 
// 	private final int k;
// 	private final int array_length;
// 	private final T[] storage;
// 	
// 	private int index = 0; // the index of the next item to insert
// 	private Comparator<T> comparator = null;
// }


import java.util.List;
import com.asher_stern.crf.utilities.TopK_DateStructure;
package com.asher_stern.crf.smalltests;



/**
 * 
 * @author Asher Stern
 * Date: Nov 19, 2014
 *
 */
public class DemoTopK_DS
{

	public static void main(String[] args)
	{
		try
		{
			new DemoTopK_DS().go();
		}
		catch(Throwable t)
		{
			t.printStackTrace(System.out);
		}
	}
	
	public void go()
	{
		int k = 3;
// Path: src/main/java/com/asher_stern/crf/utilities/TopK_DateStructure.java
// public class TopK_DateStructure<T>
// {
// 	public TopK_DateStructure(int k)
// 	{
// 		this(k, null);
// 	}
// 	
// 	
// 	@SuppressWarnings("unchecked")
// 	public TopK_DateStructure(int k, Comparator<T> comparator)
// 	{
// 		super();
// 		this.k = k;
// 		this.comparator = comparator;
// 		
// 		this.array_length = k*k + k;
// 		this.storage = (T[]) Array.newInstance(Object.class, array_length);
// 		
// 		if (k<=0) {throw new CrfException("k <= 0");}
// 		
// 		index = 0;
// 	}
// 
// 
// 
// 	/**
// 	 * Insert an item to this data-structure. This item might be discarded later when it is absolutely sure that it is not
// 	 * one of the top-k items that were inserted to this data-structure.
// 	 * @param item
// 	 */
// 	public void insert(T item)
// 	{
// 		storage[index] = item;
// 		++index;
// 		
// 		if (index>array_length) {throw new CrfException("BUG");}
// 		if (index==array_length)
// 		{
// 			sortAndShrink();
// 		}
// 	}
// 	
// 	/**
// 	 * Get the top-k items among all the items that were inserted to this data-structure so far.
// 	 * <B>Note that this method has time complexity of O(k*log(k)).</B>
// 	 * @return
// 	 */
// 	public ArrayList<T> getTopK()
// 	{
// 		if (index>k)
// 		{
// 			sortAndShrink();
// 		}
// 		
// 		ArrayList<T> topKAsList = new ArrayList<T>();
// 		for (int i=0;i<k;++i)
// 		{
// 			topKAsList.add(storage[i]);
// 		}
// 		return topKAsList;
// 	}
// 	
// 	
// 	private void sortAndShrink()
// 	{
// 		if (null==comparator)
// 		{
// 			Arrays.sort(storage, 0, index, Collections.reverseOrder());
// 		}
// 		else
// 		{
// 			Arrays.sort(storage, 0, index, Collections.reverseOrder(comparator));
// 		}
// 		
// 		index = k;
// 	}
// 
// 	private final int k;
// 	private final int array_length;
// 	private final T[] storage;
// 	
// 	private int index = 0; // the index of the next item to insert
// 	private Comparator<T> comparator = null;
// }


// Path: src/main/java/com/asher_stern/crf/smalltests/DemoTopK_DS.java
import java.util.List;
import com.asher_stern.crf.utilities.TopK_DateStructure;

package com.asher_stern.crf.smalltests;



/**
 * 
 * @author Asher Stern
 * Date: Nov 19, 2014
 *
 */
public class DemoTopK_DS
{

	public static void main(String[] args)
	{
		try
		{
			new DemoTopK_DS().go();
		}
		catch(Throwable t)
		{
			t.printStackTrace(System.out);
		}
	}
	
	public void go()
	{
		int k = 3;
		TopK_DateStructure<Integer> ds = new TopK_DateStructure<Integer>(k);