C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-21-2009, 02:37 PM   #1
Registered User
 
Join Date: Jul 2009
Posts: 24
set<string> find

hi,
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   Reply With Quote
Old 07-21-2009, 02:41 PM   #2
Senior software engineer
 
brewbuck's Avatar
 
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 ] ];
But if "efficiency" is what you want, indexing rows and columns by name is a dumb idea. Apply a single transformation to the data set up-front which maps the strings to indices. It's kind of ridiculous to perform that lookup every single time you access the matrix.
__________________
"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   Reply With Quote
Old 07-21-2009, 02:43 PM   #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   Reply With Quote
Old 07-21-2009, 05:00 PM   #4
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
Quote:
Originally Posted by lawrenced View Post
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?
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   Reply With Quote
Reply

Tags
search, set, string, vector

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 09:40 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22