/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to src/Matrix.c

  • Committer: Gustav Hartvigsson
  • Date: 2015-09-01 15:03:58 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20150901150358-vftd2io1vof8nx68
* Implemented s_matrix_set and s_matrix_append
* fixed a lil' error of ">" vs ">="... I think.... ?

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
  SMatrix * new_self = s_matrix_new (width, self->height, new_row_information);
43
43
  for (size_t i = 0; i <= self->height; i++) {
44
44
    for (size_t j = 0; j <= self->width; j++) {
45
 
      if (j > new_self->width) {
 
45
      if (j >= new_self->width) {
46
46
        s_matrix_set (new_self, i, j, s_matrix_get (self, i, j));
47
47
      } else {
48
48
        //Nothing
57
57
s_matrix_get (SMatrix * self, size_t x, size_t y) {
58
58
  spointer ret = NULL;
59
59
  if ((x < self->height) && (x < self->last_tuple)){
60
 
    ret = self->matrix[self->width * x + y];
 
60
    ret = self->matrix[(self->width * x) + y];
61
61
  } else {
62
62
    s_warn_print ("The tuple requested does not exist.\n");
63
63
  }
67
67
 
68
68
void
69
69
s_matrix_set (SMatrix * self, size_t x, size_t y, spointer data) {
70
 
  
 
70
  if (x >= self->height) {
 
71
    spointer new_matrix = realloc (self->matrix,
 
72
                                   sizeof (spointer) *
 
73
                                   round_up (x + self->width, self->width));
 
74
    if (new_matrix) {
 
75
      self->matrix = new_matrix;
 
76
    } else {
 
77
      s_err_print ("Could not reallocate memory. Out of memory?\n");
 
78
      print_backtrace ();
 
79
      return;
 
80
    }
 
81
  }
 
82
  if (x > self->last_tuple) {
 
83
    self->last_tuple = x;
 
84
  }
 
85
  self->matrix[(self->width * x) + y];
71
86
}
72
87
 
73
88
spointer *
80
95
    }
81
96
  } else {
82
97
    s_warn_print ("The tuple requested does not exist.\n");
83
 
    print_backtrace ();
84
98
  }
85
99
  return tuple;
86
100
}
89
103
s_matrix_append (SMatrix * self, spointer tuple) {
90
104
  if (!tuple){
91
105
    s_err_print ("Tuple is NULL, this is not allowed. Returning.\n");
 
106
    print_backtrace ();
92
107
    return;
93
108
  }
94
 
  
 
109
  /* Get pos of last last_tuple + 1 */
 
110
  size_t new_x_pos = self->last_tuple + 1;
 
111
  /* add data to the tuple.*/
 
112
  for (size_t i = 0; i <= self->width; i++) {
 
113
    s_matrix_set (self, new_x_pos, i, tuple[i]);
 
114
  }
 
115
  self->last_tuple = new_x_pos;
95
116
}
96
117
 
97
118