Commit f73e172f authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Take advantage of sort_data_length and sort_permute_invert.

2000-06-08  Morten Welinder  <terra@diku.dk>

	* src/commands.c (cmd_sort_undo): Take advantage of
 	sort_data_length and sort_permute_invert.

	* src/sort.c (sort_data_length): Make public.
	(sort_permute_invert): New function.
parent c66708d1
2000-06-08 Morten Welinder <terra@diku.dk>
* src/commands.c (cmd_sort_undo): Take advantage of
sort_data_length and sort_permute_invert.
* src/sort.c (sort_data_length): Make public.
(sort_permute_invert): New function.
2000-06-08 Jon K Hellan <hellan@acm.org>
* src/workbook.c (change_displayed_zoom_cb): Set zoom using
......
2000-06-08 Morten Welinder <terra@diku.dk>
* src/commands.c (cmd_sort_undo): Take advantage of
sort_data_length and sort_permute_invert.
* src/sort.c (sort_data_length): Make public.
(sort_permute_invert): New function.
2000-06-08 Jon K Hellan <hellan@acm.org>
* src/workbook.c (change_displayed_zoom_cb): Set zoom using
......
2000-06-08 Morten Welinder <terra@diku.dk>
* src/commands.c (cmd_sort_undo): Take advantage of
sort_data_length and sort_permute_invert.
* src/sort.c (sort_data_length): Make public.
(sort_permute_invert): New function.
2000-06-08 Jon K Hellan <hellan@acm.org>
* src/workbook.c (change_displayed_zoom_cb): Set zoom using
......
2000-06-08 Morten Welinder <terra@diku.dk>
* src/commands.c (cmd_sort_undo): Take advantage of
sort_data_length and sort_permute_invert.
* src/sort.c (sort_data_length): Make public.
(sort_permute_invert): New function.
2000-06-08 Jon K Hellan <hellan@acm.org>
* src/workbook.c (change_displayed_zoom_cb): Set zoom using
......
2000-06-08 Morten Welinder <terra@diku.dk>
* src/commands.c (cmd_sort_undo): Take advantage of
sort_data_length and sort_permute_invert.
* src/sort.c (sort_data_length): Make public.
(sort_permute_invert): New function.
2000-06-08 Jon K Hellan <hellan@acm.org>
* src/workbook.c (change_displayed_zoom_cb): Set zoom using
......
2000-06-08 Morten Welinder <terra@diku.dk>
* src/commands.c (cmd_sort_undo): Take advantage of
sort_data_length and sort_permute_invert.
* src/sort.c (sort_data_length): Make public.
(sort_permute_invert): New function.
2000-06-08 Jon K Hellan <hellan@acm.org>
* src/workbook.c (change_displayed_zoom_cb): Set zoom using
......
2000-06-08 Morten Welinder <terra@diku.dk>
* src/commands.c (cmd_sort_undo): Take advantage of
sort_data_length and sort_permute_invert.
* src/sort.c (sort_data_length): Make public.
(sort_permute_invert): New function.
2000-06-08 Jon K Hellan <hellan@acm.org>
* src/workbook.c (change_displayed_zoom_cb): Set zoom using
......
......@@ -1522,26 +1522,11 @@ static gboolean
cmd_sort_undo (GnumericCommand *cmd, CommandContext *context)
{
CmdSort *me = CMD_SORT (cmd);
int length, i;
int *inv;
g_return_val_if_fail (me != NULL, TRUE);
if (!me->inv) {
if (me->data->top) {
length = me->data->range->end.row -
me->data->range->start.row + 1;
} else {
length = me->data->range->end.col -
me->data->range->start.col + 1;
}
me->inv = g_new (int, length);
for (i=0; i <length; i++) {
me->inv[me->perm[i]] = i;
}
me->inv = sort_permute_invert (me->perm, sort_data_length (me->data));
}
sort_position (context, me->data, me->inv);
sheet_set_dirty (me->data->sheet, TRUE);
......
......@@ -40,7 +40,7 @@ sort_data_destroy (SortData *data)
g_free (data);
}
static int
int
sort_data_length (const SortData *data)
{
if (data->top)
......@@ -215,6 +215,19 @@ sort_permute_range (SortData *data, Range *range, int adj)
}
}
int *
sort_permute_invert (const int *perm, int length)
{
int i, *rperm;
rperm = g_new (int, length);
for (i = 0; i < length; i++)
rperm[perm[i]] = i;
return rperm;
}
#undef DEBUG_SORT
static void
......@@ -226,10 +239,6 @@ sort_permute (CommandContext *context, SortData *data, const int *perm, int leng
pt.sheet = data->sheet;
pt.paste_flags = PASTE_FORMATS | PASTE_FORMULAS | PASTE_EXPR_RELOCATE;
rperm = g_new (int, length);
for (i = 0; i < length; i++)
rperm[perm[i]] = i;
#ifdef DEBUG_SORT
fprintf (stderr, "Permutation:");
for (i = 0; i < length; i++)
......@@ -237,6 +246,8 @@ sort_permute (CommandContext *context, SortData *data, const int *perm, int leng
fprintf (stderr, "\n");
#endif
rperm = sort_permute_invert (perm, length);
for (i = 0; i < length; i++) {
Range range1, range2;
CellRegion *rcopy1, *rcopy2 = NULL;
......
......@@ -26,4 +26,7 @@ void sort_position (CommandContext *context, SortData *data, int *perm);
int *sort_contents (CommandContext *context, SortData *data);
int sort_data_length (const SortData *data);
int *sort_permute_invert (const int *perm, int length);
#endif /* SORT_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment