mirror of
https://gitlab.com/artofrev/smallint.git
synced 2024-11-14 09:21:15 -05:00
make heap_heap_return_* compatible with BigInt
This commit is contained in:
parent
b04ccea008
commit
1b4407ab45
38
src/logic.rs
38
src/logic.rs
|
@ -1,5 +1,6 @@
|
|||
use crate::smallint::SmallUintType;
|
||||
use crate::SmallUint;
|
||||
use crate::smallint::{SmallIntType, SmallUintType};
|
||||
use crate::{SmallInt, SmallUint};
|
||||
use core::cmp::Ordering;
|
||||
use core::mem::ManuallyDrop;
|
||||
use core::ops::{BitAnd, BitOr, BitXor};
|
||||
use core::ops::{BitAndAssign, BitOrAssign, BitXorAssign};
|
||||
|
@ -154,7 +155,7 @@ macro_rules! heap_heap_create_res_longest {
|
|||
macro_rules! heap_heap_return_heap {
|
||||
($typ:ident, $typ_inner:ident; $res:ident) => {
|
||||
let mut slice = ManuallyDrop::new($res.into_boxed_slice());
|
||||
$typ($typ_inner::Heap((slice.as_mut_ptr(), slice.len())))
|
||||
$typ($typ_inner::Heap((slice.as_mut_ptr(), slice.len().try_into().unwrap())))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,7 +174,7 @@ macro_rules! heap_heap_return_any {
|
|||
$typ($typ_inner::Inline(r))
|
||||
} else {
|
||||
let mut slice = ManuallyDrop::new($res.into_boxed_slice());
|
||||
$typ($typ_inner::Heap((slice.as_mut_ptr(), slice.len())))
|
||||
$typ($typ_inner::Heap((slice.as_mut_ptr(), slice.len().try_into().unwrap())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -203,3 +204,32 @@ logic_op! {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
logic_op! {
|
||||
BitXor, BitXorAssign, SmallInt, SmallIntType, bitxor, bitxor_assign;
|
||||
i, j, p, q, s, t;
|
||||
{
|
||||
todo!()
|
||||
},
|
||||
{
|
||||
match (s.cmp(&0), t.cmp(&0)) {
|
||||
(Ordering::Greater, Ordering::Greater) => {
|
||||
// as usize is equivalent to abs for non-negative isize
|
||||
let slice1 = unsafe { core::slice::from_raw_parts(p, s as usize) };
|
||||
let slice2 = unsafe { core::slice::from_raw_parts(q, t as usize) };
|
||||
|
||||
let min = std::cmp::min(slice1.len(), slice2.len());
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut res = { heap_heap_create_res_longest! { bitxor; slice1, slice2, min } };
|
||||
|
||||
heap_heap_return_any! { SmallInt, SmallIntType, i128; res }
|
||||
},
|
||||
(Ordering::Greater, Ordering::Less) => todo!(),
|
||||
(Ordering::Less, Ordering::Greater) => todo!(),
|
||||
(Ordering::Less, Ordering::Less) => todo!(),
|
||||
(Ordering::Equal, _) | (_, Ordering::Equal) => unreachable!("0 must be inline"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user