/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/DynamicArray.c

  • Committer: Gustav Hartvigsson
  • Date: 2015-04-28 12:25:20 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20150428122520-n90grm1k1l318ooa
* Finnished SLinkedList.
  * Still needs to be tested.
* Made s_object_initialize take the name of the class
* made s_object_free free the name
* fixed s_dynamic_array_free. It now takes a sboolean to tell it
  to free the data in the array or not.
* fixed a typo in defs.h
* fixed the the test of the dynamic array.
* switched (SObject *) to S_OBJECT () for casting in SError.
* changed hash_t to size_t.
* general code cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
  
43
43
  self->max_size = len;
44
44
  
 
45
  self->last_item = 0;
 
46
  
45
47
  self->priv->free_func = free_func;
46
48
  
47
49
  self->priv->array = calloc (len ,sizeof (* self->priv->array));
49
51
  return self;
50
52
}
51
53
 
52
 
void s_dynamic_array_free (SDynamicArray * self) {
53
 
  if (self->priv->free_func != NULL) {
54
 
    s_dynamic_array_for_each (self, (ForEachFunc) _private_for_each_item_free,
55
 
                            NULL);
56
 
  } else {
57
 
    for (int i = 0; i < self->last_item; i++) {
58
 
      free (self->priv->array[i]);
 
54
void s_dynamic_array_free (SDynamicArray * self, sboolean free_data) {
 
55
  if (free_data) {
 
56
    if (self->priv->free_func != NULL) {
 
57
      s_dynamic_array_for_each (self, (ForEachFunc) _private_for_each_item_free,
 
58
                              NULL);
 
59
    } else {
 
60
      for (int i = 0; i < self->last_item; i++) {
 
61
        free (self->priv->array[i]);
 
62
      }
59
63
    }
60
64
  }
 
65
  
61
66
  free (self->priv->array);
 
67
  free (self->priv);
62
68
  free (self);
63
69
}
64
70
 
69
75
void s_dynamic_array_set (SDynamicArray * self, size_t index, spointer item) {
70
76
  if (self->max_size <= index) {
71
77
    size_t new_size = round_up (index + ARRAY_PADDING, ARRAY_PADDING) + 1;
72
 
    s_dbg_print ("Index: %d current array size: %d new array size: %d ",
 
78
    s_dbg_print ("Index: %zu current array size: %zu new array size: %zu ",
73
79
      index, self->max_size, new_size);
74
80
    
75
81
    self->max_size = new_size;