summaryrefslogtreecommitdiffabout
path: root/src/depmap.c
Side-by-side diff
Diffstat (limited to 'src/depmap.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/depmap.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/depmap.c b/src/depmap.c
index 3ea5722..cb50548 100644
--- a/src/depmap.c
+++ b/src/depmap.c
@@ -81,9 +81,9 @@ TC (unsigned *R, int n)
struct pies_depmap
{
- size_t nrows;
- size_t rowlen;
- unsigned r[1];
+ size_t nrows; /* Number of rows (== number of mapped elements) */
+ size_t rowlen; /* Length of a row in words */
+ unsigned r[1]; /* Data rows */
};
pies_depmap_t
@@ -97,11 +97,18 @@ depmap_alloc (size_t count)
return dmap;
}
+/* Return size of a depmap row in bytes */
+static inline size_t
+depmap_row_size (pies_depmap_t dpm)
+{
+ return dpm->rowlen * sizeof (unsigned);
+}
+
pies_depmap_t
depmap_copy (pies_depmap_t dpm)
{
pies_depmap_t copy = depmap_alloc (dpm->nrows);
- memcpy (copy->r, dpm->r, dpm->nrows * dpm->rowlen * sizeof (unsigned));
+ memcpy (copy->r, dpm->r, dpm->nrows * depmap_row_size (dpm));
return copy;
}
@@ -174,21 +181,22 @@ depmap_end (pies_depmap_pos_t pos)
grecs_free (pos);
}
+/* Remove nth row and column from the map */
void
-depmap_clear_all (pies_depmap_t dmap, enum pies_depmap_direction dir,
- size_t coord)
+depmap_remove (pies_depmap_t dmap, size_t n)
{
- size_t i;
-
- switch (dir)
+ if (n < dmap->nrows - 1)
{
- case depmap_row:
- for (i = 0; i < dmap->nrows; i++)
- depmap_clear (dmap, coord, i);
- break;
-
- case depmap_col:
+ size_t i, j;
+
+ /* Remove nth row */
+ memmove (depmap_rowptr (dmap, n), depmap_rowptr (dmap, n + 1),
+ (dmap->nrows - n - 1) * depmap_row_size (dmap));
+ /* Renumber all columns j >= n: j = j - 1 */
for (i = 0; i < dmap->nrows; i++)
- depmap_clear (dmap, i, coord);
+ for (j = n; j < dmap->nrows - 1; j++)
+ (depmap_isset (dmap, i, j + 1) ? depmap_set : depmap_clear)
+ (dmap, i, j);
}
+ dmap->nrows--;
}

Return to:

Send suggestions and report system problems to the System administrator.