xref: /haiku/headers/private/kernel/util/RadixBitmap.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
1 /*-
2  * Copyright (c) 1998 Matthew Dillon.  All Rights Reserved.
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions
5  * are met:
6  * 1. Redistributions of source code must retain the above copyright
7  *    notice, this list of conditions and the following disclaimer.
8  * 2. Redistributions in binary form must reproduce the above copyright
9  *    notice, this list of conditions and the following disclaimer in the
10  *    documentation and/or other materials provided with the distribution.
11  * 4. Neither the name of the University nor the names of its contributors
12  *    may be used to endorse or promote products derived from this software
13  *    without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /*
29  * The radix bitmap structure is ported from FreeBSD and is only used
30  * in swap system at the time.
31  */
32 
33 
34 #ifndef _KERNEL_UTIL_RADIX_BITMAP_H
35 #define _KERNEL_UTIL_RADIX_BITMAP_H
36 
37 
38 #include <SupportDefs.h>
39 
40 
41 typedef uint32 swap_addr_t;
42 typedef uint32 bitmap_t;
43 
44 typedef struct radix_node {
45 	union {
46 		bitmap_t  bitmap;      // bitmap for the slots if we are a leaf
47 		int32     available;   // available slots under us if we are not a leaf
48 	} u;
49 	int32  big_hint;  // the biggest continuous slots under us
50 } radix_node;
51 
52 // Bitmap which uses radix tree for hinting.
53 // The radix tree is stored in an array.
54 typedef struct radix_bitmap {
55 	swap_addr_t   free_slots;     // # of free slots
56 	swap_addr_t   radix;          // coverage radix
57 	swap_addr_t   skip;           // starting skip
58 	radix_node    *root;          // root of radix tree, actually it is an array
59 	swap_addr_t	  root_size;      // size of the array(# of nodes in the tree)
60 } radix_bitmap;
61 
62 
63 #define BITMAP_RADIX  (sizeof(swap_addr_t) * 8)
64 #define NODE_RADIX    16
65 
66 #define SWAP_SLOT_NONE ((swap_addr_t)-1)
67 
68 
69 extern radix_bitmap *radix_bitmap_create(uint32 slots);
70 extern swap_addr_t radix_bitmap_alloc(radix_bitmap *bmp, uint32 count);
71 extern void radix_bitmap_dealloc(radix_bitmap *bmp, swap_addr_t slotIndex,
72 		uint32 count);
73 extern void radix_bitmap_destroy(radix_bitmap *bmp);
74 
75 #endif  // _KERNEL_UTIL_RADIX_BITMAP_H
76 
77