sudhakar_koundinya
asked on
I should have efficient Collections method
This is my method
private java.util.List[] getURLList(java.util.List list) {
Hashtable ht = new Hashtable();
for (int i = 0; i < list.size(); i++) {
String url = list.get(i).toString();
String array[] = url.split("/");
String domain = array[0];
if (array[0].toLowerCase().st artsWith(" http")) {
domain = array[2];
domain = domain + array[4];
}
else {
domain = domain + array[2];
}
ArrayList sublist = (ArrayList) ht.get(domain);
if (sublist == null) {
sublist = new ArrayList();
}
sublist.add(url);
ht.put(domain, sublist);
}
return (List[]) Collections.list(ht.elemen ts()).toAr ray(new ArrayList[0]);
}
from : https://www.experts-exchange.com/questions/21102101/Help-needed-to-make-this-collections-method-much-efficient.html (Answered by CEHJ)
private static java.util.List[] getUrlList(java.util.List list) {
Hashtable hostToUrls = new Hashtable();
try {
for (int i = 0; i < list.size(); i++) {
URL url = new URL((String) list.get(i));
String hostKey = url.getHost();
String protocol=url.getProtocol() ;
// System.err.println(url.get Protocol() );
// Could be a Set if no duplicates required
ArrayList urlsForHost = (ArrayList)hostToUrls.get( protocol+h ostKey);
if (urlsForHost == null) {
urlsForHost = new ArrayList();
urlsForHost.add(url);
hostToUrls.put(protocol+ho stKey, urlsForHost);
}
else {
urlsForHost.add(url);
}
}
}
catch (MalformedURLException e) {
return null;
}
int numberOfLists = hostToUrls.size();
return (java.util.List[]) Collections.list(hostToUrl s.elements ()).toArra y(new ArrayList[numberOfLists]);
}
Hello all,
This question was asked already by me. But I am looking at much more efficient method. The reason is although CEHJ's method is efficient, it is not giving correct sets. Actually my method gives the correct sets. But it is less efficient method than CEHJ's
So I need the correct results and should increase the performance of method than CEHJ's and my method.
for your testing,
Here is the test sample
http://www.geocities.com/sudhakar_koundinya/testsample.html (If u place the problem - copy the URL in location bar and press enter. Then it works :-D )
Actually what I am thinking is
return (List[]) Collections.list(ht.elemen ts()).toAr ray(new ArrayList[0]); this line is giving poor performance results.
Any ideas are welcome from you guys
thank you
Sudhakar
private java.util.List[] getURLList(java.util.List list) {
Hashtable ht = new Hashtable();
for (int i = 0; i < list.size(); i++) {
String url = list.get(i).toString();
String array[] = url.split("/");
String domain = array[0];
if (array[0].toLowerCase().st
domain = array[2];
domain = domain + array[4];
}
else {
domain = domain + array[2];
}
ArrayList sublist = (ArrayList) ht.get(domain);
if (sublist == null) {
sublist = new ArrayList();
}
sublist.add(url);
ht.put(domain, sublist);
}
return (List[]) Collections.list(ht.elemen
}
from : https://www.experts-exchange.com/questions/21102101/Help-needed-to-make-this-collections-method-much-efficient.html (Answered by CEHJ)
private static java.util.List[] getUrlList(java.util.List list) {
Hashtable hostToUrls = new Hashtable();
try {
for (int i = 0; i < list.size(); i++) {
URL url = new URL((String) list.get(i));
String hostKey = url.getHost();
String protocol=url.getProtocol()
// System.err.println(url.get
// Could be a Set if no duplicates required
ArrayList urlsForHost = (ArrayList)hostToUrls.get(
if (urlsForHost == null) {
urlsForHost = new ArrayList();
urlsForHost.add(url);
hostToUrls.put(protocol+ho
}
else {
urlsForHost.add(url);
}
}
}
catch (MalformedURLException e) {
return null;
}
int numberOfLists = hostToUrls.size();
return (java.util.List[]) Collections.list(hostToUrl
}
Hello all,
This question was asked already by me. But I am looking at much more efficient method. The reason is although CEHJ's method is efficient, it is not giving correct sets. Actually my method gives the correct sets. But it is less efficient method than CEHJ's
So I need the correct results and should increase the performance of method than CEHJ's and my method.
for your testing,
Here is the test sample
http://www.geocities.com/sudhakar_koundinya/testsample.html (If u place the problem - copy the URL in location bar and press enter. Then it works :-D )
Actually what I am thinking is
return (List[]) Collections.list(ht.elemen
Any ideas are welcome from you guys
thank you
Sudhakar
ASKER
ok cehj,
http://www.geocities.com/sudhakar_koundinya/sudha.html
http://www.geocities.com/sudhakar_koundinya/cehj.html
you can see the difference
thanks
sudhakar
http://www.geocities.com/sudhakar_koundinya/sudha.html
http://www.geocities.com/sudhakar_koundinya/cehj.html
you can see the difference
thanks
sudhakar
ASKER
my code gives three sets where as your's give 2 sets
thanks
sudhakar
thanks
sudhakar
Well yours looks wrong to me ;-) Or at least it's not working in the way i thought the algo was meant to work:
>>
List :0
http://192.12.0.38/exchange/vijay/Inbox/testattachment.EML
List :1
http://192.12.0.38/exchange/Administrator/Deleted Items/TEST Message 0056.EML
>>
AFAIK the unique key is host+protocol (or vice versa). Why then does the same host and protocol in your version (above) appear in different lists?
>>
List :0
http://192.12.0.38/exchange/vijay/Inbox/testattachment.EML
List :1
http://192.12.0.38/exchange/Administrator/Deleted Items/TEST Message 0056.EML
>>
AFAIK the unique key is host+protocol (or vice versa). Why then does the same host and protocol in your version (above) appear in different lists?
ASKER
CEHJ,
keys should be
http://192.12.0.38/exchange/vijay
http://192.12.0.38/exchange/Administrator
some thing like this where as
using ur code, we just have protocol and host
thanks,
sudhakar
keys should be
http://192.12.0.38/exchange/vijay
http://192.12.0.38/exchange/Administrator
some thing like this where as
using ur code, we just have protocol and host
thanks,
sudhakar
ASKER
the key should be protocol+host+user
>>using ur code, we just have protocol and host
But that's what i thought you wanted! Where is the key meant to stop - after the second (account?) directory? And are you separating on protocol too? i.e. should
http://192.12.0.38/exchange/vijay
and
https://192.12.0.38/exchange/vijay
appear in separate lists?
But that's what i thought you wanted! Where is the key meant to stop - after the second (account?) directory? And are you separating on protocol too? i.e. should
http://192.12.0.38/exchange/vijay
and
https://192.12.0.38/exchange/vijay
appear in separate lists?
ASKER
this should be protocol+host+user final key for me
ASKER
CEHJ,
I got an Idea how to speed the result
But just wanted to clarify one thing from you
Initially I have declared some thing like this
Object object[]=new Object[0];
Now dynamically how can we Increase the size of array with out loosing previous results. Which we can do same in c/c++
I got an Idea how to speed the result
But just wanted to clarify one thing from you
Initially I have declared some thing like this
Object object[]=new Object[0];
Now dynamically how can we Increase the size of array with out loosing previous results. Which we can do same in c/c++
> The reason is although CEHJ's method is efficient, it is not giving correct sets.
Then why did you accept it. You should ask for that question to be reopened instead of opening a new question.
Then why did you accept it. You should ask for that question to be reopened instead of opening a new question.
ASKER
>> Then why did you accept it.
I have waited for some time for some other experts inputs. As no one participated, I thought that, I should close the question and then open it as new question
I have waited for some time for some other experts inputs. As no one participated, I thought that, I should close the question and then open it as new question
> I should close the question and then open it as new question
You shouldn't do that.
Either delete the question, and open a new one.
Or ask a new question linking to the old one.
CS can help you with it.
You shouldn't do that.
Either delete the question, and open a new one.
Or ask a new question linking to the old one.
CS can help you with it.
ASKER
OK,
shall I ask the CS people to reopen that question and move this question points to that Link?
Thanks
Sudhakar
shall I ask the CS people to reopen that question and move this question points to that Link?
Thanks
Sudhakar
you can probably delete this one, and ask a new 20 point q linking to the reopened question.
>>I have waited for some time for some other experts inputs
sudhakar - i haven't forgotten you. i've corrected the error but have not posted the code as i haven't optimized it yet. Do you want me to post it anyway?
sudhakar - i haven't forgotten you. i've corrected the error but have not posted the code as i haven't optimized it yet. Do you want me to post it anyway?
ASKER
sure
ASKER
But plz post that in previous link. So that objects also will participate in that thread
Thanks
Sudhakar
Thanks
Sudhakar
ASKER
The reason is I have already asked the CS people to reopen the previous question
Can you remind me which one it was? - i'm losing track ;-)
Also, could you post a link to some of the most representative data? - it will help with testing ;-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello objects, are you there??
What do you mean ? ;-)