I am looking for a "special" kind of map :
- it is read like a map
- if the searched element exists, it is given back imediately
- if the searched element does not exist, an initialise() is called to
do the job.
- anyway the map has a limited size, when it is full, the oldest element
is dropped ( if recalled later, will need again an initialise())
Is there some STL (or not) to do that?
My idea is to store in memory big data only if there is enough physical
memory available.
Thank you in advance
Pierre Couderc 8 1459
"Pierre Couderc" <pi****@couderc.ccNOSPAM> skrev i en meddelelse
news:d7***********@biggoron.nerim.net... I am looking for a "special" kind of map :
- it is read like a map
This is ok - if the searched element exists, it is given back imediately
This is ok
- if the searched element does not exist, an initialise() is called to do the job.
This is ok - assuming you can use the default constructor to do the job. - anyway the map has a limited size, when it is full, the oldest element is dropped ( if recalled later, will need again an initialise())
You can't do that. The map knows about order of elements, but does not
remember when they were inserted. Is there some STL (or not) to do that?
Nope. It would not be a big problem creating one such structure. You would
need two structures: one to keep elements according to their "age" and one
to keep the elements sorted. My idea is to store in memory big data only if there is enough physical memory available.
This is more difficult to do portable. What do you mean by physical memory? Thank you in advance
Pierre Couderc
/Peter
Pierre Couderc <pi****@couderc.ccNOSPAM> scribbled on the stall wall: I am looking for a "special" kind of map :
- it is read like a map - if the searched element exists, it is given back imediately - if the searched element does not exist, an initialise() is called to do the job. - anyway the map has a limited size, when it is full, the oldest element is dropped ( if recalled later, will need again an initialise())
subclass a traditional map to do what you want...that's the beauty of
c++.
--
dual 2.8Ghz Xeon; 2GB RAM; 500GB ATA-133; nVidia powered
Linux 2.6.10; glibc-2.3.5; vendor neutral home-brewed installation
----anything after this line is ANNOYING CRAP that the newsserver adds-----
---directly contact newsfeeds and ISPs that piggy back them to complain----
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Wiseguy schreef: Pierre Couderc <pi****@couderc.ccNOSPAM> scribbled on the stall wall: I am looking for a "special" kind of map :
- it is read like a map - if the searched element exists, it is given back imediately - if the searched element does not exist, an initialise() is called to do the job. - anyway the map has a limited size, when it is full, the oldest element is dropped ( if recalled later, will need again an initialise())
subclass a traditional map to do what you want...that's the beauty of c++.
Why? It's not a std::map in the OO sense. Remember, in OO "IS-A" means
is-a substitute. You can't use such a special map where you would
otherwise
use a std::map. E.g. the dtor is not virtual, nor is the operator[].
Of course, this fixedSizeMap can probably use a std::map member.
HTH,
Michiel Salters
Pierre Couderc wrote: I am looking for a "special" kind of map :
- it is read like a map - if the searched element exists, it is given back imediately - if the searched element does not exist, an initialise() is called to do the job. - anyway the map has a limited size, when it is full, the oldest element is dropped ( if recalled later, will need again an initialise())
Is there some STL (or not) to do that?
My idea is to store in memory big data only if there is enough physical memory available.
Thank you in advance
Pierre Couderc
Check out Boost.MultiIndex.
You could build something like that on top of this container - it is
more efficient than maintaining several STL containers.
For example, you could make a composite index of a linked list and a
balanced tree. Your linked list would be used to find the oldest
member, and the tree would be used for indexed lookups.
I don't know if there's something "off the shelf" to do what you want.
Calum
"msalters" <Mi*************@logicacmg.com> scribbled on the stall wall: subclass a traditional map to do what you want...that's the beauty of c++.
Why? It's not a std::map in the OO sense. Remember, in OO "IS-A" means is-a substitute. You can't use such a special map where you would otherwise use a std::map. E.g. the dtor is not virtual, nor is the operator[].
Of course, this fixedSizeMap can probably use a std::map member.
shouldn't matter whether members are virtual or not. std::map give a good
starting point to CREATE a class that does what the OP wants. whether
the map is subclassed or is merely a member is merely a point of coding
preference.
--
dual 2.8Ghz Xeon; 2GB RAM; 500GB ATA-133; nVidia powered
Linux 2.6.10; glibc-2.3.5; vendor neutral home-brewed installation
----anything after this line is ANNOYING CRAP that the newsserver adds-----
---directly contact newsfeeds and ISPs that piggy back them to complain----
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Wiseguy wrote: "msalters" <Mi*************@logicacmg.com> scribbled on the stall wall: subclass a traditional map to do what you want...that's the beauty of c++.
Why? It's not a std::map in the OO sense. Remember, in OO "IS-A" means is-a substitute. You can't use such a special map where you would otherwise use a std::map. E.g. the dtor is not virtual, nor is the operator[].
Of course, this fixedSizeMap can probably use a std::map member.
shouldn't matter whether members are virtual or not. std::map give a good starting point to CREATE a class that does what the OP wants. whether the map is subclassed or is merely a member is merely a point of coding preference.
IMO, a problem like this is better solved through containment rather
than structural inheritance. If it means creating 'forwarding'
functions, then so be it. Let's not be lazy.
-shez-
Shezan Baig wrote: Wiseguy wrote:
"msalters" <Mi*************@logicacmg.com> scribbled on the stall wall:
subclass a traditional map to do what you want...that's the beauty of c++.
Why? It's not a std::map in the OO sense. Remember, in OO "IS-A" means is-a substitute. You can't use such a special map where you would otherwise use a std::map. E.g. the dtor is not virtual, nor is the operator[].
Of course, this fixedSizeMap can probably use a std::map member.
shouldn't matter whether members are virtual or not. std::map give a good starting point to CREATE a class that does what the OP wants. whether the map is subclassed or is merely a member is merely a point of coding preference. IMO, a problem like this is better solved through containment rather than structural inheritance. If it means creating 'forwarding' functions, then so be it. Let's not be lazy.
Good point. You don't want to violate your class invariant by exposing
the base class. For example, if someone called std::map::insert,
instead of mymap::insert, then your invariant (that you don't exceed a
certain size) could be violated. So you'd probably be looking at
protected inheritance anyway, in which case you may as well just use a
member.
Calum
-shez-
Calum Grant wrote: Good point. You don't want to violate your class invariant by exposing the base class. For example, if someone called std::map::insert, instead of mymap::insert, then your invariant (that you don't exceed a certain size) could be violated. So you'd probably be looking at protected inheritance anyway, in which case you may as well just use a member.
Calum
-shez-
Use private inheritance. Some of the stock STL classes have protected
members for just this reason (see std::priority_queue for an example). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: john smith |
last post by:
Hi, I have a question about map and classes that contain maps. My problem
is declaring any class methods const that would do something to the map.
Presumably it's because when operator is...
|
by: Markus Hämmerli |
last post by:
I have seen in the STL that the map is working with one key.
Does everyboby know if there is a possibility to have two key.
Do you have a little example.
Thanks Markus
|
by: Florian Liefers |
last post by:
"Hello World\n",
i have the following problem:
One of my headerfiles for a lib is including <vector>.
When i compile the lib, everything is done well.
In my application another file is...
|
by: laurence |
last post by:
I am implementing a comprehensive image-map generator utility, so have been
studying W3C HTML 4.01 Specification
(http://www.w3.org/TR/html4/struct/objects.html#h-13.6) on image maps (among
other...
|
by: Evgeny |
last post by:
Hi, all!
I didn't find yet solution for this problem! Somebody knows where is a
catch?
Looks like "operator =" or copy constructor not implemented in one of
internal templates....
Thanks in...
|
by: Steve Edwards |
last post by:
Hi,
Given a map:
typedef map<long, string, greater<long> > mapOfFreq;
Is there a quicker way to find the rank (i.e. index) of the elememt that
has the long value of x?
At the moment I'm...
|
by: Mike Copeland |
last post by:
I'm having difficulty updating map objects. In the code I've
excerpted below, I store map objects without difficulty, but my attempts
to modify elements of the stored data don't work.
struct...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |