37 g_table_entry_constructor constructor;
38 g_table_entry_destroyer destroyer;
44 g_table_new (guint entry_size,
45 g_table_entry_constructor constructor,
46 g_table_entry_destroyer destroyer,
53 gtable->array = g_array_new(FALSE, FALSE, entry_size);
55 gtable->entry_size = entry_size;
60 gtable->constructor = constructor;
61 gtable->destroyer = destroyer;
63 gtable->user_data = user_data;
69 g_table_destroy (
GTable *gtable)
74 g_table_resize (gtable, 0, 0);
76 g_array_free (gtable->array, TRUE);
84 g_table_index (
GTable *gtable,
int row,
int col)
90 if ((row < 0) || (col < 0))
92 if (row >= gtable->rows)
94 if (col >= gtable->cols)
97 index = ((row * gtable->cols) + col) * gtable->entry_size;
99 return >able->array->data[index];
103 g_table_resize (
GTable *gtable,
int rows,
int cols)
110 if ((rows < 0) || (cols < 0))
113 old_len = gtable->array->len;
114 new_len = rows * cols;
116 if (new_len == old_len)
120 if ((new_len < old_len) && gtable->destroyer)
125 entry = >able->array->data[new_len * gtable->entry_size];
126 for (i = new_len; i < old_len; i++)
128 gtable->destroyer(entry, gtable->user_data);
129 entry += gtable->entry_size;
134 g_array_set_size(gtable->array, new_len);
137 if ((new_len > old_len) && gtable->constructor)
142 entry = >able->array->data[old_len * gtable->entry_size];
143 for (i = old_len; i < new_len; i++)
145 gtable->constructor(entry, gtable->user_data);
146 entry += gtable->entry_size;
155 g_table_rows (
GTable *gtable)
164 g_table_cols (
GTable *gtable)