Algorithm-PageRank-XS
view release on metacpan or search on metacpan
if (array == NULL)
return 1;
if (array->data != NULL)
free(array->data);
free(array);
return 0;
}
void _table_expand(Table *tb, unsigned int i);
Table * table_init()
{
Table * result;
result = (Table *)malloc(sizeof(Table));
if (result == NULL) {
fprintf(stderr, "Memory error\n");
exit(2);
}
result->order = 1;
result->capacity = result->order = 0;
result->rows = (Array **)malloc(sizeof(Array *));
if (result->rows == NULL) {
fprintf(stderr, "Memory error\n");
exit(2);
}
result->rows[0] = NULL;
_table_expand(result, 999);
result->order = 0;
return result;
}
void table_print(FILE * file, Table * tb)
{
register unsigned int i;
fprintf(file, "TABLE OF ORDER %d AND CAPACITY %d\n", tb->order, tb->capacity);
for (i = 0; i < tb->order; i++) {
fprintf(file, "%d: ", i);
array_print(file, table_get(tb, i));
fprintf(file, "\n");
}
}
void _table_expand(Table *tb, unsigned int i)
{
unsigned int j;
if (i < tb->capacity)
return;
tb->rows = (Array **)realloc(tb->rows, (i + 1) * sizeof(Array *));
if (tb->rows == NULL) {
fprintf(stderr, "Memory error\n");
exit(2);
for (j = tb->order; j <= i; j++) {
tb->rows[j] = NULL;
}
tb->capacity = tb->order = i + 1;
}
Array * table_add(Table * tb, unsigned int i, Array * row)
{
if (i >= tb->capacity)
_table_expand(tb, i);
else {
if (i >= tb->order) {
tb->order = i + 1;
}
}
tb->rows[i] = row;
return row;
}
( run in 2.604 seconds using v1.01-cache-2.11-cpan-5b529ec07f3 )