Re: map/multimap/wildcards
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Thu, 8 Jun 2006 14:59:56 -0400
Igor Tandetnik <itandetnik@xxxxxxxx> wrote:
Jason S <jmsachs@xxxxxxxxx> wrote:
Argh. I keep an index (presently implemented as map<char *, long,
pchar_cmp> where pchar_cmp calls strcmp() appropriately; the "char
*"s are stored elsewhere & will exist as long as the map does) for
character string lookup in sorted order. Works great for exact
matches. Now I need an alternate accessor (need to keep the
exact-match lookup around) to use it for string completion, e.g. find
all the entries that start with an arbitrary string.
Use lower_bound to find the first string that starts with the prefix
(if any). Walk from this point on until you find the first string
that does not start with the prefix.
Alternatively, call lower_bound with the prefix, and upper_bound with
prefix+'\0xFF' (that is a string consisting of your prefix and an
extra character '\0xFF' at the end). This will give you the range.
'\0xFF' should be '\xFF', of course.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- References:
- map/multimap/wildcards
- From: Jason S
- Re: map/multimap/wildcards
- From: Igor Tandetnik
- map/multimap/wildcards
- Prev by Date: Re: map/multimap/wildcards
- Next by Date: Re: map/multimap/wildcards
- Previous by thread: Re: map/multimap/wildcards
- Next by thread: Re: map/multimap/wildcards
- Index(es):
Relevant Pages
|