This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Something about sizeof(char)


On Mon, 2004-06-21 at 19:09, Paolo Carlini wrote:
> Dhruv Matani wrote:
> 
> >I'm not too good at figuring out whether code is portable or not, so I'm
> >not rally sure that this would be acceptable, so I'd like to hear from
> >the experts.
> >  
> >
> >>ffirst_of(string const& src, string const& f)
> >>{
> >>#if __CHAR_BIT__ <= 8
> >>  char table[1 << __CHAR_BIT__] = { 0 };
> >>  string::size_type sz = f.size();
> >>  string::size_type i;
> >>
> >>  for (i = 0; i < sz; ++i)
> >>    table[(unsigned int)f[i]] = 1;
> >>    
> >>
> A general problem I can easily see with this kind of idea is that its 
> profitability
> depends way too much on the size of f: what happens when f is big and src is
> small? We should work on this issue, first.

Yes, correct. What we could do is have some sort of threshold for the
string f. So, if sizeof(f) - sizeof(src) > threshold1 && sizeof(f) >
threshold2, then use the traditional algorithm, else use the
table-algorithm.

> 
> Paolo.
-- 
        -Dhruv Matani.
http://www.geocities.com/dhruvbird/

The price of freedom is responsibility, but it's a bargain, because
freedom is priceless. ~ Hugh Downs


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]