Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #8789
| Date | 2011-08-13 15:26 +0100 |
|---|---|
| From | Leigh Johnston <leigh@i42.co.uk> |
| Newsgroups | comp.lang.c++ |
| Subject | Re: maximum cases in a switch ? |
| References | (3 earlier) <4e424aff$0$6580$9b4e6d93@newsspool3.arcor-online.net> <j1uanm$3qf$1@dont-email.me> <j209kt$ijs$1@adenine.netfront.net> <3uydnS2bVrh7LtjTnZ2dnUVZ7vGjnZ2d@giganews.com> <j25vnh$307c$1@adenine.netfront.net> |
| Message-ID | <AO2dna1DbZ4vFNvTnZ2dnUVZ8hGdnZ2d@giganews.com> (permalink) |
On 13/08/2011 14:54, Paul wrote:
>
> "Leigh Johnston" <leigh@i42.co.uk> wrote in message
> news:3uydnS2bVrh7LtjTnZ2dnUVZ7vGjnZ2d@giganews.com...
>> On 11/08/2011 11:07, Paul wrote:
>>>
>>> "Lynn McGuire" <lmc@winsim.com> wrote in message
>>> news:j1uanm$3qf$1@dont-email.me...
>>>> On 8/10/2011 4:10 AM, Marcel Müller wrote:
>>>>> Lynn McGuire wrote:
>>>>>> Incredibly easy. Here is some of the method:
>>>>>>
>>>>>> DataDescriptor aDD_GEN_CALVAPPRE (GEN_CALVAPPRE, "CALVAPPRE",
>>>>>> "Calculate Vapor Pressure for all streams", true, false, false,
>>>>>> SYM_Enumerated, nil, nil, nil, nil, nil, SYM_BOOLEAN,
>>>>>> SYM_DGenInit, 420, nil, nil);
>>>>>>
>>>>>> DataDescriptor * GenGroup::descriptor (int aSymbol, int version)
>>>>>> {
>>>>>> switch (aSymbol)
>>>>>> {
>>>>>> case GEN_CALVAPPRE:
>>>>>> return & aDD_GEN_CALVAPPRE;
>>>>>> case GEN_CALSONVEL:
>>>>>> return & aDD_GEN_CALSONVEL;
>>>>>> case GEN_ONLYWRITESTREAMBOXONFIRSTSHEET:
>>>>>> return & aDD_GEN_ONLYWRITESTREAMBOXONFIRSTSHEET;
>>>>>> ...
>>>>>> }
>>>>>>
>>>>>> // default return
>>>>>> return NULL;
>>>>>> }
>>>>>
>>>>> I would strongly recommend a meta data table.
>>>>>
>>>>> static const DataDescriptor DispatchTable[] =
>>>>> { DataDescriptor(GEN_CALVAPPRE, "CALVAPPRE",
>>>>> "Calculate Vapor Pressure for all streams", true, false, false,
>>>>> SYM_Enumerated, nil, nil, nil, nil, nil, SYM_BOOLEAN,
>>>>> SYM_DGenInit, 420, nil, nil),
>>>>> DataDescriptor(GEN_CALSONVEL, ...),
>>>>> ...
>>>>> };
>>>>>
>>>>> If the DataDescriptors are ordered by the key aSymbol, you could use
>>>>> a binary search to locate a DataDescriptor in the table.
>>>>>
>>>>> Alternatively class DataDescriptor could hold a static repository of
>>>>> type std::map<int,DataDescriptor*> with all it's instances. The
>>>>> constructor of DataDescriptor could register it's own instance in the
>>>>> repository. Then the method GenGroup::descriptor reduces to a
>>>>> hash lookup in the repository. No more than a dozen code lines
>>>>> instead of some thousands in the switch case. And the advantage is
>>>>> that you can keep the code for the DataDescriptor definitions without
>>>>> changes. You only have to delete the large switch.
>>>>>
>>>>>> This is a 470,000 line C++ Win32 user interface for a highly
>>>>>> successful calculation engine.
>>>>>
>>>>> Maybe, but keep in mind that compilers are not well tested with this
>>>>> kind of code. I triggered internal compiler errors with too
>>>>> large functions from time to time (large window procedures).
>>>>>
>>>>>> This code is bulletproof and
>>>>>> very extensible.
>>>>>
>>>>> The two above solutions too.
>>>>>
>>>>>
>>>>> Marcel
>>>>
>>>> This solution is order dependent. Mine is not. Not that
>>>> I'm looking for a new solution.
>>>>
>>> Best to keep it simple it seems you are already using the best solution.
>>>
>>> 525 switch cases seem alot but how long does this take to compute,
>>> assuming the very last case is the one that is true? Probably not very
>>> long, maybe 3 instructions per conditional test, so it might be around
>>> 1500 clock cycles or something.
>>>
>>
>> Only if the compiler was as naive as you (for a clue you should learn
>> about jump tables).
>>
>
> From behind which rock have you crawled?
What an amazingly original insult. Perhaps you think I was being
disrespectful? Well you will receive as much respect as you deserve and
in this forum your past record dictates how much respect you deserve.
Your past record is awful.
HTH.
/Leigh
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
maximum cases in a switch ? Lynn McGuire <lmc@winsim.com> - 2011-08-09 11:03 -0500
Re: maximum cases in a switch ? LR <lruss@superlink.net> - 2011-08-09 12:27 -0400
Re: maximum cases in a switch ? Lynn McGuire <lmc@winsim.com> - 2011-08-09 12:23 -0500
Re: maximum cases in a switch ? Joe Greer <jgreer@doubletake.com> - 2011-08-10 12:45 +0000
Re: maximum cases in a switch ? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-10 09:09 -0400
Re: maximum cases in a switch ? Joe Greer <jgreer@doubletake.com> - 2011-08-11 12:49 +0000
Re: maximum cases in a switch ? Lynn McGuire <lmc@winsim.com> - 2011-08-11 10:48 -0500
Re: maximum cases in a switch ? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-08-11 18:26 +0200
Re: maximum cases in a switch ? Lynn McGuire <lmc@winsim.com> - 2011-08-11 11:45 -0500
Re: maximum cases in a switch ? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-08-11 20:06 +0200
Re: maximum cases in a switch ? Lynn McGuire <lmc@winsim.com> - 2011-08-11 14:47 -0500
Re: maximum cases in a switch ? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-08-11 22:32 +0200
Re: maximum cases in a switch ? gwowen <gwowen@gmail.com> - 2011-08-12 06:00 -0700
Re: maximum cases in a switch ? Lynn McGuire <lmc@winsim.com> - 2011-08-12 10:49 -0500
Re: maximum cases in a switch ? Joe Greer <jgreer@doubletake.com> - 2011-08-12 13:46 +0000
Re: maximum cases in a switch ? Lynn McGuire <lmc@winsim.com> - 2011-08-12 10:58 -0500
Re: maximum cases in a switch ? Joe Greer <jgreer@doubletake.com> - 2011-08-12 20:22 +0000
Re: maximum cases in a switch ? Lynn McGuire <lmc@winsim.com> - 2011-08-12 15:57 -0500
Re: maximum cases in a switch ? Leo Equinox Gaspard <ekinox1995@gmail.com> - 2011-08-13 20:58 +0200
Re: maximum cases in a switch ? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-13 18:16 -0400
Re: maximum cases in a switch ? Leo Equinox Gaspard <ekinox1995@gmail.com> - 2011-08-16 07:55 +0200
Re: maximum cases in a switch ? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-16 09:04 -0400
Re: maximum cases in a switch ? Leo Equinox Gaspard <ekinox1995@gmail.com> - 2011-08-17 00:11 +0200
Re: maximum cases in a switch ? Ian Collins <ian-news@hotmail.com> - 2011-08-17 10:24 +1200
Re: maximum cases in a switch ? Leo Equinox Gaspard <ekinox1995@gmail.com> - 2011-08-17 01:33 +0200
Re: maximum cases in a switch ? Leo Equinox Gaspard <ekinox1995@gmail.com> - 2011-08-17 00:18 +0200
Re: maximum cases in a switch ? Ian Collins <ian-news@hotmail.com> - 2011-08-17 10:29 +1200
Re: maximum cases in a switch ? Leo Equinox Gaspard <ekinox1995@gmail.com> - 2011-08-17 01:37 +0200
Re: maximum cases in a switch ? Ian Collins <ian-news@hotmail.com> - 2011-08-17 12:02 +1200
Re: maximum cases in a switch ? Juha Nieminen <nospam@thanks.invalid> - 2011-08-09 16:38 +0000
Re: maximum cases in a switch ? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-09 15:42 -0400
Re: maximum cases in a switch ? Lynn McGuire <lmc@winsim.com> - 2011-08-09 15:39 -0500
Re: maximum cases in a switch ? Leo Equinox Gaspard <ekinox1995@gmail.com> - 2011-08-09 23:39 +0200
Re: maximum cases in a switch ? Lynn McGuire <lmc@winsim.com> - 2011-08-09 17:18 -0500
Re: maximum cases in a switch ? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-09 20:06 -0400
Re: maximum cases in a switch ? Juha Nieminen <nospam@thanks.invalid> - 2011-08-10 06:54 +0000
Re: maximum cases in a switch ? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-08-10 12:20 +0000
Re: maximum cases in a switch ? Lynn McGuire <lmc@winsim.com> - 2011-08-10 11:34 -0500
Re: maximum cases in a switch ? Paul Brettschneider <paul.brettschneider@yahoo.fr> - 2011-08-10 20:34 +0200
Re: maximum cases in a switch ? Paul Brettschneider <paul.brettschneider@yahoo.fr> - 2011-08-10 21:06 +0200
Re: maximum cases in a switch ? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-08-11 21:00 +0000
Re: maximum cases in a switch ? Marcel Müller <news.5.maazl@spamgourmet.com> - 2011-08-10 11:10 +0200
Re: maximum cases in a switch ? Juha Nieminen <nospam@thanks.invalid> - 2011-08-10 10:40 +0000
Re: maximum cases in a switch ? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-10 09:02 -0400
Re: maximum cases in a switch ? Juha Nieminen <nospam@thanks.invalid> - 2011-08-11 08:05 +0000
Re: maximum cases in a switch ? Marcel Müller <news.5.maazl@spamgourmet.com> - 2011-08-10 21:17 +0200
Re: maximum cases in a switch ? Lynn McGuire <lmc@winsim.com> - 2011-08-10 11:12 -0500
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-11 11:07 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-13 00:14 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-13 14:54 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-13 15:26 +0100
Re: maximum cases in a switch ? Juha Nieminen <nospam@thanks.invalid> - 2011-08-14 18:14 +0000
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-15 01:09 +0100
Re: maximum cases in a switch ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-08-15 02:15 -0700
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-15 12:18 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-15 13:22 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-15 13:38 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-15 14:06 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-15 16:05 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-15 16:20 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-15 20:24 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-15 22:09 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-15 22:19 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-16 03:10 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-16 13:08 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-16 14:01 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-16 14:10 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-16 03:07 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-16 13:05 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-16 13:57 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-16 14:07 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-16 19:29 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-16 19:35 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-17 00:01 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-17 00:11 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-17 01:23 +0100
Re: maximum cases in a switch ? Juha Nieminen <nospam@thanks.invalid> - 2011-08-15 13:32 +0000
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-15 15:20 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-15 15:33 +0100
Re: maximum cases in a switch ? Juha Nieminen <nospam@thanks.invalid> - 2011-08-16 07:34 +0000
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-16 13:49 +0100
Re: maximum cases in a switch ? Juha Nieminen <nospam@thanks.invalid> - 2011-08-16 15:02 +0000
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-16 16:07 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-16 19:50 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-16 19:57 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-17 00:12 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-16 19:34 +0100
Re: maximum cases in a switch ? Juha Nieminen <nospam@thanks.invalid> - 2011-08-17 12:55 +0000
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-17 14:32 +0100
Re: maximum cases in a switch ? Juha Nieminen <nospam@thanks.invalid> - 2011-08-17 20:11 +0000
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-18 11:00 +0100
Re: maximum cases in a switch ? Joshua Maurice <joshuamaurice@gmail.com> - 2011-08-15 15:35 -0700
Re: maximum cases in a switch ? Gareth Owen <gwowen@gmail.com> - 2011-08-17 06:34 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-17 12:23 +0100
Re: maximum cases in a switch ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-08-17 02:01 -0700
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-17 12:29 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-17 14:13 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-17 14:18 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-17 14:43 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-17 15:23 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-17 15:31 +0100
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-17 15:48 +0100
Re: maximum cases in a switch ? Leigh Johnston <leigh@i42.co.uk> - 2011-08-17 15:53 +0100
Re: maximum cases in a switch ? SG <s.gesemann@gmail.com> - 2011-08-17 07:54 -0700
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-17 20:40 +0100
Re: maximum cases in a switch ? Larry Evans <cppljevans@suddenlink.net> - 2011-08-17 10:54 -0500
Re: maximum cases in a switch ? Robert Wessel <robertwessel2@yahoo.com> - 2011-08-17 12:44 -0500
jump table vs. vector of function pointers(was Re: maximum cases in a switch ? Larry Evans <cppljevans@suddenlink.net> - 2011-08-17 15:18 -0500
Re: jump table vs. vector of function pointers(was Re: maximum cases in a switch ? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-08-17 22:48 +0200
Re: jump table vs. vector of function pointers(was Re: maximum cases in a switch ? Larry Evans <cppljevans@suddenlink.net> - 2011-08-17 16:49 -0500
Re: maximum cases in a switch ? Thomas David Rivers <rivers@dignus.com> - 2011-08-17 13:50 -0400
Re: maximum cases in a switch ? "Paul" <pchristor@yahoo.co.uk> - 2011-08-17 22:04 +0100
Re: maximum cases in a switch ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-08-22 03:23 -0700
Re: maximum cases in a switch ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-08-12 05:51 -0700
Re: maximum cases in a switch ? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-13 08:45 -0400
Re: maximum cases in a switch ? James Kanze <james.kanze@gmail.com> - 2011-08-21 16:55 -0700
Re: maximum cases in a switch ? Robert Wessel <robertwessel2@yahoo.com> - 2011-08-21 23:22 -0500
Re: maximum cases in a switch ? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-22 08:14 -0400
Re: maximum cases in a switch ? James Kanze <james.kanze@gmail.com> - 2011-08-22 10:56 -0700
csiph-web