Skip to content

Commit

Permalink
rework (autosave)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Mar 13, 2021
1 parent 61a65f9 commit f681d8f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rust/arrow/src/array/array_decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<T: ArrowDecimalType> fmt::Debug for DecimalArray<T> {
}
}

impl<T: ArrowDecimalType> Array for DecimalArray<T> {
impl<T: 'static + ArrowDecimalType> Array for DecimalArray<T> {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down
12 changes: 6 additions & 6 deletions rust/arrow/src/datatypes/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ macro_rules! make_type {
#[inline(always)]
fn rescale_to_new(self, scale: usize) -> $name {
if self.digits.is_zero() {
return $name::new(0, 0, scale);
return $name::new(<$native_ty>::zero(), 0, scale);
}

let digits = match self.scale.cmp(&scale) {
Expand Down Expand Up @@ -378,7 +378,7 @@ macro_rules! make_type {

let mut result = String::new();

if self.digits < 0 {
if self.digits.le(&<$native_ty>::zero()) {
result.push_str("-")
}

Expand Down Expand Up @@ -407,12 +407,12 @@ macro_rules! make_type {
impl Zero for $name {
#[inline]
fn zero() -> $name {
$name::new(0, 1, 0)
$name::new(<$native_ty>::zero(), 1, 0)
}

#[inline]
fn is_zero(&self) -> bool {
self.digits == 0
self.digits.is_zero()
}
}

Expand Down Expand Up @@ -593,7 +593,7 @@ macro_rules! make_type {
None => {
let digits = s.parse::<$native_ty>()?;

if digits < 0 {
if digits.le(&<$native_ty>::zero()) {
(s.parse::<$native_ty>()?, s.len() - 1, 0)
} else {
(s.parse::<$native_ty>()?, s.len(), 0)
Expand All @@ -608,7 +608,7 @@ macro_rules! make_type {

let digits = parts.parse::<$native_ty>()?;

if digits < 0 {
if digits.lt(&<$native_ty>::zero()) {
(digits, lead.len() - 1, trail.len())
} else {
(digits, lead.len(), trail.len())
Expand Down
63 changes: 57 additions & 6 deletions rust/arrow/src/datatypes/i256_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
use crate::alloc::NativeType;
use crate::datatypes::DataType;
use num::Zero;
use std::cmp::Ordering;
use std::cmp::{Ordering};
use std::fmt;
use std::num::ParseIntError;
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
use std::str::FromStr;

/// Number of bits a signed 256-bit number occupies.
pub const BITS: usize = 256;

/// Number of bytes a signed 256-bit number occupies.
pub const BYTES: usize = 32;

/// An signed 256-bit number.
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
/// An signed 256-bit number. Rust language doesnt provide i256, for now It's a polyfill.
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
pub(crate) struct i256 {
#[cfg(target_endian = "little")]
lo: u128,
Expand All @@ -40,9 +42,23 @@ pub(crate) struct i256 {
lo: u128,
}

impl i256 {
pub fn to_le_bytes(self) -> [u8; 32] {
unimplemented!();
}

pub fn to_be_bytes(self) -> [u8; 32] {
unimplemented!();
}

pub fn abs(self) -> Self {
unimplemented!();
}
}

impl Default for i256 {
fn default() -> Self {
i256 { lo: 0, hi: 0 }
i256::zero()
}
}

Expand All @@ -52,6 +68,33 @@ impl fmt::Display for i256 {
}
}

impl Ord for i256 {
fn cmp(&self, other: &Self) -> Ordering {
unimplemented!()
}

fn max(self, other: Self) -> Self
where
Self: Sized,
{
unimplemented!()
}

fn min(self, other: Self) -> Self
where
Self: Sized,
{
unimplemented!()
}

fn clamp(self, min: Self, max: Self) -> Self
where
Self: Sized,
{
unimplemented!()
}
}

impl PartialOrd for i256 {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
unimplemented!()
Expand All @@ -74,13 +117,21 @@ impl PartialOrd for i256 {
}
}

impl FromStr for i256 {
type Err = ParseIntError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
unimplemented!()
}
}

impl Zero for i256 {
fn zero() -> Self {
unimplemented!()
i256 { lo: 0, hi: 0 }
}

fn is_zero(&self) -> bool {
unimplemented!()
self.lo == 0 && self.hi == 0
}
}

Expand Down

0 comments on commit f681d8f

Please sign in to comment.