[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 13/13] range-set: New macro RANGE_SET_FOR_EACH to make iteration
From: |
Ben Pfaff |
Subject: |
[PATCH 13/13] range-set: New macro RANGE_SET_FOR_EACH to make iteration easier. |
Date: |
Mon, 16 Apr 2012 20:52:19 -0700 |
---
src/data/datasheet.c | 5 ++---
src/libpspp/range-set.h | 5 +++++
src/libpspp/sparse-xarray.c | 14 +++++---------
tests/libpspp/range-set-test.c | 5 ++---
4 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/src/data/datasheet.c b/src/data/datasheet.c
index bee55f0..b64df14 100644
--- a/src/data/datasheet.c
+++ b/src/data/datasheet.c
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2009, 2010, 2011, 2012 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
@@ -926,8 +926,7 @@ axis_hash (const struct axis *axis, struct md4_ctx *ctx)
md4_process_bytes (&size, sizeof size, ctx);
}
- for (rsn = range_set_first (axis->available); rsn != NULL;
- rsn = range_set_next (axis->available, rsn))
+ RANGE_SET_FOR_EACH (rsn, axis->available)
{
unsigned long int start = range_set_node_get_start (rsn);
unsigned long int end = range_set_node_get_end (rsn);
diff --git a/src/libpspp/range-set.h b/src/libpspp/range-set.h
index 5b79f0e..64d888f 100644
--- a/src/libpspp/range-set.h
+++ b/src/libpspp/range-set.h
@@ -67,6 +67,11 @@ unsigned long int range_set_scan (const struct range_set *,
static inline bool range_set_is_empty (const struct range_set *);
+#define RANGE_SET_FOR_EACH(NODE, RANGE_SET) \
+ for ((NODE) = range_set_first (RANGE_SET); \
+ (NODE) != NULL; \
+ (NODE) = range_set_next (RANGE_SET, NODE))
+
static inline const struct range_set_node *range_set_first (
const struct range_set *);
static inline const struct range_set_node *range_set_next (
diff --git a/src/libpspp/sparse-xarray.c b/src/libpspp/sparse-xarray.c
index 12509fd..0cc91c6 100644
--- a/src/libpspp/sparse-xarray.c
+++ b/src/libpspp/sparse-xarray.c
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2009, 2010, 2011, 2012 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
@@ -105,8 +105,7 @@ sparse_xarray_clone (const struct sparse_xarray *old)
new->disk = ext_array_create ();
new->disk_rows = range_set_clone (old->disk_rows, NULL);
- for (node = range_set_first (old->disk_rows); node != NULL;
- node = range_set_next (old->disk_rows, node))
+ RANGE_SET_FOR_EACH (node, old->disk_rows)
{
unsigned long int start = range_set_node_get_start (node);
unsigned long int end = range_set_node_get_end (node);
@@ -336,8 +335,7 @@ sparse_xarray_write_columns (struct sparse_xarray *sx,
size_t start,
{
const struct range_set_node *node;
- for (node = range_set_first (sx->disk_rows); node != NULL;
- node = range_set_next (sx->disk_rows, node))
+ RANGE_SET_FOR_EACH (node, sx->disk_rows)
{
unsigned long int start_row = range_set_node_get_start (node);
unsigned long int end_row = range_set_node_get_end (node);
@@ -446,8 +444,7 @@ sparse_xarray_copy (const struct sparse_xarray *sx, struct
sparse_xarray *dx,
const struct range_set_node *node;
void *tmp = xmalloc (sx->n_bytes);
- for (node = range_set_first (sx->disk_rows); node != NULL;
- node = range_set_next (sx->disk_rows, node))
+ RANGE_SET_FOR_EACH (node, sx->disk_rows)
{
unsigned long int start = range_set_node_get_start (node);
unsigned long int end = range_set_node_get_end (node);
@@ -587,8 +584,7 @@ sparse_xarray_model_checker_hash (const struct
sparse_xarray *sx,
void *tmp = xmalloc (sx->n_bytes);
md4_process_bytes ("d", 1, &ctx);
- for (node = range_set_first (sx->disk_rows); node != NULL;
- node = range_set_next (sx->disk_rows, node))
+ RANGE_SET_FOR_EACH (node, sx->disk_rows)
{
unsigned long int start = range_set_node_get_start (node);
unsigned long int end = range_set_node_get_end (node);
diff --git a/tests/libpspp/range-set-test.c b/tests/libpspp/range-set-test.c
index c1fc708..c7a8917 100644
--- a/tests/libpspp/range-set-test.c
+++ b/tests/libpspp/range-set-test.c
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2009, 2010, 2011, 2012 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
@@ -163,8 +163,7 @@ print_regions (const struct range_set *rs)
const struct range_set_node *node;
printf ("result:");
- for (node = range_set_first (rs); node != NULL;
- node = range_set_next (rs, node))
+ RANGE_SET_FOR_EACH (node, rs)
printf (" (%lu,%lu)",
range_set_node_get_start (node), range_set_node_get_end (node));
printf ("\n");
--
1.7.2.5
- Re: [PATCH 03/13] gui: Add undocumented --measure-startup option., (continued)
- [PATCH 04/13] gui: Call g_thread_init() earlier., Ben Pfaff, 2012/04/16
- [PATCH 05/13] format: New functions fmt_change_width(), fmt_change_decimals()., Ben Pfaff, 2012/04/16
- [PATCH 07/13] format: Fix typo in comment., Ben Pfaff, 2012/04/16
- [PATCH 08/13] helper: New function value_to_text__()., Ben Pfaff, 2012/04/16
- [PATCH 09/13] value-labels: New function val_labs_find_value()., Ben Pfaff, 2012/04/16
- [PATCH 06/13] format: Introduce a new type "enum fmt_use"., Ben Pfaff, 2012/04/16
- [PATCH 10/13] abt: Drop child parameters from 'reaugment' function., Ben Pfaff, 2012/04/16
- [PATCH 11/13] abt: New function abt_is_empty()., Ben Pfaff, 2012/04/16
- [PATCH 12/13] range-set: Rename "insert" function "set1", "delete" to "set0"., Ben Pfaff, 2012/04/16
- [PATCH 13/13] range-set: New macro RANGE_SET_FOR_EACH to make iteration easier.,
Ben Pfaff <=
- Re: [PATCH 00/13] second batch of psppsheet changes, John Darrington, 2012/04/18