want to know the index of ArrayList during BinarySearch
-
Hi all, I am trying to develop a text mining engine and in it i need to work on large number of files...and deal with lots of words... i ve made a word class which has following variables
public string term;
public int df;
public ArrayList tf = new ArrayList();
public ArrayList docID= new ArrayList();
public static int count;here term is the variable wich contains the actual value of the word. now when user queries for a word i need to search all these terms and find out whether the term user wants exists or not.... i ve this word class sorted w.r.t the "term" variable so it means that i can apply binary search for finding the user query.....i m doing this by adding all the term variables of the class in an arraylist and then applying binary search over it....but the problem is that i need to know the index of the arraylist where the user's queried term exists.....and i dont know the way to find out the index :( i ve added the sample chunk of code here.....anyone plzz help
//adding all the term variables of Terminology class to the allTerms ArrayList.......
for(int i = 0; i < Terminology .count; i ++ )
{
allTerms.Add(word[i].term);
}//queryList is the ArrayList that contains the pharase queried by the user in the form of //one string at one index
for(int j = 0; j < queryList.Count; j ++)
{
if(allTerms.BinarySearch(queryList[j]) >= 0)
{
need to know the index of allTerms ArrayList.
}
}looking forward for help Regards,
-
Hi all, I am trying to develop a text mining engine and in it i need to work on large number of files...and deal with lots of words... i ve made a word class which has following variables
public string term;
public int df;
public ArrayList tf = new ArrayList();
public ArrayList docID= new ArrayList();
public static int count;here term is the variable wich contains the actual value of the word. now when user queries for a word i need to search all these terms and find out whether the term user wants exists or not.... i ve this word class sorted w.r.t the "term" variable so it means that i can apply binary search for finding the user query.....i m doing this by adding all the term variables of the class in an arraylist and then applying binary search over it....but the problem is that i need to know the index of the arraylist where the user's queried term exists.....and i dont know the way to find out the index :( i ve added the sample chunk of code here.....anyone plzz help
//adding all the term variables of Terminology class to the allTerms ArrayList.......
for(int i = 0; i < Terminology .count; i ++ )
{
allTerms.Add(word[i].term);
}//queryList is the ArrayList that contains the pharase queried by the user in the form of //one string at one index
for(int j = 0; j < queryList.Count; j ++)
{
if(allTerms.BinarySearch(queryList[j]) >= 0)
{
need to know the index of allTerms ArrayList.
}
}looking forward for help Regards,
Ehh, BinarySearch returns the index. If it just indicated if the item was present or not it would have returned a bool. It is also worth noticing that in case the item is not found, the return value indicates the position the item should have been at if it was present (useful for inserting in the list after it is sorted). All of this is in the MSDN documentation.
-
Ehh, BinarySearch returns the index. If it just indicated if the item was present or not it would have returned a bool. It is also worth noticing that in case the item is not found, the return value indicates the position the item should have been at if it was present (useful for inserting in the list after it is sorted). All of this is in the MSDN documentation.
i really thought that it just returns a bool value....now i understand a little bit....but it wud b really helpful if u illustrate it with a little example thxx in advance regards,
-
i really thought that it just returns a bool value....now i understand a little bit....but it wud b really helpful if u illustrate it with a little example thxx in advance regards,