@SuppressWarnings("unchecked")
    private boolean buildInvertedIndex(Dataset ds)
    {
    	ArrayList<Posting>[] list = new ArrayList[this.V];
        for (int k=0; k<this.V; ++k) {
        	list[k] = new ArrayList<Posting>();
        }
        	
        for (int m = 0; m < this.M; m++)
        {
        	Data d = ds.getDataAt(m);
         	for (int position = 0; position < d.size(); position++)
         	{
        		int w = d.getFeatureAt(position).dim;
         		// add posting
         		list[w].add(new Posting(m, position));
        	}
        }
        // convert to array
        this.invertedIndex = new Posting[this.V][];
        for (int w = 0; w < this.V; w++)
        {
        	this.invertedIndex[w] = list[w].toArray(new Posting[0]);
        }
        return true;
    }