Storing and accessing a collection of strings (STD C++) -
sku1 sku2 description "01234" "34545" "white bread" "01545" "34236" "wheat bread" i need cross-reference these 3 fields, i.e. retrieve sku2 while knowing sku1, sku1 while knowing sku2, , description while knowing either sku1 or sku2.
i'm curious - best way this? vectors using search() or find()? using map somehow?
i have working using vector< vector<string> >, looping through 'parent' vectors , 'child' vectors, comparing values, seems primitive.
basically, need vector uses of strings index return 1 of 2 other values. general way i'm doing considered acceptable/optimal?
vector< vector<string> > products; int = 0; for( = 0; < 2; ++i) { products.push_back( vector<string>() ); products[i].push_back( "sku1" ); products[i].push_back( "sku2" ); products[i].push_back( "description" ); } thanks assistance.
build 3 std::map<std::string, std::string>s: 1 map sku1s sku2s, 1 map sku1s descriptions, , 1 map sku2s descriptions. (better yet, use std::unordered_map, if have (c++0x)).
this assuming have lot of data , prioritizing speed rather memory usage.
Comments
Post a Comment