FireBall
asked on
if map exceeds number of rows
Hello ,
Is there any possible way remove if the number of rows exceeds X the oldest (Total_Row - X ) count rows.
Is there any possible way remove if the number of rows exceeds X the oldest (Total_Row - X ) count rows.
ASKER
static std::map<std::string ,int> Hexdump_Container;
No it is a C question
Hm - at least I don't understand. What 'rows' do you mean? A 'std::map' (which is C++, not C, just to avoid misunderstandings) doesn't have any rows. Probably you simply mean entries instead?
In this case there's one problem - in order to remove the correct ones you'll have to somehow store a counter or timestamp or something with the entries in the map.
You could i.e. add an int somehow like this: static std::map< std::string ,std::pair< int, int > >, thus you can use i.e. the second int as an increasing counter. You'll have to store a counter value somewhere, set it and increase it whenever a new entry is added. Then you should be able to i.e. write a simple loop to remove all entries with a counter smaller than a given value.
ZOPPO
In this case there's one problem - in order to remove the correct ones you'll have to somehow store a counter or timestamp or something with the entries in the map.
You could i.e. add an int somehow like this: static std::map< std::string ,std::pair< int, int > >, thus you can use i.e. the second int as an increasing counter. You'll have to store a counter value somewhere, set it and increase it whenever a new entry is added. Then you should be able to i.e. write a simple loop to remove all entries with a counter smaller than a given value.
ZOPPO
ASKER
Hm - at least I don't understand. What 'rows' do you mean? A 'std::map' (which is C++, not C, just to avoid misunderstandings) doesn't have any rows. Probably you simply mean entries instead?
Yes i am sorry , when i think like in my language row is possibily good word for the describe :)
In this case there's one problem - in order to remove the correct ones you'll have to somehow store a counter or timestamp or something with the entries in the map.
does it insert the entries randomly ?
Sorry. :)
The std::map class doesn't age items in the list so there's no direct "delete the oldest N items from the list" function.
Most list constructs add new members to the end, so it's probably safe to assume that items in the list are initially in aged order. There is no guarantee that the order is maintained once items in the list are modified or deleted. That is, if the list has 100 items and item 8 is deleted, are the 92 items that follow item 8 slid up or is the last item moved to the open slot?
You'll probably have to write your own by iterating over the list and drop points that you no longer want .
Kent
The std::map class doesn't age items in the list so there's no direct "delete the oldest N items from the list" function.
Most list constructs add new members to the end, so it's probably safe to assume that items in the list are initially in aged order. There is no guarantee that the order is maintained once items in the list are modified or deleted. That is, if the list has 100 items and item 8 is deleted, are the 92 items that follow item 8 slid up or is the last item moved to the open slot?
You'll probably have to write your own by iterating over the list and drop points that you no longer want .
Kent
ASKER
static std::map<std::string, timer ,int> Hexdump_Container;
is there any possible way, if we add time to the entries like this :
struct timeval now_v;
gettimeofday (&now_v, NULL);
timer = ((now_v.tv_sec*1000000)+now_v.tv_usec);
how should we order it newest to oldest ?
That should work. But you'll still need to write your own delete_oldest method or process.
ASKER
what about the arrays ? how is the performance of arrays ? does it ordered in inserting order ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thankyou std::list is good
Are you sure this is a C question? It looks like you probably want a database solution.
Kent