2024-02-12 02:37:26 +00:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
class Utils {
|
|
|
|
static List<int> splitDigits(int number) {
|
|
|
|
final digits = <int>[];
|
|
|
|
while (number != 0) {
|
|
|
|
digits.add(number % 10);
|
|
|
|
number = number ~/ 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
return digits;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Uint8List serializeBigInt(BigInt bi) {
|
|
|
|
Uint8List array = Uint8List((bi.bitLength / 8).ceil());
|
|
|
|
for (int i = 0; i < array.length; i++) {
|
|
|
|
array[i] = (bi >> (i * 8)).toUnsigned(8).toInt();
|
|
|
|
}
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BigInt deserializeBigInt(Uint8List array) {
|
|
|
|
var bi = BigInt.zero;
|
|
|
|
for (var byte in array.reversed) {
|
|
|
|
bi <<= 8;
|
|
|
|
bi |= BigInt.from(byte);
|
|
|
|
}
|
|
|
|
return bi;
|
|
|
|
}
|
2024-03-01 18:22:57 +00:00
|
|
|
|
|
|
|
/// FOR ISAR, FROM ISAR DOCUMENTATION
|
|
|
|
/// FNV-1a 64bit hash algorithm optimized for Dart Strings
|
|
|
|
static int fastHash(String string) {
|
|
|
|
var hash = 0xcbf29ce484222325;
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
while (i < string.length) {
|
|
|
|
final codeUnit = string.codeUnitAt(i++);
|
|
|
|
hash ^= codeUnit >> 8;
|
|
|
|
hash *= 0x100000001b3;
|
|
|
|
hash ^= codeUnit & 0xFF;
|
|
|
|
hash *= 0x100000001b3;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
2024-02-12 02:37:26 +00:00
|
|
|
}
|