range_list.h
Go to the documentation of this file.
/*
* Copyright (C) 2008-2010 Timothy D. Morgan
*
* 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
* the Free Software Foundation; version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id$
*/
#ifndef _RANGE_LIST_H
#define _RANGE_LIST_H
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <talloc.h>
#include "compat.h"
typedef struct _range_list_element
{
uint32_t offset;
uint32_t length;
void* data;
} range_list_element;
typedef struct _range_list
{
range_list_element** elements;
uint32_t elem_alloced;
uint32_t size;
} range_list;
_EXPORT()
range_list* range_list_new();
_EXPORT()
void range_list_free(range_list* rl);
_EXPORT()
uint32_t range_list_size(const range_list* rl);
_EXPORT()
bool range_list_add(range_list* rl, uint32_t offset, uint32_t length, void* data);
_EXPORT()
bool range_list_remove(range_list* rl, uint32_t index);
_EXPORT()
const range_list_element* range_list_get(const range_list* rl, uint32_t index);
_EXPORT()
int32_t range_list_find(const range_list* rl, uint32_t offset);
_EXPORT()
void* range_list_find_data(const range_list* rl, uint32_t offset);
_EXPORT()
bool range_list_split_element(range_list* rl, uint32_t index, uint32_t offset);
_EXPORT()
bool range_list_has_range(range_list* rl, uint32_t start, uint32_t length);
#endif
range_list_element
Definition: range_list.h:42
range_list_add
bool range_list_add(range_list *rl, uint32_t offset, uint32_t length, void *data)
Adds an element to the range_list.
Definition: range_list.c:161
range_list_free
void range_list_free(range_list *rl)
Frees the memory associated with a range_list, including the elements, but not any data parameters re...
Definition: range_list.c:147
range_list_get
const range_list_element * range_list_get(const range_list *rl, uint32_t index)
Retrieves the element for a given index.
Definition: range_list.c:244
range_list_find
int32_t range_list_find(const range_list *rl, uint32_t offset)
Attempts to find the unique element whose range encompasses offset.
Definition: range_list.c:253
range_list_new
range_list * range_list_new()
Allocates a new range_list.
Definition: range_list.c:125
range_list_find_data
void * range_list_find_data(const range_list *rl, uint32_t offset)
Same as range_list_find(), but returns the data associated with an element.
Definition: range_list.c:275
range_list_split_element
bool range_list_split_element(range_list *rl, uint32_t index, uint32_t offset)
Splits an existing element into two elements in place.
Definition: range_list.c:285
range_list_size
uint32_t range_list_size(const range_list *rl)
Query the current number of elements on a range_list.
Definition: range_list.c:154
range_list_remove
bool range_list_remove(range_list *rl, uint32_t index)
Removes an element from the list.
Definition: range_list.c:212
range_list_has_range
bool range_list_has_range(range_list *rl, uint32_t start, uint32_t length)
Determines whether or not a specified range exists contiguously within the range_list.
Definition: range_list.c:318
range_list
XXX: document this.
Definition: range_list.h:51