ranges

advertisement
This is a package for working with closed, bounded intervals on the
real line (as approximated by the machine's floating-point numbers).
Single points are considered to be ignorable; an interval containing
only one point is dropped.
ranges.h declares an opaque type RANGES which is used as a handle by
all the routines.
The routines are:
RANGES *ranges_new()
Creates and returns a new RANGES structure. The new structure
is initialized to contain no intervals, as if ranges_clear had
been called on it.
ranges_clear(r)
RANGES *r;
Clears the RANGES structure, so it contains no intervals.
ranges_add(r,min,max)
RANGES *r;
float min;
float max;
Adds an interval to the RANGES structure.
overlapping intervals are coalesced.
Touching or
ranges_del(r,min,max)
RANGES *r;
float min;
float max;
Deletes an interval from the RANGES structure, splitting,
shrinking, and/or deleting intervals as necessary.
ranges_map(r,fxn)
RANGES r;
void (*fxn)(); /* called as (*fxn)(min,max) float min,max; */
Calls the specified function with each interval in the RANGES
structure. The order in which the intervals are processed is
unspecified. If the function uses the other functions to
manipulate the RANGES structure, the results are unspecified
and probably not what was desired.
ranges_free(r)
RANGES *r;
Frees the RANGES structure and all associated storage. After
calling this, the RANGES structure should never be used again.
If ranges.c is compiled with -DRANGES_TEST, a simple test main() will
be included. A sample run of the resulting program:
Currently:
> a 1 10
Currently: [1..10]
> d 2 3
Currently: [1..2] [3..10]
> d 4 5
Currently: [1..2] [3..4] [5..10]
> d 6 7
Currently: [1..2] [3..4] [5..6] [7..10]
> d 8 9
Currently: [1..2] [3..4] [5..6] [7..8] [9..10]
> a 4.2 4.6
Currently: [1..2] [3..4] [4.2..4.6] [5..6] [7..8] [9..10]
> d 3.5 4.5
Currently: [1..2] [3..3.5] [4.5..4.6] [5..6] [7..8] [9..10]
> d 4.5 5.5
Currently: [1..2] [3..3.5] [5.5..6] [7..8] [9..10]
> a 3.5 4
Currently: [1..2] [3..4] [5.5..6] [7..8] [9..10]
> a 5 5.5
Currently: [1..2] [3..4] [5..6] [7..8] [9..10]
> a 4 5
Currently: [1..2] [3..6] [7..8] [9..10]
> d 1.5 7.5
Currently: [1..1.5] [7.5..8] [9..10]
> a 2 8.5
Currently: [1..1.5] [2..8.5] [9..10]
> a 1.25 9.1
Currently: [1..10]
> d 3 7
Currently: [1..3] [7..10]
> c
Currently:
>
Download