🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3688

Re: String value of enum

#3688
From: J. Kanze
Date: Fri, 15 Mar 1996 15:08
36 lines
2624 bytes
In article <4i9cn4$7cf@ns.hcsc.com> bill@amber.ssd.hcsc.com (Bill
Leonard) writes:

|> In article <4i8a38$2qq@engnews1.Eng.Sun.COM>, clamage@Eng.Sun.COM
|> (Steve Clamage) writes:

|> > The more general case of non-contiguous enum values could be handled
|> > by a table of value/string pairs and a lookup function. The standard
|> > "map" class will do it all for you.

|> But using the map class would require initialization at runtime, wouldn't
|> it?  That increases the startup cost of the program.  Using a sorted array
|> of value/string pairs (statically initialized) and a binary search would
|> probably be more efficient.

At start-up, yes.  If the map is large enough for this to make a
difference, however, it's likely that the difference between the O(ln n)
binary search and a O(k) hash table look-up is also significant.

Given that the enum labels are all in the source code, and programmers
being on the whole a lazy group of people, the resulting tables are
typically so small that it really doesn't make a difference, especially
since anytime that the conversion is necessary, output will follow.
(I'm still using a linear search in my implementation, and it has yet to
cause a performance bottleneck.)
-- 
James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils, itudes et rialisations en logiciel orienti objet --
              -- A la recherche d'une activiti dans une region francophone
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Technical Details
Message-ID: <KANZE.96Mar15151356@gabi.gabi-soft.fr>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <4i5sf3$89c@hermes.is.co.za> <Do81tp.H9u@rsvl.unisys.com> <4i8a38$2qq@engnews1.Eng.Sun.COM> <4i9cn4$7cf@ns.hcsc.com>

Show Full Headers
Complete Article Headers
From: kanze@gabi-soft.fr (J. Kanze)
Message-ID: <KANZE.96Mar15151356@gabi.gabi-soft.fr>
X-Original-Date: 15 Mar 1996 14:13:56 GMT
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 15 Mar 96 15:08:14 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: Re: String value of enum
Organization: GABI Software, Sarl.
References: <4i5sf3$89c@hermes.is.co.za> <Do81tp.H9u@rsvl.unisys.com>
 <4i8a38$2qq@engnews1.Eng.Sun.COM> <4i9cn4$7cf@ns.hcsc.com>
In-Reply-To: bill@amber.ssd.hcsc.com's message of 14 Mar 96 16:29:27 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMUmIFeEDnX0m9pzZAQGlxQF/RwugN9s8NOcLWT1XYZD+bqsUlzZ22WTg
 r56zWV4u+5Wmm0ZEBoo76rWON8vgPnPr
 =fnu7