1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::mem;
use smallvec::SmallVec;
#[derive(Hash, Eq, PartialEq, Clone, Debug)]
pub struct Ubig<const S: usize>(SmallVec<[usize; S]>);
#[derive(Hash, Eq, PartialEq, Clone, Debug)]
pub struct NonZeroUbig<const S: usize>(SmallVec<[usize; S]>);
pub mod io;
pub mod ops;
pub mod properties;
impl<const S: usize> Ubig<S> {
pub(crate) unsafe fn is_well_formed(&self) -> bool {
match self.0.last() {
None => true,
Some(&value) => value != 0,
}
}
pub(crate) fn inner(&self) -> &SmallVec<[usize; S]> {
&self.0
}
pub(crate) unsafe fn inner_mut(&mut self) -> &mut SmallVec<[usize; S]> {
&mut self.0
}
pub(crate) fn into_inner(self) -> SmallVec<[usize; S]> {
self.0
}
}
impl<const S: usize> NonZeroUbig<S> {
pub(crate) unsafe fn is_well_formed(&self) -> bool {
match self.0.last() {
None => false,
Some(&value) => value != 0,
}
}
pub(crate) fn inner(&self) -> &SmallVec<[usize; S]> {
&self.0
}
pub(crate) unsafe fn inner_mut(&mut self) -> &mut SmallVec<[usize; S]> {
&mut self.0
}
pub(crate) fn first(&self) -> &usize {
unsafe {
self.0.get_unchecked(0)
}
}
pub(crate) unsafe fn first_mut(&mut self) -> &mut usize {
self.0.get_unchecked_mut(0)
}
pub(crate) fn into_inner(self) -> SmallVec<[usize; S]> {
self.0
}
}
pub const BITS_PER_WORD: u32 = (mem::size_of::<usize>() * 8) as u32;