diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2021-09-05 10:40:35 +0200 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2021-09-05 10:40:35 +0200 |
| commit | 1f5ce91ae21c975655a68d70714ab62434b914f6 (patch) | |
| tree | 1a3e50fdbb02f1bf9149459a6bac6f2fd1b13569 /core/math/big/internal.odin | |
| parent | d7627744dabd352aa09fc49c79a9466beec558ab (diff) | |
big: Add `internal_random_prime`.
Diffstat (limited to 'core/math/big/internal.odin')
| -rw-r--r-- | core/math/big/internal.odin | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/core/math/big/internal.odin b/core/math/big/internal.odin index 5b7e84a87..a0516be3d 100644 --- a/core/math/big/internal.odin +++ b/core/math/big/internal.odin @@ -2045,6 +2045,7 @@ internal_invmod :: proc{ internal_int_inverse_modulo, }; /* Helpers to extract values from the `Int`. + Offset is zero indexed. */ internal_int_bitfield_extract_bool :: proc(a: ^Int, offset: int) -> (val: bool, err: Error) { limb := offset / _DIGIT_BITS; @@ -2116,6 +2117,34 @@ internal_int_bitfield_extract :: proc(a: ^Int, offset, count: int) -> (res: _WOR } /* + Helpers to (un)set a bit in an Int. + Offset is zero indexed. +*/ +internal_int_bitfield_set_single :: proc(a: ^Int, offset: int) -> (err: Error) { + limb := offset / _DIGIT_BITS; + if limb < 0 || limb >= a.used { return .Invalid_Argument; } + i := DIGIT(1 << uint((offset % _DIGIT_BITS))); + a.digit[limb] |= i; + return; +} + +internal_int_bitfield_unset_single :: proc(a: ^Int, offset: int) -> (err: Error) { + limb := offset / _DIGIT_BITS; + if limb < 0 || limb >= a.used { return .Invalid_Argument; } + i := DIGIT(1 << uint((offset % _DIGIT_BITS))); + a.digit[limb] &= _MASK - i; + return; +} + +internal_int_bitfield_toggle_single :: proc(a: ^Int, offset: int) -> (err: Error) { + limb := offset / _DIGIT_BITS; + if limb < 0 || limb >= a.used { return .Invalid_Argument; } + i := DIGIT(1 << uint((offset % _DIGIT_BITS))); + a.digit[limb] ~= i; + return; +} + +/* Resize backing store. We don't need to pass the allocator, because the storage itself stores it. @@ -2817,7 +2846,7 @@ internal_int_random_digit :: proc(r: ^rnd.Rand = nil) -> (res: DIGIT) { return 0; // We shouldn't get here. } -internal_int_rand :: proc(dest: ^Int, bits: int, r: ^rnd.Rand = nil, allocator := context.allocator) -> (err: Error) { +internal_int_random :: proc(dest: ^Int, bits: int, r: ^rnd.Rand = nil, allocator := context.allocator) -> (err: Error) { context.allocator = allocator; bits := bits; @@ -2842,7 +2871,7 @@ internal_int_rand :: proc(dest: ^Int, bits: int, r: ^rnd.Rand = nil, allocator : dest.used = digits; return nil; } -internal_rand :: proc { internal_int_rand, }; +internal_random :: proc { internal_int_random, }; /* Internal helpers. |