@@ -3,7 +3,7 @@ use core::{intrinsics::unlikely, marker::PhantomData};
3
3
use crate :: traits:: BitOps ;
4
4
5
5
#[ derive( Debug , Clone ) ]
6
- pub ( crate ) struct BitMapCore < T : BitOps > {
6
+ pub struct BitMapCore < T : BitOps > {
7
7
phantom : PhantomData < T > ,
8
8
}
9
9
@@ -15,7 +15,7 @@ impl<T: BitOps> BitMapCore<T> {
15
15
}
16
16
17
17
/// 获取位图中的某一位
18
- pub ( crate ) fn get ( & self , n : usize , data : & [ T ] , index : usize ) -> Option < bool > {
18
+ pub fn get ( & self , n : usize , data : & [ T ] , index : usize ) -> Option < bool > {
19
19
if unlikely ( index >= n) {
20
20
return None ;
21
21
}
@@ -30,7 +30,7 @@ impl<T: BitOps> BitMapCore<T> {
30
30
}
31
31
32
32
/// 设置位图中的某一位
33
- pub ( crate ) fn set ( & self , n : usize , data : & mut [ T ] , index : usize , value : bool ) -> Option < bool > {
33
+ pub fn set ( & self , n : usize , data : & mut [ T ] , index : usize , value : bool ) -> Option < bool > {
34
34
if unlikely ( index >= n) {
35
35
return None ;
36
36
}
@@ -43,7 +43,7 @@ impl<T: BitOps> BitMapCore<T> {
43
43
Some ( bit)
44
44
}
45
45
46
- pub ( crate ) fn set_all ( & self , n : usize , data : & mut [ T ] , value : bool ) {
46
+ pub fn set_all ( & self , n : usize , data : & mut [ T ] , value : bool ) {
47
47
let val = if value { T :: max ( ) } else { T :: zero ( ) } ;
48
48
for element in data. iter_mut ( ) {
49
49
* element = val;
@@ -58,7 +58,7 @@ impl<T: BitOps> BitMapCore<T> {
58
58
}
59
59
60
60
/// 获取位图中第一个为1的位
61
- pub ( crate ) fn first_index ( & self , data : & [ T ] ) -> Option < usize > {
61
+ pub fn first_index ( & self , data : & [ T ] ) -> Option < usize > {
62
62
for ( i, element) in data. iter ( ) . enumerate ( ) {
63
63
let bit = <T as BitOps >:: first_index ( element) ;
64
64
if let Some ( b) = bit {
@@ -70,7 +70,7 @@ impl<T: BitOps> BitMapCore<T> {
70
70
}
71
71
72
72
/// 获取位图中第一个为0的位
73
- pub ( crate ) fn first_false_index ( & self , n : usize , data : & [ T ] ) -> Option < usize > {
73
+ pub fn first_false_index ( & self , n : usize , data : & [ T ] ) -> Option < usize > {
74
74
for ( i, element) in data. iter ( ) . enumerate ( ) {
75
75
if let Some ( bit) = <T as BitOps >:: first_false_index ( element) {
76
76
return self . make_index ( n, i * T :: bit_size ( ) + bit) ;
@@ -81,7 +81,7 @@ impl<T: BitOps> BitMapCore<T> {
81
81
}
82
82
83
83
/// 获取位图中最后一个为1的位
84
- pub ( crate ) fn last_index ( & self , n : usize , data : & [ T ] ) -> Option < usize > {
84
+ pub fn last_index ( & self , n : usize , data : & [ T ] ) -> Option < usize > {
85
85
for ( i, element) in data. iter ( ) . enumerate ( ) . rev ( ) {
86
86
if let Some ( bit) = <T as BitOps >:: last_index ( element) {
87
87
return self . make_index ( n, i * T :: bit_size ( ) + bit) ;
@@ -97,7 +97,7 @@ impl<T: BitOps> BitMapCore<T> {
97
97
///
98
98
/// - `data`:位图数据
99
99
/// - `n`:位图有效位数
100
- pub ( crate ) fn last_false_index ( & self , n : usize , data : & [ T ] ) -> Option < usize > {
100
+ pub fn last_false_index ( & self , n : usize , data : & [ T ] ) -> Option < usize > {
101
101
let mut iter = data. iter ( ) . rev ( ) ;
102
102
let mut last_element = * iter. next ( ) ?;
103
103
@@ -123,7 +123,7 @@ impl<T: BitOps> BitMapCore<T> {
123
123
}
124
124
125
125
/// 获取位图中下一个为1的位
126
- pub ( crate ) fn next_index ( & self , n : usize , data : & [ T ] , index : usize ) -> Option < usize > {
126
+ pub fn next_index ( & self , n : usize , data : & [ T ] , index : usize ) -> Option < usize > {
127
127
if unlikely ( index >= n) {
128
128
return None ;
129
129
}
@@ -146,7 +146,7 @@ impl<T: BitOps> BitMapCore<T> {
146
146
}
147
147
148
148
/// 获取位图中下一个为0的位
149
- pub ( crate ) fn next_false_index ( & self , n : usize , data : & [ T ] , index : usize ) -> Option < usize > {
149
+ pub fn next_false_index ( & self , n : usize , data : & [ T ] , index : usize ) -> Option < usize > {
150
150
if unlikely ( index >= n) {
151
151
return None ;
152
152
}
@@ -169,7 +169,7 @@ impl<T: BitOps> BitMapCore<T> {
169
169
}
170
170
171
171
/// 获取位图中上一个为1的位
172
- pub ( crate ) fn prev_index ( & self , n : usize , data : & [ T ] , index : usize ) -> Option < usize > {
172
+ pub fn prev_index ( & self , n : usize , data : & [ T ] , index : usize ) -> Option < usize > {
173
173
if unlikely ( index >= n) {
174
174
return None ;
175
175
}
@@ -190,7 +190,7 @@ impl<T: BitOps> BitMapCore<T> {
190
190
None
191
191
}
192
192
193
- pub ( crate ) fn prev_false_index ( & self , n : usize , data : & [ T ] , index : usize ) -> Option < usize > {
193
+ pub fn prev_false_index ( & self , n : usize , data : & [ T ] , index : usize ) -> Option < usize > {
194
194
let element_index = index / T :: bit_size ( ) ;
195
195
let bit_index = index % T :: bit_size ( ) ;
196
196
@@ -208,7 +208,7 @@ impl<T: BitOps> BitMapCore<T> {
208
208
None
209
209
}
210
210
211
- pub ( crate ) fn invert ( & self , n : usize , data : & mut [ T ] ) {
211
+ pub fn invert ( & self , n : usize , data : & mut [ T ] ) {
212
212
for element in data. iter_mut ( ) {
213
213
<T as BitOps >:: invert ( element) ;
214
214
}
@@ -222,7 +222,7 @@ impl<T: BitOps> BitMapCore<T> {
222
222
}
223
223
}
224
224
225
- pub ( crate ) fn is_full ( & self , n : usize , data : & [ T ] ) -> bool {
225
+ pub fn is_full ( & self , n : usize , data : & [ T ] ) -> bool {
226
226
let mut iter = data. iter ( ) . peekable ( ) ;
227
227
while let Some ( element) = iter. next ( ) {
228
228
if iter. peek ( ) . is_none ( ) {
@@ -245,7 +245,7 @@ impl<T: BitOps> BitMapCore<T> {
245
245
return false ;
246
246
}
247
247
248
- pub ( crate ) fn is_empty ( & self , data : & [ T ] ) -> bool {
248
+ pub fn is_empty ( & self , data : & [ T ] ) -> bool {
249
249
for element in data. iter ( ) {
250
250
if element != & T :: zero ( ) {
251
251
return false ;
0 commit comments