X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fllx.c;h=3a0cbf60fce154cc7c5c88e390741236ae38cc80;hb=81579d9e9f994fb2908f50af41c3eb033d216e58;hp=4dc82bffeb66219bf37d12f7cff7131a0c73cccc;hpb=43b1296aafe7582e7dbe6c2b6a8b478d7d9b0fcf;p=pspp-builds.git diff --git a/src/libpspp/llx.c b/src/libpspp/llx.c index 4dc82bff..3a0cbf60 100644 --- a/src/libpspp/llx.c +++ b/src/libpspp/llx.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2006 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 @@ -28,8 +28,8 @@ #include #endif -#include -#include "compiler.h" +#include "libpspp/llx.h" +#include "libpspp/compiler.h" #include #include @@ -219,6 +219,20 @@ llx_remove_if (struct llx *r0, struct llx *r1, 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. */ @@ -232,7 +246,7 @@ llx_find_equal (const struct llx *r0, const struct llx *r1, for (x = r0; x != r1; x = llx_next (x)) if (compare (llx_data (x), target, aux) == 0) break; - return (struct llx *) x; + return CONST_CAST (struct llx *, x); } /* Returns the first node in R0...R1 for which PREDICATE returns @@ -248,7 +262,7 @@ llx_find_if (const struct llx *r0, const struct llx *r1, for (x = r0; x != r1; x = llx_next (x)) if (predicate (llx_data (x), aux)) break; - return (struct llx *) x; + return CONST_CAST (struct llx *, x); } /* Compares each pair of adjacent nodes in R0...R1 @@ -266,10 +280,10 @@ llx_find_adjacent_equal (const struct llx *r0, const struct llx *r1, for (x = r0, y = llx_next (x); y != r1; x = y, y = llx_next (y)) if (compare (llx_data (x), llx_data (y), aux) == 0) - return (struct llx *) x; + return CONST_CAST (struct llx *, x); } - return (struct llx *) r1; + return CONST_CAST (struct llx *, r1); } /* Returns the number of nodes in R0...R1. @@ -329,7 +343,7 @@ llx_max (const struct llx *r0, const struct llx *r1, if (compare (llx_data (x), llx_data (max), aux) > 0) max = x; } - return (struct llx *) max; + return CONST_CAST (struct llx *, max); } /* Returns the least node in R0...R1 according to COMPARE given @@ -348,7 +362,7 @@ llx_min (const struct llx *r0, const struct llx *r1, if (compare (llx_data (x), llx_data (min), aux) < 0) min = x; } - return (struct llx *) min; + return CONST_CAST (struct llx *, min); } /* Lexicographically compares A0...A1 to B0...B1. @@ -521,7 +535,7 @@ llx_find_run (const struct llx *r0, const struct llx *r1, llx_data (r0), aux) <= 0); } - return (struct llx *) r0; + return CONST_CAST (struct llx *, r0); } /* Merges B0...B1 into A0...A1 according to COMPARE given @@ -734,7 +748,7 @@ llx_find_partition (const struct llx *r0, const struct llx *r1, if (predicate (llx_data (x), aux)) return NULL; - return (struct llx *) partition; + return CONST_CAST (struct llx *, partition); } /* Allocates and returns a node using malloc. */