CMapStringToPtr

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2006
Posts: 61
Reputation: dev.cplusplus is an unknown quantity at this point 
Solved Threads: 0
dev.cplusplus's Avatar
dev.cplusplus dev.cplusplus is offline Offline
Junior Poster in Training

CMapStringToPtr

 
0
  #1
Aug 9th, 2006
:mrgreen:
Hi to all, I have a challange in my work, we have a project that uses a variable of type "CMapStringToPtr", this object is use to store some data, now we want to change the type to more efective type, the problem is that we need to know if a value was change and put it in the first place of the list, I was thinking using "Linked List", if I value was changed, dleted the current value and put it in head of the list.
I was wandering is linked list the best solution?
Do you have any suggestion of Data Structures, we can use?
we have are saving something like this:
key, value

key value key value key value
1 1------>2 4------>4 6

Now for example key "2" its value is change to 1, now the list should be like:
key value key value key value
2 1------>1 1------>4 6
In the head of the list should be the last object(key) that was changed
Thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: CMapStringToPtr

 
0
  #2
Aug 9th, 2006
> I was wandering is linked list the best solution?
There isn't a "best" solution as such, there are many tradeoffs to be considered. Some of which are not so obvious.

Well the search/replace is going to be expensive on larger lists, but that has to be weighed against the extra complexity of something like std::map.

Are you only interested in the head of the list, or in the whole of the list?

How many times do you process the list compared to modifying the list?
Like do you scan it 100 times and change it once?

As it stands, I might go with a std::map to permit easy lookup and changing of values, and also maintain a std::list through the map to indicate the change order.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 147
Reputation: Laiq Ahmed will become famous soon enough Laiq Ahmed will become famous soon enough 
Solved Threads: 20
Laiq Ahmed Laiq Ahmed is offline Offline
Junior Poster

Re: CMapStringToPtr

 
0
  #3
Aug 10th, 2006
The problem you've described might consists of pair of key value... using pair< T1,T2> template is agood choice .....then.

I totally agree with salem, every Data Structure has some advantages and tradsoff, its depends upon your need and how it fits the scenario...

in LIFO(Last in First Out) link list the complexity of insert is O(1);
search is O(n) and it provides the forward iterator;.......

in most situation with pair of values we often need to change the "value" part of pair with key like v["key"]="value";
this is often required what is called Random Access iterator like array indexing mechanism.....

I suggest you to develop your Own std::map like structure and modify it that best suited your needs........
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum


Views: 2103 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC