Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #8033

Re: string case clauses

Date 2011-09-14 12:36 -0700
From Patricia Shanahan <pats@acm.org>
Newsgroups comp.lang.java.programmer
Subject Re: string case clauses
References <2oop671bkkrj4kg2cn59nq46ns1qg0n0qe@4ax.com> <j4ipg0$or7$1@dont-email.me> <rmdq67llms44km62upf66g787nnlai0ulc@4ax.com> <poWdnWdt5NBv6_DTnZ2dnUVZ_gydnZ2d@posted.palinacquisition> <16u177dof4qdro9a9pbps9ts7gce8gvuoq@4ax.com>
Message-ID <j7GdnboERbDWn-zTnZ2dnUVZ_sSdnZ2d@earthlink.com> (permalink)

Show all headers | View raw


On 9/14/2011 12:13 PM, Roedy Green wrote:
> On Sun, 11 Sep 2011 20:05:20 -0700, Peter Duniho
> <NpOeStPeAdM@NnOwSlPiAnMk.com>  wrote, quoted or indirectly quoted
> someone who said :
>
>> Huh?  How so?  It's actually basically the same algorithm a full-on hash
>> table would use.  Specifically: hash value gets you to a very small
>> subset of the possible values (very often just one, as long as the hash
>> code algorithm is good), then linear search on collisions.
>
> Before case strings, there were two JVM instructions for implementing
> an int switch, tableswitch and lookupswitch. The efficient tableswitch
> is a jump table used when the switch values are reasonably dense e.g.
> numbered 0..N. The less efficient lookupswitch is a binary search or
> linear search used when the switch values all over the map.
>
> 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.

Why do you assume it would be inefficient? If the number of cases is
small, a linear search may well be faster than a HashMap lookup. If the
number of cases is large, wouldn't it use a binary search?

However, I don't like switch statements with a lot of cases anyway,
because of unreadability and maintenance issues.

Patricia

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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