Skip to content

Commit

Permalink
add an is_equal vtable to pmcmatrix2d
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Mar 15, 2010
1 parent 04f9eff commit e46e5d7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/pmc/pmcmatrix2d.pmc
Expand Up @@ -177,6 +177,34 @@ pmclass PMCMatrix2D dynpmc auto_attrs provides matrix {
return PMCNULL;
}

VTABLE INTVAL is_equal(PMC *other) {
Parrot_PMCMatrix2D_attributes * const attrs = PARROT_PMCMATRIX2D(SELF);
Parrot_PMCMatrix2D_attributes * const oattr = PARROT_PMCMATRIX2D(other);
PMC ** s;
INTVAL self_rows, self_cols, i, j, num = 0;

if (other->vtable->base_type != SELF->vtable->base_type)
return 0;

self_rows = attrs->rows;
self_cols = attrs->cols;

if (self_rows != oattr->rows || self_cols != oattr->cols)
return 0;
s = attrs->storage;

for (i = 0; i < self_rows; i++) {
for (j = 0; j < self_cols; j++) {
PMC * const ovalue = VTABLE_get_pmc_keyed_int(interp, other, num);
PMC * const mvalue = ITEM_XY_ROWMAJOR(s, self_rows, self_cols, j, i);
if (!VTABLE_is_equal(INTERP, mvalue, ovalue))
return 0;
num++;
}
}
return 1;
}

METHOD initialize_from_array(INTVAL rows_size, INTVAL cols_size, PMC * values) {
Parrot_PMCMatrix2D_attributes * const attrs = PARROT_PMCMATRIX2D(SELF);
PMC ** s;
Expand Down

0 comments on commit e46e5d7

Please sign in to comment.