mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Simplify integer and float functions trait bounds
This commit is contained in:
parent
efbfa81fa7
commit
51767725b2
17 changed files with 217 additions and 521 deletions
|
@ -33,7 +33,7 @@ impl From<OrderedFloat<f64>> for FacetValue {
|
|||
|
||||
impl From<i64> for FacetValue {
|
||||
fn from(integer: i64) -> FacetValue {
|
||||
FacetValue::Number(integer as f64)
|
||||
FacetValue::Number(OrderedFloat(integer as f64))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,16 +13,6 @@ pub fn f64_into_bytes(float: f64) -> Option<[u8; 8]> {
|
|||
None
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn i64_into_bytes(int: i64) -> [u8; 8] {
|
||||
xor_first_bit(int.to_be_bytes())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn i64_from_bytes(bytes: [u8; 8]) -> i64 {
|
||||
i64::from_be_bytes(xor_first_bit(bytes))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn xor_first_bit(mut x: [u8; 8]) -> [u8; 8] {
|
||||
x[0] ^= 0x80;
|
||||
|
@ -55,15 +45,4 @@ mod tests {
|
|||
let vec: Vec<_> = [a, b, c, d, e].iter().cloned().map(f64_into_bytes).collect();
|
||||
assert!(is_sorted(&vec), "{:?}", vec);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_i64_bytes() {
|
||||
let a = -10_i64;
|
||||
let b = -0_i64;
|
||||
let c = 1_i64;
|
||||
let d = 43_i64;
|
||||
|
||||
let vec: Vec<_> = [a, b, c, d].iter().cloned().map(i64_into_bytes).collect();
|
||||
assert!(is_sorted(&vec), "{:?}", vec);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue