/* PSPP - a program for statistical analysis.
- Copyright (C) 2006, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2009, 2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <config.h>
#endif
-#include <libpspp/llx.h>
-#include "compiler.h"
-#include <assert.h>
+#include "libpspp/llx.h"
+#include "libpspp/compiler.h"
#include <stdlib.h>
/* Destroys LIST and frees all of its nodes using MANAGER.
{
struct llx *llx;
- for (llx = r0; llx != r1; )
+ for (llx = r0; llx != r1;)
llx = llx_remove (llx, manager);
}
size_t count;
count = 0;
- for (x = r0; x != r1; )
+ for (x = r0; x != r1;)
if (compare (llx_data (x), target, aux) == 0)
{
x = llx_remove (x, manager);
size_t count;
count = 0;
- for (x = r0; x != r1; )
+ for (x = r0; x != r1;)
if (predicate (llx_data (x), aux))
{
x = llx_remove (x, manager);
return count;
}
+/* Returns the first node in R0...R1 that has data TARGET.
+ Returns NULL if no node in R0...R1 equals TARGET. */
+struct llx *
+llx_find (const struct llx *r0, const struct llx *r1, const void *target)
+{
+ const struct llx *x;
+
+ for (x = r0; x != r1; x = llx_next (x))
+ if (llx_data (x) == target)
+ return CONST_CAST (struct llx *, x);
+
+ return NULL;
+}
+
/* Returns the first node in R0...R1 that equals TARGET
according to COMPARE given auxiliary data AUX.
Returns R1 if no node in R0...R1 equals TARGET. */
llx_sort (struct llx *r0, struct llx *r1, llx_compare_func *compare, void *aux)
{
struct llx *pre_r0;
- size_t output_run_cnt;
+ size_t output_run_len;
if (r0 == r1 || llx_next (r0) == r1)
return;
do
{
struct llx *a0 = llx_next (pre_r0);
- for (output_run_cnt = 1; ; output_run_cnt++)
+ for (output_run_len = 1; ; output_run_len++)
{
struct llx *a1 = llx_find_run (a0, r1, compare, aux);
struct llx *a2 = llx_find_run (a1, r1, compare, aux);
a0 = llx_merge (a0, a1, a1, a2, compare, aux);
}
}
- while (output_run_cnt > 1);
+ while (output_run_len > 1);
}
/* Finds the extent of a run of nodes of increasing value