473,394 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

stl map without any information



Is there a way to use map without any information associated
with keys? I do not need any information stored with the keys.

map<char * , >

I do not want to waste any space and keeping information with
my key will just waste space. If this can not be done, what is
smallest piece of junk i could add?

map<char *,char> ?

Or is there something better in terms of space.

Thanks,
--j

Jul 23 '05 #1
11 1517
http://www.sgi.com/tech/stl/hash_set.html
probably this is what you are looking for :-/

Jul 23 '05 #2
set< char* >

Jul 23 '05 #3
John wrote:
Is there a way to use map without any information associated
with keys? I do not need any information stored with the keys.

map<char * , >

I do not want to waste any space and keeping information with
my key will just waste space. If this can not be done, what is
smallest piece of junk i could add?

map<char *,char> ?

Or is there something better in terms of space.


std::set. If you're going to store pointers, you'll also need to pass
a comparison function to get meaningful results -- otherwise, it'll
attempt to compare the pointers themselves, not what they point at. The
result generally won't be useful.

Alternatively, you might want to store something like std::string that
already defines a useful comparison function. OTOH, this might also
negate the space savings you're trying for.

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 23 '05 #4
Thanks for all your answers. I also need the next month of the year.
I dont think std::set can do that, can it?

struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};

int main()
{
map<const char*, int, ltstr> months;

months["january"] = 31;
months["february"] = 28;
months["march"] = 31;
months["april"] = 30;
months["may"] = 31;
months["june"] = 30;
months["july"] = 31;
months["august"] = 31;
months["september"] = 30;
months["october"] = 31;
months["november"] = 30;
months["december"] = 31;

cout << "june -> " << months["june"] << endl;
map<const char*, int, ltstr>::iterator cur = months.find("june");
map<const char*, int, ltstr>::iterator prev = cur;
map<const char*, int, ltstr>::iterator next = cur;
++next;
--prev;
cout << "Previous (in alphabetical order) is " << (*prev).first <<
endl;
cout << "Next (in alphabetical order) is " << (*next).first << endl;
}

Jul 23 '05 #5
It looks to me you are wasting what a map is good for and ignoring
other more suitable data structures. Consider some variations of what
you are attempting:

struct MonthInfo
{
const char *monthName;
int daysInMonth;
};
vector<MonthInfo> v;
// fill v with objects
// or maybe more appropriately:
MonthInfo arr[] = {{"january", 31}, {"february", 28}, etc... };

just a thought

Jul 23 '05 #6


That was just an example, I am going to put a million such strings,
insert and delete them and the query strings not in the map for
strings that are alphabetically just larger than the query string.

Hope this makes it more clear,
--j

Jul 23 '05 #7
John wrote:
Thanks for all your answers. I also need the next month of the year.
I dont think std::set can do that, can it?
I'm still not clear what you're trying to do. set knows nothing more
nor less than map about the order of mothns in the year. But if you
truly believe that you want a map with junk values, then a set is what
you really want. Essentially a set is a map where the values are the
keys, but they're stored only once of course, so this is certainly
better than any junk data you might attach.

If you mean by "next month of the year" the next ordered element in the
set, then yes, a set can do this just as a map can.

Mark

struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};

int main()
{
map<const char*, int, ltstr> months;

months["january"] = 31;
months["february"] = 28;
months["march"] = 31;
months["april"] = 30;
months["may"] = 31;
months["june"] = 30;
months["july"] = 31;
months["august"] = 31;
months["september"] = 30;
months["october"] = 31;
months["november"] = 30;
months["december"] = 31;

cout << "june -> " << months["june"] << endl;
map<const char*, int, ltstr>::iterator cur = months.find("june");
map<const char*, int, ltstr>::iterator prev = cur;
map<const char*, int, ltstr>::iterator next = cur;
++next;
--prev;
cout << "Previous (in alphabetical order) is " << (*prev).first <<
endl;
cout << "Next (in alphabetical order) is " << (*next).first << endl;
}

Jul 23 '05 #8
Cool, this is the answer I was looking for, so the set does have
a order defined inside it? using the iterator++ / -- function?

Thanks a lot,
--j

Jul 23 '05 #9
John wrote:
Cool, this is the answer I was looking for, so the set does have
a order defined inside it? using the iterator++ / -- function?


Yes it does. set, like map, is a _sorted_ associative container. Look
at http://www.sgi.com/tech/stl/set.html for details.
Jul 23 '05 #10
John wrote:
Thanks for all your answers. I also need the next month of the year.
I dont think std::set can do that, can it?
Yes, but a map would be more suitable.
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
struct month_data {
int days;
char *prev;
char *next;

month_data(int d, char *p, char *n) : days(d), prev(p), next(n) {}
};
months["january"] = 31;
months["January"] = month_data(31, "December", "February");

[ ... ]
cout << "june -> " << months["june"] << endl;


cout << "june -> " << months["june"].days << endl;

month_data &m = months.find("june")->second;
cout << "Previous month -> " << m.prev << endl;
cout << "Next month -> " << m.next << endl;

Whether this is better or worse than an array of structures holding the
month names and number of days in order depends: this uses more memory
to get faster lookups. For only 12 items, it's probably a waste, but if
you had something like millions of items, that might be a different
story.

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 23 '05 #11
I think std::set<char*> is exactly what you need. "set" keeps keys only and
no values.
Michael
"John" <we**********@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...


Is there a way to use map without any information associated
with keys? I do not need any information stored with the keys.

map<char * , >

I do not want to waste any space and keeping information with
my key will just waste space. If this can not be done, what is
smallest piece of junk i could add?

map<char *,char> ?

Or is there something better in terms of space.

Thanks,
--j

Jul 23 '05 #12

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

Similar topics

4
by: Bosconian | last post by:
I have a client that provides a list of companies on their web site (powered by PHP/MySQL.) These companies advertise their services to visitors. The company information has been maintained...
3
by: Troy | last post by:
Hello- I have a website that uses a custom built webserver to serve the pages. (Please don't ask me why my boss had his own web server written). I am displaying a log of information that is an...
37
by: Haines Brown | last post by:
I understand that <br /> is marginal in CSS, and so am looking for a substitute for the EOL character. I've failed in both approaches and seek advice. The first thing I tried was to use the...
1
by: milton | last post by:
hi how i can view a datagrid control from the begining of the asp.net page is open, with or without information? thanks
22
by: Sandman | last post by:
So, I have this content management system I've developed myself. The system has a solid community part where members can register and then participate in forums, write weblogs and a ton of other...
1
by: Troels Arvin | last post by:
Hello, publib.boulder.ibm.com has been rather unstable lately, so I figured I should install a local copy of the documentation web pages. I grabbed the Windows-version of the offline version...
20
by: Prisoner at War | last post by:
Hi, People, Is it possible to have an "empty" or "dummy" <a href***without*** the browser jumping back up the page?? I have a hyperlink that doesn't point to another document, but is used to...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.