/[paths]/src/graph.c
ViewVC logotype

Diff of /src/graph.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8 by ben, Sun Jul 29 10:54:56 2012 UTC revision 9 by ben, Sun Jul 29 12:07:57 2012 UTC
# Line 1  Line 1 
1  #include <string.h>  #include <string.h>
2  #include <stdlib.h>  #include <stdlib.h>
3  #include <time.h>  #include <time.h>
4    #include <assert.h>
5  #include "graph.h"  #include "graph.h"
6    
7  void node_destroy(struct node* n)  void node_destroy(struct node* n)
# Line 48  int node_link(struct node* a, struct nod Line 49  int node_link(struct node* a, struct nod
49  {  {
50          struct edge *nba, *nbb;          struct edge *nba, *nbb;
51    
52            assert (a != b);
53    
54          a->count++;          a->count++;
55          nba = realloc(a->neighbours, a->count * sizeof(struct edge));          nba = realloc(a->neighbours, a->count * sizeof(struct edge));
56          if (!nba) {          if (!nba) {
# Line 146  int graph_randomize(struct graph* g) Line 149  int graph_randomize(struct graph* g)
149                  for (j = 0; j < en; j++) {                  for (j = 0; j < en; j++) {
150                          m = rand() % g->count;                          m = rand() % g->count;
151                          n = rand() % g->count;                          n = rand() % g->count;
152                          if (node_is_linked(&(g->nodes[m]), &(g->nodes[n]))) {                          if ((m == n) || node_is_linked(&(g->nodes[m]), &(g->nodes[n]))) {
153                                  continue;                                  continue;
154                          }                          }
155                          if (node_link(&(g->nodes[m]), &(g->nodes[n]), rand())) {                          if (node_link(&(g->nodes[m]), &(g->nodes[n]), rand())) {

Legend:
Removed from v.8  
changed lines
  Added in v.9

  ViewVC Help
Powered by ViewVC 1.1.26