Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. (function(){
  2. console.log('script init');
  3.  
  4. var Vertox = function(label){
  5. var _str = function(label) {
  6. return 'Vectox['+ label + ']';
  7. };
  8.  
  9. return {
  10. label: label,
  11.  
  12. str: _str(label)
  13. };
  14. };
  15.  
  16.  
  17. var Edge = function(v, w){
  18. var _str = function(v, w){
  19. return 'Edge[' + v.str + ',' + w.str + ']';
  20. };
  21.  
  22. return {
  23. v : v,
  24. w : w,
  25. str: _str(v, w)
  26. };
  27. };
  28.  
  29. var Graph = function(vs) {
  30. var es = {};
  31.  
  32. var _str = function(es){
  33. console.log(es);
  34. };
  35.  
  36. return {
  37. vs: vs,
  38. es: {},
  39.  
  40. add_edge: function(v, w) {
  41. var e = Edge(v, w);
  42. this.es[v] = {w: e};
  43. this.es[w] = {v: e};
  44. },
  45.  
  46. add_all_edge: function() {
  47. for (var i=0; i < vs.length; i++){
  48. for (var j=i+1; j < vs.length; j++){
  49. this.add_edge(vs[i], vs[j]);
  50. }
  51. }
  52. },
  53.  
  54. str: ,
  55. };
  56. };
  57.  
  58. var init = function(){
  59. v = Vertox('v');
  60. w = Vertox('w');
  61. e = Edge(v, w);
  62.  
  63. g = Graph([v, w]);
  64. g.add_all_edge();
  65. console.log(g.str);
  66.  
  67. };
  68.  
  69. init();
  70. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement