mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
DString reverse and an initial BigInt implementation (untested),
This commit is contained in:
@@ -467,6 +467,19 @@ fn void! out_string_append_fn(void* data, char c) @private
|
||||
s.append_char(c);
|
||||
}
|
||||
|
||||
fn void DString.reverse(self)
|
||||
{
|
||||
StringData *data = self.data();
|
||||
if (!data) return;
|
||||
isz mid = data.len / 2;
|
||||
for (isz i = 0; i < mid; i++)
|
||||
{
|
||||
char temp = data.chars[i];
|
||||
isz reverse_index = data.len - 1 - i;
|
||||
data.chars[i] = data.chars[reverse_index];
|
||||
data.chars[reverse_index] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
fn StringData* DString.data(self) @inline @private
|
||||
{
|
||||
|
||||
1111
lib/std/math/bigint.c3
Normal file
1111
lib/std/math/bigint.c3
Normal file
File diff suppressed because it is too large
Load Diff
@@ -82,6 +82,7 @@
|
||||
- Added MD5 and crypto::safe_compare.
|
||||
- Added generic HMAC.
|
||||
- Added generic PBKDF2 implementation.
|
||||
- DString `reverse`.
|
||||
|
||||
## 0.6.2 Change list
|
||||
|
||||
|
||||
@@ -10,6 +10,20 @@ fn void test_replace()
|
||||
assert(hello.str_view() == "Hello world where are yoooo? Are yoooo here too?");
|
||||
}
|
||||
|
||||
fn void test_reverse()
|
||||
{
|
||||
DString a;
|
||||
a.append("abcd");
|
||||
a.reverse();
|
||||
assert(a.str_view() == "dcba");
|
||||
a.reverse();
|
||||
assert(a.str_view() == "abcd");
|
||||
a.append("e");
|
||||
assert(a.str_view() == "abcde");
|
||||
a.reverse();
|
||||
assert(a.str_view() == "edcba");
|
||||
}
|
||||
|
||||
fn void test_delete()
|
||||
{
|
||||
{
|
||||
|
||||
34
test/unit/stdlib/math/bigint.c3
Normal file
34
test/unit/stdlib/math/bigint.c3
Normal file
@@ -0,0 +1,34 @@
|
||||
module std::math::bigint @test;
|
||||
|
||||
fn void test_plus()
|
||||
{
|
||||
BigInt a = bigint::from_int(123);
|
||||
BigInt b = bigint::from_int(234);
|
||||
assert(a.add(b).equals(bigint::from_int(234 + 123)));
|
||||
|
||||
a = bigint::from_int(12323400012311213314141414i128);
|
||||
b = bigint::from_int(23400012311213314141414i128);
|
||||
assert(a.add(b).equals(bigint::from_int(12323400012311213314141414i128 + 23400012311213314141414i128)));
|
||||
}
|
||||
|
||||
fn void test_minus()
|
||||
{
|
||||
BigInt a = bigint::from_int(123);
|
||||
BigInt b = bigint::from_int(234);
|
||||
assert(a.sub(b).equals(bigint::from_int(123 - 234)));
|
||||
|
||||
a = bigint::from_int(12323400012311213314141414i128);
|
||||
b = bigint::from_int(23400012311213314141414i128);
|
||||
assert(a.sub(b).equals(bigint::from_int(12323400012311213314141414i128 - 23400012311213314141414i128)));
|
||||
}
|
||||
|
||||
fn void test_init_string_radix()
|
||||
{
|
||||
BigInt a;
|
||||
a.init_string_radix("123", 10)!!;
|
||||
assert(a.equals(bigint::from_int(123)));
|
||||
a.init_string_radix("123", 8)!!;
|
||||
assert(a.equals(bigint::from_int(0o123)));
|
||||
a.init_string_radix("123", 16)!!;
|
||||
assert(a.equals(bigint::from_int(0x123)));
|
||||
}
|
||||
Reference in New Issue
Block a user