lundi 27 juillet 2015

Getting random lines from Trove (TObjectIntHashMap)?

Is there a way to get random lines from a Trove (TObjectIntHashMap)? I'm using Random to test how fast a Trove can seek/load 10,000 lines. Specifically, I'd like to pass in a random integer and have the Trove seek/load that line. I've tried using the get() method, but it requires that I pass a string rather than a random int. I've also considered using keys() to return an array and reading from that array, but that would defeat the purpose as I wouldn't be reading directly from the Trove. Here's my code:

import java.io.IOException;
import java.util.List;
import java.util.Random;

import com.comScore.TokenizerTests.Methods.TokenizerUtilities;

import gnu.trove.TObjectIntHashMap;

public class Trove {

    public static TObjectIntHashMap<String> lines = new TObjectIntHashMap<String>();

    public static void TroveMethod(List<String> fileInArrayList)
            throws IOException {
        TObjectIntHashMap<String> lines = readToTrove(fileInArrayList);
        TokenizerUtilities.writeOutTrove(lines);
    }

    public static TObjectIntHashMap<String> readToTrove(
            List<String> fileInArrayList) {

        int lineCount = 0;

        for (int i = 0; i < fileInArrayList.size(); i++) {

            lines.adjustOrPutValue(fileInArrayList.get(i), 1, 1);
            lineCount++;
        }

        TokenizerUtilities.setUrlInput(lineCount);
        return lines;
    }

    public static void loadRandomMapEntries() {
        Random rnd = new Random(lines.size());

        int loadCount = 10000;

        for (int i = 0; i < loadCount; i++) {
            lines.get(rnd);
        }

        TokenizerUtilities.setLoadCount(loadCount);
    }
}

The method in question is loadRandomMapEntries(), specifically the for-loop. Any help is appreciated. Thanks!




Aucun commentaire:

Enregistrer un commentaire