-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhanced Orthogonal Persistence: Refactor 64-bit Port of SLEB128 for …
…BigInt (#4486) * Refactor 64-bit port of SLEB128 for BigInt * Remove redundant test file
- Loading branch information
1 parent
588204f
commit 4e628b3
Showing
2 changed files
with
46 additions
and
12 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
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,44 @@ | ||
object Random { | ||
let max = 0xF_FFFF_FFFF_FFFF_FFFF; | ||
let seed = 4711; | ||
var number = seed; | ||
|
||
public func nextInt() : Int { | ||
let number = +nextNat(); | ||
let sign = if (number % 2 == 0) { -1 } else { +1 }; | ||
number * sign; | ||
}; | ||
|
||
public func nextNat() : Nat { | ||
number := (123138118391 * number + 133489131) % 9_999_999; | ||
(number * number) % max; | ||
}; | ||
}; | ||
|
||
func serializeInt(a : [Int]) : Blob = to_candid (a); | ||
func deserialzeInt(b : Blob) : ?[Int] = from_candid (b); | ||
|
||
func serializeNat(a : [Nat]) : Blob = to_candid (a); | ||
func deserialzeNat(b : Blob) : ?[Nat] = from_candid (b); | ||
|
||
let rounds = 100000; | ||
|
||
var count = 0; | ||
while (count < rounds) { | ||
let number = Random.nextInt(); | ||
assert ((?[number]) == deserialzeInt(serializeInt([number]))); | ||
count += 1; | ||
}; | ||
|
||
|
||
count := 0; | ||
while (count < rounds) { | ||
let number = Random.nextNat(); | ||
assert ((?[number]) == deserialzeNat(serializeNat([number]))); | ||
count += 1; | ||
}; | ||
|
||
|
||
//SKIP run | ||
//SKIP run-ir | ||
//SKIP run-low |