Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #8048
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: string case clauses |
| Date | 2011-09-14 20:05 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <262624c5-d488-4807-b68c-5f5e4dc7a1a2@glegroupsg2000goo.googlegroups.com> (permalink) |
| References | (1 earlier) <j4ipg0$or7$1@dont-email.me> <rmdq67llms44km62upf66g787nnlai0ulc@4ax.com> <poWdnWdt5NBv6_DTnZ2dnUVZ_gydnZ2d@posted.palinacquisition> <16u177dof4qdro9a9pbps9ts7gce8gvuoq@4ax.com> <8MGdnUUsOf7P0-zTnZ2dnUVZ_uWdnZ2d@posted.palinacquisition> |
Peter Duniho wrote: > Roedy Green wrote: >> [...] >> I understood the way string case labels worked posted earlier was to >> use the hashCode as the switch variable, which would necessitate the >> use of the inefficient lookupswitch plus a little kludge to deal with >> hashCode collisions. >> >> In contrast a String case lookup done manually with HashMap does not >> involve any binary search or linear scan. It folds the hashCode to a >> reasonable value and does a table lookup. [...] > > I agree with Patricia's assessment. There is no proof that the current > implementation of an integral switch would be less efficient than a full > hash table implementation, and in fact for relatively few values (as a > switch really ought to be), it's likely to be more efficient. At the > very least, it's difficult to easily get a small hash table without also > having collisions. > > I see no reason to be concerned whatsoever about the performance > implications of the choice of implementation for string case labels in > Java. If and when you have a program where that turns out to be a > bottleneck, then of course you can look at alternatives. I doubt you'll > run into that situation though. And if you do, it's quite likely that > you should have been using a hash table structure for other reasons anyway. These points or similar were made fairly early in this thread by a couple of people. A 'switch' by any other name is still a 'goto'. But at least it's forward only. -- Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar
string case clauses Roedy Green <see_website@mindprod.com.invalid> - 2011-09-11 09:35 -0700
Re: string case clauses Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-09-11 12:00 -0500
Re: string case clauses Roedy Green <see_website@mindprod.com.invalid> - 2011-09-11 15:33 -0700
Re: string case clauses Arne Vajhøj <arne@vajhoej.dk> - 2011-09-11 21:56 -0400
Re: string case clauses Lew <lewbloch@gmail.com> - 2011-09-11 20:54 -0700
Re: string case clauses Arne Vajhøj <arne@vajhoej.dk> - 2011-09-12 18:58 -0400
Re: string case clauses Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-09-11 20:05 -0700
Re: string case clauses Roedy Green <see_website@mindprod.com.invalid> - 2011-09-14 12:13 -0700
Re: string case clauses Patricia Shanahan <pats@acm.org> - 2011-09-14 12:36 -0700
Re: string case clauses Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-09-14 18:01 -0700
Re: string case clauses Lew <lewbloch@gmail.com> - 2011-09-14 20:05 -0700
csiph-web