-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
141 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "bigbit" | ||
version = "0.0.6" | ||
version = "0.0.7" | ||
authors = ["Kotauskas <[email protected]>"] | ||
edition = "2018" | ||
description = "Implements the BigBig format, allowing for compact storage of arbitrarily large numbers." | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use crate::LBString; | ||
use alloc::string::String; | ||
use core::cmp::Ordering; // We're not gonna deal with atomics here, right? | ||
|
||
impl PartialEq for LBString { | ||
#[inline(always)] | ||
fn eq(&self, rhs: &Self) -> bool { | ||
self.cmp(rhs) == Ordering::Equal | ||
} | ||
} | ||
impl Eq for LBString {} | ||
impl PartialOrd for LBString { | ||
#[inline(always)] | ||
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering> { | ||
Some(self.cmp(rhs)) | ||
} | ||
} | ||
impl Ord for LBString { | ||
#[inline] | ||
fn cmp(&self, rhs: &Self) -> Ordering { | ||
let (mut chars_l, mut chars_r) = (self.chars(), rhs.chars()); | ||
loop { | ||
let (l, r) = (chars_l.next(), chars_r.next()); | ||
if let Some(l_val) = l { | ||
if let Some(r_val) = r { | ||
match l_val.cmp(&r_val) { | ||
Ordering::Greater => {return Ordering::Greater;}, | ||
Ordering::Less => {return Ordering::Less;}, | ||
Ordering::Equal => {} | ||
} | ||
} else {return Ordering::Greater;} | ||
} else if r.is_some() {return Ordering::Less;} else {break;} | ||
} | ||
Ordering::Equal | ||
} | ||
} | ||
|
||
macro_rules! impl_pcmp_for_chars { | ||
($ty:ident) => { | ||
impl PartialEq<$ty> for LBString { | ||
#[inline(always)] | ||
fn eq(&self, rhs: &$ty) -> bool { | ||
self.partial_cmp(rhs) == Some(Ordering::Equal) | ||
} | ||
} | ||
impl PartialOrd<$ty> for LBString { | ||
fn partial_cmp(&self, rhs: &$ty) -> Option<Ordering> { | ||
let (mut chars_l, mut chars_r) = (self.chars(), rhs.chars()); | ||
loop { | ||
let (l, r) = (chars_l.next(), chars_r.next()); | ||
if let Some(l_val) = l { | ||
if let Some(r_val) = r { | ||
match l_val.cmp(&r_val) { | ||
Ordering::Greater => {return Some(Ordering::Greater);}, | ||
Ordering::Less => {return Some(Ordering::Less);}, | ||
Ordering::Equal => {} | ||
} | ||
} else {return Some(Ordering::Greater);} | ||
} else if r.is_some() {return Some(Ordering::Less);} else {break;} | ||
} | ||
Some(Ordering::Equal) | ||
} | ||
} | ||
|
||
impl PartialEq<LBString> for $ty { | ||
#[inline(always)] | ||
fn eq(&self, rhs: &LBString) -> bool { | ||
self.partial_cmp(rhs) == Some(Ordering::Equal) | ||
} | ||
} | ||
impl PartialOrd<LBString> for $ty { | ||
#[inline(always)] | ||
fn partial_cmp(&self, rhs: &LBString) -> Option<Ordering> { | ||
rhs.partial_cmp(self) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_pcmp_for_chars!(String); | ||
impl_pcmp_for_chars!(str); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use alloc::string::String; | ||
use crate::LBString; | ||
|
||
impl From<&String> for LBString { | ||
#[inline(always)] | ||
fn from(op: &String) -> Self { | ||
op.chars().collect::<Self>() | ||
} | ||
} | ||
impl From<String> for LBString { | ||
#[inline(always)] | ||
fn from(op: String) -> Self { | ||
op.chars().collect::<Self>() | ||
} | ||
} | ||
impl<'a> From<&'a str> for LBString { | ||
#[inline(always)] | ||
fn from(op: &'a str) -> Self { | ||
op.chars().collect::<Self>() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use alloc::string::String; | ||
use crate::LBString; | ||
|
||
impl From<LBString> for String { | ||
#[inline(always)] | ||
fn from(op: LBString) -> Self { | ||
op.chars().collect::<Self>() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod from; mod into; mod cmp; | ||
#[allow(unused_imports)] | ||
pub(crate) use {from::*, into::*, cmp::*}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// Uncomment when implementing arithmetics for these | ||
// Uncomment when implementing operations for these | ||
//pub(crate) mod headbyte; | ||
//pub(crate) mod extheadbyte; | ||
pub(crate) mod linkedbytes; | ||
pub(crate) mod linkedbytes; | ||
pub(crate) mod lbstring; |