range: Introduce range_inverse_array()

This helper reverses a list of regions within a [low, high]
span, turning original regions into holes and original
holes into actual regions, covering the whole UINT64_MAX span.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
Tested-by: Yanghang Liu <yanghliu@redhat.com>
Reviewed-by: "Michael S. Tsirkin" <mst@redhat.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
Eric Auger 2023-10-19 15:45:14 +02:00 committed by Cédric Le Goater
parent 908cae0de4
commit b439595a08
2 changed files with 63 additions and 0 deletions

View file

@ -225,4 +225,12 @@ int range_compare(Range *a, Range *b);
GList *range_list_insert(GList *list, Range *data);
/*
* Inverse an array of sorted ranges over the [low, high] span, ie.
* original ranges becomes holes in the newly allocated inv_ranges
*/
void range_inverse_array(GList *in_ranges,
GList **out_ranges,
uint64_t low, uint64_t high);
#endif