![]() |
| | #1 |
| Registered User Join Date: Jul 2009
Posts: 24
| set<string> find I am new to c++ - there may be a better way to do this but I have a CSV file with column names on top and row names along the left side. and the matrix contains double values. i currently use a ifstream to pull in data into 3 containers - list of column strings, list of row strings, vector of doubles. I want to do a search on the strings in the columns to return the column position, then search the list of row strings to get the row position, then pull the value from my vector of doubles. I then convert the vector of doubles into a 2d matrix. Is this the best way to find the value from the table? Also, efficiency is very important. If it is significantly faster to convert the row strings and column strings to integers and then do the search, then that may be possible. Last edited by lawrenced; 07-21-2009 at 02:41 PM. |
| lawrenced is offline | |
| | #2 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| std::map< string, int > to map from strings to row/column indices. You then look up via: Code: double value = data[ rowMap[ rowName ] * colMap.size() + colMap[ colName ] ];
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #3 |
| Registered User Join Date: Jul 2009
Posts: 24
| transform the strings into indices? is this convert the position into an integer and then use that integer wherever i would've had the string before? |
| lawrenced is offline | |
| | #4 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Yes, but do this only once up front, not every time you access a matrix element. Of course, if the strings are being generated dynamically and handed to you, you can't do that. But if you're given a fixed data set and row/col string pairs up front, just convert everything once in the beginning.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
![]() |
| Tags |
| search, set, string, vector |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| could not find -lwsock32.lib | thomas_joyee | C++ Programming | 8 | 07-14-2008 12:28 PM |
| How to find O of threads ? | jabka | C Programming | 3 | 03-11-2008 12:25 PM |
| how do u find 2nd largest number?? | juancardenas | C Programming | 8 | 02-14-2003 08:28 AM |
| Problem building Quake source | Silvercord | Game Programming | 14 | 01-25-2003 10:01 PM |
| Q: Recursion to find all paths of a maze | reti | C Programming | 7 | 11-26-2002 09:28 AM |