473,466 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

STL map - Can I find() on a subset of key

Hi All,

I am using a stl::map and my key is a structure which looks like

struct key
{
int id;
char* name;
};

struct data
{..
....
};

typedef std::map<key*,data*,compare> table;
//compare is defined too

Most of the times, I require a find(key*) and that works fine. But on a
few occasions I need to do find(name)[purpose is to check if there is
atleast one entry with that name]. This fails as my library [windriver]
seems to be creating only find(const key*) and find(const key*) const !

Is there any roundabout way or should I do a brute checking (linear
check) ?

Thanks for your time,

Shireesh

Jul 23 '05 #1
2 4316
> I am using a stl::map and my key is a structure which looks like

struct key
{
int id;
char* name;
};

struct data

typedef std::map<key*,data*,compare> table;
//compare is defined too

Most of the times, I require a find(key*) and that works fine. But on a
few occasions I need to do find(name)[purpose is to check if there is
atleast one entry with that name]. This fails as my library [windriver]
seems to be creating only find(const key*) and find(const key*) const !


You can only search a map efficiently with the comparison function it was
defined with. The reason is that map builds an internal structure optimized
for such a search. If you want to search with another criteria, linear
search is the best you can get.

What you might do is to create a second map, such as this:

map<key *, data *, different_compare>

and put the same keys and data there. Then you can search it with different
criteria.

If you only want to check if there is at least one entry with that name (as
you write), you might also use a set for that purpose, because you don't
need access to the data:

set<key *, different_compare>

cheers,
M.
Jul 23 '05 #2
> If you only want to check if there is at least one entry with that name
(as you write), you might also use a set for that purpose, because you
don't need access to the data:

set<key *, different_compare>


Actually it should be multiset, because it seems that you can have more than
one entry with the same name:

multiset<key *, different_compare>

cheers,
M.
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: whamoo | last post by:
Hello, I'm looking for a library like ncurses, but that can be used also on windows in a very simple way... There is some library that do some like curses? Thanks a lot --
15
by: les_ander | last post by:
Hi, I have many set objects some of which can contain same group of object while others can be subset of the other. Given a list of sets, I need to get a list of unique sets such that non of the...
29
by: Chris Dutrow | last post by:
I searched around on the net for a bit, couldn't find anything though. I would like to find some code for a function where I input A Range Of Integers For example: Function( 1, 100 ); And the...
2
by: Dave | last post by:
Hello all, I have a class that contains a large number of discrete pieces of state information. Any combination of these member variables might be valid for a given object. Any given member...
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
2
by: galsaba | last post by:
Is there a "Find" fucntion in Access? I found this is Excell Find (find_text, within_text, start_num). Where can i find a similar function is Access? galsaba
36
by: Robert Vazan | last post by:
I am looking for other people's attempts to create safe subset of C and enforce it with scripts. Does anybody know about anything like this? By "safe", I mean the following: * Strongly typed...
0
by: camarkco | last post by:
Hi, I am running Version 8.0.50727.867 (vsvista.050727-8600) of VS2005. In my C# program Find All References returns only a subset of all references, the definition of the type and where the...
4
by: Andrus | last post by:
Checking Client-only framework subset in VS2008 SP1 project properties causes in my application compile error The type 'System.Data.Linq.ITable' is defined in an assembly that is not...
7
by: PeteSpeed | last post by:
Hi, I need help with creating an algorithm to solve the problem below in the most efficient manner (efficiency in this case means low processing, not memory) (Disclaimer: I studied discrete...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.