Skip to content

Commit 88d5688

Browse files
committed
Fix the compilation
1 parent cba779c commit 88d5688

1 file changed

Lines changed: 47 additions & 50 deletions

File tree

  • roaring/src/bitmap/store/array_store

roaring/src/bitmap/store/array_store/mod.rs

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ mod visitor;
55
use crate::bitmap::store::array_store::visitor::{CardinalityCounter, VecWriter};
66
use core::cmp::Ordering;
77
use core::cmp::Ordering::*;
8+
use core::convert::identity;
89
use core::fmt::{Display, Formatter};
910
use core::mem::size_of;
1011
use core::ops::{BitAnd, BitAndAssign, BitOr, BitXor, RangeInclusive, Sub, SubAssign};
11-
use std::convert::identity;
1212

1313
#[cfg(not(feature = "std"))]
1414
use alloc::vec::Vec;
@@ -127,30 +127,28 @@ impl ArrayStore {
127127

128128
#[inline]
129129
pub fn insert(&mut self, index: u16) -> bool {
130-
if cfg!(feature = "simd") {
131-
vector::quad_search(&self.vec, index)
132-
} else {
133-
self.vec.binary_search(&index)
134-
}
135-
.map_err(|loc| self.vec.insert(loc, index))
136-
.is_err()
130+
#[cfg(feature = "simd")]
131+
let result = vector::quad_search(&self.vec, index);
132+
#[cfg(not(feature = "simd"))]
133+
let result = self.vec.binary_search(&index);
134+
result.map_err(|loc| self.vec.insert(loc, index)).is_err()
137135
}
138136

139137
pub fn insert_range(&mut self, range: RangeInclusive<u16>) -> u64 {
140138
let start = *range.start();
141139
let end = *range.end();
142140

143141
// Figure out the starting/ending position in the vec.
144-
let pos_start = if cfg!(feature = "simd") {
145-
vector::quad_search(&self.vec, start).unwrap_or_else(identity)
146-
} else {
147-
self.vec.binary_search(&start).unwrap_or_else(identity)
148-
};
149-
let pos_end_result = if cfg!(feature = "simd") {
150-
vector::quad_search(&self.vec[pos_start..], end)
151-
} else {
152-
self.vec[pos_start..].binary_search(&end)
153-
};
142+
#[cfg(feature = "simd")]
143+
let pos_start = vector::quad_search(&self.vec, start).unwrap_or_else(identity);
144+
#[cfg(not(feature = "simd"))]
145+
let pos_start = self.vec.binary_search(&start).unwrap_or_else(identity);
146+
147+
#[cfg(feature = "simd")]
148+
let pos_end_result = vector::quad_search(&self.vec[pos_start..], end);
149+
#[cfg(not(feature = "simd"))]
150+
let pos_end_result = self.vec[pos_start..].binary_search(&end);
151+
154152
let pos_end = match pos_end_result {
155153
Ok(x) => x + pos_start + 1,
156154
Err(x) => x + pos_start,
@@ -190,30 +188,29 @@ impl ArrayStore {
190188
}
191189

192190
pub fn remove(&mut self, index: u16) -> bool {
193-
if cfg!(feature = "simd") {
194-
vector::quad_search(&self.vec, index)
195-
} else {
196-
self.vec.binary_search(&index)
197-
}
198-
.map(|loc| self.vec.remove(loc))
199-
.is_ok()
191+
#[cfg(feature = "simd")]
192+
let result = vector::quad_search(&self.vec, index);
193+
#[cfg(not(feature = "simd"))]
194+
let result = self.vec.binary_search(&index);
195+
196+
result.map(|loc| self.vec.remove(loc)).is_ok()
200197
}
201198

202199
pub fn remove_range(&mut self, range: RangeInclusive<u16>) -> u64 {
203200
let start = *range.start();
204201
let end = *range.end();
205202

206203
// Figure out the starting/ending position in the vec.
207-
let pos_start = if cfg!(feature = "simd") {
208-
vector::quad_search(&self.vec, start).unwrap_or_else(identity)
209-
} else {
210-
self.vec.binary_search(&start).unwrap_or_else(identity)
211-
};
212-
let pos_end_result = if cfg!(feature = "simd") {
213-
vector::quad_search(&self.vec[pos_start..], end)
214-
} else {
215-
self.vec[pos_start..].binary_search(&end)
216-
};
204+
#[cfg(feature = "simd")]
205+
let pos_start = vector::quad_search(&self.vec, start).unwrap_or_else(identity);
206+
#[cfg(not(feature = "simd"))]
207+
let pos_start = self.vec.binary_search(&start).unwrap_or_else(identity);
208+
209+
#[cfg(feature = "simd")]
210+
let pos_end_result = vector::quad_search(&self.vec[pos_start..], end);
211+
#[cfg(not(feature = "simd"))]
212+
let pos_end_result = self.vec[pos_start..].binary_search(&end);
213+
217214
let pos_end = match pos_end_result {
218215
Ok(x) => x + pos_start + 1,
219216
Err(x) => x + pos_start,
@@ -233,11 +230,10 @@ impl ArrayStore {
233230
}
234231

235232
pub fn contains(&self, index: u16) -> bool {
236-
if cfg!(feature = "simd") {
237-
vector::quad_contains(&self.vec, index)
238-
} else {
239-
self.vec.binary_search(&index).is_ok()
240-
}
233+
#[cfg(feature = "simd")]
234+
return vector::quad_contains(&self.vec, index);
235+
#[cfg(not(feature = "simd"))]
236+
return self.vec.binary_search(&index).is_ok();
241237
}
242238

243239
pub fn contains_range(&self, range: RangeInclusive<u16>) -> bool {
@@ -248,11 +244,12 @@ impl ArrayStore {
248244
return false;
249245
}
250246

251-
let start_i = match if cfg!(feature = "simd") {
252-
vector::quad_search(&self.vec, start)
253-
} else {
254-
self.vec.binary_search(&start)
255-
} {
247+
#[cfg(feature = "simd")]
248+
let result = vector::quad_search(&self.vec, start);
249+
#[cfg(not(feature = "simd"))]
250+
let result = self.vec.binary_search(&start);
251+
252+
let start_i = match result {
256253
Ok(i) => i,
257254
Err(_) => return false,
258255
};
@@ -341,11 +338,11 @@ impl ArrayStore {
341338
}
342339

343340
pub fn rank(&self, index: u16) -> u64 {
344-
let result = if cfg!(feature = "simd") {
345-
vector::quad_search(&self.vec, index)
346-
} else {
347-
self.vec.binary_search(&index)
348-
};
341+
#[cfg(feature = "simd")]
342+
let result = vector::quad_search(&self.vec, index);
343+
#[cfg(not(feature = "simd"))]
344+
let result = self.vec.binary_search(&index);
345+
349346
match result {
350347
Ok(i) => i as u64 + 1,
351348
Err(i) => i as u64,

0 commit comments

Comments
 (0)