2007-01-24 01:03:52 +00:00
|
|
|
typedef struct range {
|
|
|
|
long start;
|
2007-01-25 22:38:22 +00:00
|
|
|
long stop;
|
2007-01-24 01:03:52 +00:00
|
|
|
} range;
|
|
|
|
|
|
|
|
typedef struct transition {
|
|
|
|
long pos;
|
|
|
|
// negative if end of range. Never zero
|
|
|
|
int delta;
|
|
|
|
// >= abs(delta). Number of times the range immediately less than
|
|
|
|
// this point is pinned.
|
|
|
|
int pins;
|
|
|
|
} transition;
|
|
|
|
|
|
|
|
typedef struct rangeTracker rangeTracker;
|
|
|
|
|
|
|
|
rangeTracker * rangeTrackerInit(int quantization);
|
|
|
|
void rangeTrackerDeinit(rangeTracker * rt);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Add a new range
|
2007-02-06 02:32:01 +00:00
|
|
|
|
|
|
|
@return a null terminated array of newly-pinned, quantized ranges.
|
|
|
|
This array might contain ranges that were already pinned, and/or
|
|
|
|
ones that overlap (this aspect of the behavior is intentionally
|
|
|
|
left unspecified).
|
2007-01-24 01:03:52 +00:00
|
|
|
*/
|
|
|
|
range ** rangeTrackerAdd(rangeTracker * rt, const range * r);
|
|
|
|
/**
|
2007-02-06 02:32:01 +00:00
|
|
|
Remove a range
|
|
|
|
|
|
|
|
@return a null terminated array of unpinned, quantized ranges.
|
|
|
|
|
|
|
|
@see rangeTrackerAdd for a discussion of approximations that may
|
|
|
|
be applied to rangeTrackerRemove's return value.
|
2007-01-24 01:03:52 +00:00
|
|
|
*/
|
|
|
|
range ** rangeTrackerRemove(rangeTracker * rt, const range * r);
|
|
|
|
|
2007-01-25 22:38:22 +00:00
|
|
|
const transition ** rangeTrackerEnumerate(rangeTracker * rt);
|
2007-01-24 01:03:52 +00:00
|
|
|
char * rangeToString(const range * r);
|
|
|
|
char * transitionToString(const transition * t);
|
|
|
|
|
2007-02-12 07:54:32 +00:00
|
|
|
static inline long rangeTrackerRoundDown(long x, long quant) {
|
|
|
|
return (x / quant) * quant;
|
|
|
|
}
|
|
|
|
static inline long rangeTrackerRoundUp(long x, long quant) {
|
|
|
|
return (((x-1) / quant) + 1) * quant;
|
|
|
|
}
|
|
|
|
|