X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Frange-set.h;h=9e665e994efae8d079cc0166129568779c9bdfb2;hb=ac9250d84078a03c825f3d801305cdcd071ebb86;hp=3b7d04f4883710530b894a0f03e48fe7e60be39a;hpb=f726e96e846a133b6493fb017668d4cf4795f737;p=pspp-builds.git diff --git a/src/libpspp/range-set.h b/src/libpspp/range-set.h index 3b7d04f4..9e665e99 100644 --- a/src/libpspp/range-set.h +++ b/src/libpspp/range-set.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2007, 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 @@ -25,7 +25,8 @@ #define LIBPSPP_RANGE_SET_H #include -#include +#include "libpspp/bt.h" +#include "libpspp/cast.h" /* A set of ranges. */ struct range_set @@ -70,6 +71,10 @@ static inline const struct range_set_node *range_set_first ( const struct range_set *); static inline const struct range_set_node *range_set_next ( const struct range_set *, const struct range_set_node *); +static inline const struct range_set_node *range_set_last ( + const struct range_set *); +static inline const struct range_set_node *range_set_prev ( + const struct range_set *, const struct range_set_node *); static inline unsigned long int range_set_node_get_start ( const struct range_set_node *); static inline unsigned long int range_set_node_get_end ( @@ -85,6 +90,10 @@ static inline struct range_set_node *range_set_next__ ( const struct range_set *, const struct range_set_node *); static inline struct range_set_node *range_set_first__ ( const struct range_set *); +static inline struct range_set_node *range_set_prev__ ( + const struct range_set *, const struct range_set_node *); +static inline struct range_set_node *range_set_last__ ( + const struct range_set *); /* Returns true if RS contains no 1-bits, false otherwise. */ static inline bool @@ -114,10 +123,35 @@ static inline const struct range_set_node * range_set_next (const struct range_set *rs, const struct range_set_node *node) { return (node != NULL - ? range_set_next__ (rs, (struct range_set_node *) node) + ? range_set_next__ (rs, CONST_CAST (struct range_set_node *, node)) : range_set_first__ (rs)); } +/* Returns the node representing the last contiguous region of + 1-bits in RS, or a null pointer if RS is empty. + Any call to range_set_insert, range_set_delete, or + range_set_allocate invalidates the returned node. */ +static inline const struct range_set_node * +range_set_last (const struct range_set *rs) +{ + return range_set_last__ (rs); +} + +/* If NODE is nonnull, returns the node representing the previous + contiguous region of 1-bits in RS following NODE, or a null + pointer if NODE is the first region in RS. + If NODE is null, returns the last region in RS, as for + range_set_last. + Any call to range_set_insert, range_set_delete, or + range_set_allocate invalidates the returned node. */ +static inline const struct range_set_node * +range_set_prev (const struct range_set *rs, const struct range_set_node *node) +{ + return (node != NULL + ? range_set_prev__ (rs, CONST_CAST (struct range_set_node *, node)) + : range_set_last__ (rs)); +} + /* Returns the position of the first 1-bit in NODE. */ static inline unsigned long int range_set_node_get_start (const struct range_set_node *node) @@ -166,4 +200,21 @@ range_set_first__ (const struct range_set *rs) return range_set_node_from_bt__ (bt_first (&rs->bt)); } +/* Returns the previous range_set_node in RS after NODE, + or a null pointer if NODE is the first node in RS. */ +static inline struct range_set_node * +range_set_prev__ (const struct range_set *rs, + const struct range_set_node *node) +{ + return range_set_node_from_bt__ (bt_prev (&rs->bt, &node->bt_node)); +} + +/* Returns the last range_set_node in RS, + or a null pointer if RS is empty. */ +static inline struct range_set_node * +range_set_last__ (const struct range_set *rs) +{ + return range_set_node_from_bt__ (bt_last (&rs->bt)); +} + #endif /* libpspp/range-set.h */