C Overlap Algorithm

struct overlap_algo

An instance of the overlap algorithm.

typedef double overlap_value_t

The type for “value” used by the overlap algorithm.

This can be changed if an implementation wants to use a different type for “value”. For example, on a small platform which does not support floating point, it could be changed to an uint32_t which counts only seconds.

struct overlap_algo *overlap_new(void)

Allocate and initialize an overlap_algo instance.

Returns

the a pointer to the newly allocated instance.

void overlap_del(struct overlap_algo *algo)

Clean up and free an overlap_algo instance.

Parameters

algo – pointer to the algorithm instance

int overlap_add(struct overlap_algo *algo, overlap_value_t lo, overlap_value_t hi)

Add a range the overlap algorithm.

Note, that for each call to process a new edge structure will be allocated which will not be freed until overlap_del is called on the whole algorithm instance. On a small platform, make sure to limit the number of of calls to a sensible number before giving up and restarting.

If the function returns 0 indicating an error, the algorithm instance should not be used any more, delete it and start over.

Parameters
  • algo – pointer to the algorithm instance

  • lo – the low value for range

  • hi – the high value for range

Returns

1 on success or 0 on failure (memory allocation failed)

int overlap_find(struct overlap_algo *algo, overlap_value_t *lo, overlap_value_t *hi)

Find the overlap of all added ranges.

The pointers at lo and hi of the overlap algorithm instance will be updated with the overlap that has been found.

If returned number of overlaps is 0 the nothing will be written to the values pointed to by lo and hi.

Parameters
  • algo – pointer to the algorithm instance

  • lo – the low value of the overlap is written to this pointer

  • hi – the high value of the overlap is written to this pointer

Returns

the number of ranges in the returned overlap