1b9fea50ea428d4d521d9983bb52d1aae744fd1c
[pspp-builds.git] / src / libpspp / range-set.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 2007 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or
5    modify it under the terms of the GNU General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    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, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17    02110-1301, USA. */
18
19 /* Bitmap, implemented as a balanced binary tree.
20
21    Each operation has O(lg N) cost, where N is the number of
22    contiguous regions of 1-bits in the bitmap.  Also, a cache
23    reduces the second and subsequent containment tests within a
24    single contiguous region to O(1). */
25
26 #ifndef LIBPSPP_RANGE_SET_H
27 #define LIBPSPP_RANGE_SET_H
28
29 #include <stdbool.h>
30
31 struct pool;
32
33 struct range_set *range_set_create (void);
34 struct range_set *range_set_create_pool (struct pool *);
35 struct range_set *range_set_clone (const struct range_set *, struct pool *);
36 void range_set_destroy (struct range_set *);
37
38 void range_set_insert (struct range_set *,
39                        unsigned long int start, unsigned long int width);
40 void range_set_delete (struct range_set *,
41                        unsigned long int start, unsigned long int width);
42 bool range_set_allocate (struct range_set *, unsigned long int request,
43                          unsigned long int *start, unsigned long int *width);
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 */