Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5564 | serge | 1 | /************************************************************************** |
2 | * |
||
3 | * Copyright 2009 VMware, Inc. |
||
4 | * All Rights Reserved. |
||
5 | * |
||
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
7 | * copy of this software and associated documentation files (the |
||
8 | * "Software"), to deal in the Software without restriction, including |
||
9 | * without limitation the rights to use, copy, modify, merge, publish, |
||
10 | * distribute, sub license, and/or sell copies of the Software, and to |
||
11 | * permit persons to whom the Software is furnished to do so, subject to |
||
12 | * the following conditions: |
||
13 | * |
||
14 | * The above copyright notice and this permission notice (including the |
||
15 | * next paragraph) shall be included in all copies or substantial portions |
||
16 | * of the Software. |
||
17 | * |
||
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||
20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
||
21 | * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
||
22 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||
23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||
24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
25 | * |
||
26 | **************************************************************************/ |
||
27 | |||
28 | /** |
||
29 | * @file |
||
30 | * Generic bitmask. |
||
31 | * |
||
32 | * @author Jose Fonseca |
||
33 | */ |
||
34 | |||
35 | #ifndef U_HANDLE_BITMASK_H_ |
||
36 | #define U_HANDLE_BITMASK_H_ |
||
37 | |||
38 | |||
39 | #include "pipe/p_compiler.h" |
||
40 | |||
41 | |||
42 | #ifdef __cplusplus |
||
43 | extern "C" { |
||
44 | #endif |
||
45 | |||
46 | |||
47 | #define UTIL_BITMASK_INVALID_INDEX (~0U) |
||
48 | |||
49 | |||
50 | /** |
||
51 | * Abstract data type to represent arbitrary set of bits. |
||
52 | */ |
||
53 | struct util_bitmask; |
||
54 | |||
55 | |||
56 | struct util_bitmask * |
||
57 | util_bitmask_create(void); |
||
58 | |||
59 | |||
60 | /** |
||
61 | * Search a cleared bit and set it. |
||
62 | * |
||
63 | * It searches for the first cleared bit. |
||
64 | * |
||
65 | * Returns the bit index on success, or UTIL_BITMASK_INVALID_INDEX on out of |
||
66 | * memory growing the bitmask. |
||
67 | */ |
||
68 | unsigned |
||
69 | util_bitmask_add(struct util_bitmask *bm); |
||
70 | |||
71 | /** |
||
72 | * Set a bit. |
||
73 | * |
||
74 | * Returns the input index on success, or UTIL_BITMASK_INVALID_INDEX on out of |
||
75 | * memory growing the bitmask. |
||
76 | */ |
||
77 | unsigned |
||
78 | util_bitmask_set(struct util_bitmask *bm, |
||
79 | unsigned index); |
||
80 | |||
81 | void |
||
82 | util_bitmask_clear(struct util_bitmask *bm, |
||
83 | unsigned index); |
||
84 | |||
85 | boolean |
||
86 | util_bitmask_get(struct util_bitmask *bm, |
||
87 | unsigned index); |
||
88 | |||
89 | |||
90 | void |
||
91 | util_bitmask_destroy(struct util_bitmask *bm); |
||
92 | |||
93 | |||
94 | /** |
||
95 | * Search for the first set bit. |
||
96 | * |
||
97 | * Returns UTIL_BITMASK_INVALID_INDEX if a set bit cannot be found. |
||
98 | */ |
||
99 | unsigned |
||
100 | util_bitmask_get_first_index(struct util_bitmask *bm); |
||
101 | |||
102 | |||
103 | /** |
||
104 | * Search for the first set bit, starting from the giving index. |
||
105 | * |
||
106 | * Returns UTIL_BITMASK_INVALID_INDEX if a set bit cannot be found. |
||
107 | */ |
||
108 | unsigned |
||
109 | util_bitmask_get_next_index(struct util_bitmask *bm, |
||
110 | unsigned index); |
||
111 | |||
112 | |||
113 | #ifdef __cplusplus |
||
114 | } |
||
115 | #endif |
||
116 | |||
117 | #endif /* U_HANDLE_BITMASK_H_ */ |