c++ - standard and efficient map between objects -


i working on clustering problem have called distance matrix. distance matrix like: distance matrix

  1. the number of nodes(g) n (dynamic)
  2. this matrix symmetric (dist[i,j]==dist[j,i])
  3. g1,g2,.... object (they contain strings , integers , may more..)
  4. i want able reach value simple way dist[4][3] or more clear way dist(g1,g5) (here g1 , g5 may kind of pointer or reference)
  5. many std algorithm applied on distance matrix min, max, accumulate ..etc
  6. preferably not mandatory, not use boost or other 3rd party libraries

what best standard way declare matrix.

you can create 2 dimensional vector so

std::vector<std::vector<float> > table(n, std::vector<float>(n)); 

don`t forget initialize this, reserves memory n members, not need reallocate members adding more. , not fragment memory. can access members so

table[1][2] = 2.01; 

it not uses copy constructors time because vector index operator returns reference member; pretty efficient if n not need change.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -