Re: map/multimap/wildcards
- From: "Jason S" <jmsachs@xxxxxxxxx>
- Date: 8 Jun 2006 13:25:39 -0700
Igor Tandetnik wrote:
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.
I'm confused. How can I define two comparison objects in a multimap?
I need to use the regular strcmp (compare the full length of string 1
to string 2) for inserting objects into the multimap.
I need to use the strncmp(a,b,N) with the match pattern (using the
length of the match pattern) for finding objects in the multimap.
I don't see how I can use both. If I use strncmp then I'll get some
weird sorting pattern depending on what order the elements were
inserted, how long they are, and the order of arguments passed into my
comparison object e.g. compare(a,b) vs (b,a) where a is some element in
the multimap and b is the key I'm trying to check it against.
The easiest thing I can come up with (w/o abandoning map/multimap) is
to do something like this:
struct hack {
char *pstring;
bool is_partial_match;
};
struct less_hack :
public std::binary_function<const hack&, const hack&, bool> {
bool operator()(const hack& h1, const hack& h2) const {
if (h1.is_partial_match)
return strncmp(h1.pstring,h2.pstring,strlen(h1.pstring)) <
0;
if (h2.is_partial_match)
return strncmp(h1.pstring,h2.pstring,strlen(h2.pstring)) <
0;
return strcmp(h1.pstring, h2.pstring) < 0; }
};
}
typedef multimap<hack, long, less_hack> my_hack_map_t;
and then insert stuff into the map using is_partial_match = false,
retrieve stuff using a find key with is_partial_match = true.
.
- Follow-Ups:
- Re: map/multimap/wildcards
- From: Stephen Howe
- Re: map/multimap/wildcards
- From: Igor Tandetnik
- Re: map/multimap/wildcards
- 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
|