Android Open Source - WordOfTheDay Trie Node Hashmap Experiment Tmp






From Project

Back to project page WordOfTheDay.

License

The source code is released under:

MIT License

If you think the Android project WordOfTheDay listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.aferla.wotd.dictionary;
// w  ww. jav a  2  s  .  c  om
import com.google.caliper.BeforeExperiment;
import com.google.caliper.Benchmark;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by aferla on 21/04/2014.
 */
public final class TrieNodeHashmapExperimentTmp {

    List<String> words;
    int wordsSize;
    DictionaryTrie hashTrie;
    DictionaryTrie treeTrie;

    @BeforeExperiment
    public void setUp (){

        try{
            words = loadWords();
        }
        catch (IOException e){
            throw new IllegalArgumentException("No Source File");
        }

        wordsSize = words.size();

        hashTrie = new DictionaryTrie(true);
        treeTrie = new DictionaryTrie(false);
        for (String word : words){
            if (!words.isEmpty()){
                hashTrie.addWord(word);
                treeTrie.addWord(word);
            }

        }

    }

    @Benchmark
    public long treeMapImplementations (int reps){
        long rand = 0l;

        for (int i =0; i < reps; i++){
            String wordToFind = words.get((int)(Math.random() * wordsSize));
            List<String> ret = hashTrie.findByPrefix(wordToFind);
            rand = ret.size();
        }

        return rand;
    }


    @Benchmark
    public long linkedListMapImplementations (int reps){
        long rand = 0l;

        for (int i =0; i < reps; i++){
            String wordToFind = words.get((int)(Math.random() * wordsSize));
            List<String> ret = treeTrie.findByPrefix(wordToFind);
            rand = ret.size();
        }

        return rand;
    }


    private List<String> loadWords () throws IOException{

        List<String> retList = new ArrayList<>();

        try(BufferedReader bReader = new BufferedReader(new FileReader("src/caliper/resources/words.txt"))){
            String buff = "";
            while ((buff = bReader.readLine()) != null) {
                retList.add(buff);
            }
        }

        return words;
    }
}




Java Source Code List

com.adamf.wotd.WotdMainActivity.java
com.aferla.wotd.dictionary.DictionaryTrie.java
com.aferla.wotd.dictionary.TrieNodeHashmapExperimentTmp.java