range-set: New function range_set_allocate_fully.
[pspp-builds.git] / src / libpspp / range-set.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2007, 2009 Free Software Foundation, Inc.
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, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 /* Bitmap, implemented as a balanced binary tree.
18
19    Each operation has O(lg N) cost, where N is the number of
20    contiguous regions of 1-bits in the bitmap.  Also, a cache
21    reduces the second and subsequent containment tests within a
22    single contiguous region to O(1). */
23
24 #ifndef LIBPSPP_RANGE_SET_H
25 #define LIBPSPP_RANGE_SET_H
26
27 #include <stdbool.h>
28
29 struct pool;
30
31 struct range_set *range_set_create (void);
32 struct range_set *range_set_create_pool (struct pool *);
33 struct range_set *range_set_clone (const struct range_set *, struct pool *);
34 void range_set_destroy (struct range_set *);
35
36 void range_set_insert (struct range_set *,
37                        unsigned long int start, unsigned long int width);
38 void range_set_delete (struct range_set *,
39                        unsigned long int start, unsigned long int width);
40 bool range_set_allocate (struct range_set *, unsigned long int request,
41                          unsigned long int *start, unsigned long int *width);
42 bool range_set_allocate_fully (struct range_set *, unsigned long int request,
43                                unsigned long int *start);
44 bool range_set_contains (const struct range_set *, unsigned long int position);
45
46 bool range_set_is_empty (const struct range_set *);
47
48 const struct range_set_node *range_set_first (const struct range_set *);
49 const struct range_set_node *range_set_next (const struct range_set *,
50                                              const struct range_set_node *);
51 unsigned long int range_set_node_get_start (const struct range_set_node *);
52 unsigned long int range_set_node_get_end (const struct range_set_node *);
53 unsigned long int range_set_node_get_width (const struct range_set_node *);
54
55 #endif /* libpspp/range-set.h */