regfi
range_list.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2010 Timothy D. Morgan
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * $Id$
18  */
19 
30 #ifndef _RANGE_LIST_H
31 #define _RANGE_LIST_H
32 
33 #include <stdlib.h>
34 #include <stdbool.h>
35 #include <stdint.h>
36 #include <string.h>
37 #include <math.h>
38 #include <talloc.h>
39 
40 #include "compat.h"
41 
42 typedef struct _range_list_element
43 {
44  uint32_t offset;
45  uint32_t length;
46  void* data;
48 
49 
51 typedef struct _range_list
52 {
53  range_list_element** elements;
54  uint32_t elem_alloced;
55  uint32_t size;
56 } range_list;
57 
58 
63 _EXPORT()
65 
66 
74 _EXPORT()
75 void range_list_free(range_list* rl);
76 
77 
84 _EXPORT()
85 uint32_t range_list_size(const range_list* rl);
86 
87 
104 _EXPORT()
105 bool range_list_add(range_list* rl, uint32_t offset, uint32_t length, void* data);
106 
107 
117 _EXPORT()
118 bool range_list_remove(range_list* rl, uint32_t index);
119 
120 
129 _EXPORT()
130 const range_list_element* range_list_get(const range_list* rl, uint32_t index);
131 
132 
140 _EXPORT()
141 int32_t range_list_find(const range_list* rl, uint32_t offset);
142 
143 
155 _EXPORT()
156 void* range_list_find_data(const range_list* rl, uint32_t offset);
157 
158 
177 _EXPORT()
178 bool range_list_split_element(range_list* rl, uint32_t index, uint32_t offset);
179 
180 
190 _EXPORT()
191 bool range_list_has_range(range_list* rl, uint32_t start, uint32_t length);
192 
193 #endif
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
uint32_t range_list_size(const range_list *rl)
Query the current number of elements on a range_list.
Definition: range_list.c:154
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
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
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
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
bool range_list_remove(range_list *rl, uint32_t index)
Removes an element from the list.
Definition: range_list.c:212
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 * range_list_new()
Allocates a new range_list.
Definition: range_list.c:125
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
Definition: range_list.h:43
XXX: document this.
Definition: range_list.h:52