///|
/// Stable non-cryptographic fingerprint used for deterministic replay evidence.
///
/// This function is deliberately identical on every MoonBit backend. It is
/// intended for change detection and replay comparison, not for security.
pub fn fingerprint_text(text : String) -> Int {
// Keep `value * 257` below the signed 32-bit limit on every backend.
let modulo = 8000009
let mut value = 216613
for i = 0; i < text.length(); i = i + 1 {
value = (value * 257 + text.unsafe_get(i).to_int() + 1) % modulo
}
value
}
///|
/// Combines journal metadata and an application-provided payload fingerprint.
pub fn event_fingerprint(
previous_hash : Int,
sequence : Int,
kind : String,
correlation_id : String,
payload_fingerprint : String,
) -> Int {
fingerprint_text(
"\{previous_hash}|\{sequence}|\{kind}|\{correlation_id}|\{payload_fingerprint}",
)
}