My requirement is to inject rows into the array that are not in the array. I also need to maintain fixed indexes, as this array will be used with a different data structure with a one-to-one relationship with each index. I am currently using the ArrayList class and checking with the indexOf () method to check if it exists first, if not, add it to the list using the add () method with one argument. I am not familiar with classes in java and therefore I canβt understand how I can implement it using HashMap or something else (trie or else), which will speed up the loading process.
Does sequential search indexOf () in ArrayList ? My task is to reduce processing time when loading words into an array without inserting duplicates and maintain a fixed index of elements. If the word under test is already in the array, then the index into which it is already inserted is required, since this index is necessary for indexing into some other structure and performing some processing. Any suggestions for improving this process?
UPDATE
There is an array, I have some documents, from where I need to scan every word and find unique words in the documents. But also I need to count the number of duplicates. In other words, I need to calculate the number of frequencies of unique terms found in documents. I support ArrayList<Integer[]> time frequency (number of terms x number of documents). I extract one word and then check if it is in the list of words using the indexOf () method. If it is not in the list of words, I insert the word in the list and select a new line in the 2d array ( Array<Integer[]> ), and then set the counter of the term element in the 2d array to 1. If the word is already in the word array, then I I use the index of the word in the array for indexing in the matrix row Array<Integer[]> and use the current number of the processed document to access the cell and increase the score.
My question is to reduce the processing time of indexOf () for every word that I am currently using. I need to get the index of a word in an array of words, if it is already there, and if it is not there, I need to insert it into the array dynamically.
Code example
import java.io.*; import java.util.ArrayList; import static java.lang.Math.log; class DocumentRepresentation { private String dirPath; private ArrayList<String> fileNameVector; private ArrayList<String> termVector; private ArrayList<Integer[]> tf; private Integer df[]; private Double idf[]; private Double tfIdf[][]; DocumentRepresentation (String dirPath) { this.dirPath = dirPath; fileNameVector = new ArrayList<String> (); termVector = new ArrayList<String> (); tf = new ArrayList<Integer[]> (); } public int start () { File fileDir = new File (dirPath); int fileCount = 0; int index; if (fileDir.isDirectory () == false) { return -1; } File fileList[] = fileDir.listFiles (); for (int i=0; i<fileList.length; i++) { if (fileList[i].isFile () == true) { fileNameVector.add (fileList[i].getName ());
Note: code is disabled to focus on the issue.
source share