#![cfg(not(feature = "compact"))]
#![cfg(feature = "power-of-two")]
#![doc(hidden)]
use lexical_util::format;
use lexical_util::num::{Integer, UnsignedInteger};
use crate::algorithm::{algorithm, algorithm_u128};
use crate::table::get_table;
pub trait Radix: UnsignedInteger {
fn radix<const FORMAT: u128, const MASK: u128, const SHIFT: i32>(
self,
buffer: &mut [u8],
) -> usize;
}
macro_rules! radix_impl {
($($t:ty)*) => ($(
impl Radix for $t {
#[inline(always)]
fn radix<const FORMAT: u128, const MASK: u128, const SHIFT: i32>(
self,
buffer: &mut [u8]
) -> usize {
debug_assert!(<Self as Integer>::BITS <= 64);
let radix = format::radix_from_flags(FORMAT, MASK, SHIFT);
let table = get_table::<FORMAT, MASK, SHIFT>();
algorithm(self, radix, table, buffer)
}
}
)*);
}
radix_impl! { u8 u16 u32 u64 usize }
impl Radix for u128 {
#[inline(always)]
fn radix<const FORMAT: u128, const MASK: u128, const SHIFT: i32>(
self,
buffer: &mut [u8],
) -> usize {
let table = get_table::<FORMAT, MASK, SHIFT>();
algorithm_u128::<FORMAT, MASK, SHIFT>(self, table, buffer)
}
}