Skip to main content

cjc_runtime/
lib.rs

1//! CJC Runtime System
2//!
3//! This crate provides the core runtime infrastructure for the CJC deterministic
4//! numerical programming language. It is the largest crate in the workspace and
5//! underpins both the AST tree-walk interpreter (`cjc-eval`) and the MIR register
6//! machine executor (`cjc-mir-exec`).
7//!
8//! # Core Abstractions
9//!
10//! - [`Buffer<T>`] -- Deterministic memory allocation with COW (copy-on-write)
11//!   semantics. Cloning is O(1); mutation triggers a deep copy only when shared.
12//! - [`Tensor`] -- N-dimensional tensor backed by `Buffer<f64>`. Supports
13//!   element-wise arithmetic (SIMD-accelerated), matrix multiplication (tiled +
14//!   parallel), and numerically-stable reductions via [`BinnedAccumulatorF64`].
15//! - [`Value`] -- The universal tagged-union value type that flows through both
16//!   interpreters. Covers scalars, strings, tensors, closures, structs, enums,
17//!   and opaque type-erased objects (AD graphs, tidy views, quantum states).
18//! - [`RuntimeError`] -- Error type for all fallible runtime operations.
19//!
20//! # Determinism Guarantees
21//!
22//! - All floating-point reductions use Kahan or [`BinnedAccumulatorF64`] summation.
23//! - Ordered containers only ([`BTreeMap`]/[`BTreeSet`]) -- no `HashMap`/`HashSet`.
24//! - [`DetMap`] provides a deterministic hash map with [`murmurhash3`] hashing.
25//! - SIMD kernels avoid hardware FMA for bit-identical cross-platform results.
26//! - RNG is SplitMix64 with explicit seed threading (`cjc-repro`).
27//!
28//! # Memory Model
29//!
30//! - **NoGC tier:** [`Buffer<T>`], [`Tensor`], [`AlignedByteSlice`] -- zero GC
31//!   overhead, COW semantics.
32//! - **GC tier:** [`GcHeap`] / [`GcRef`] -- RC-backed object slab for class
33//!   instances.
34//! - **Arena tier:** [`FrameArena`] / [`ArenaStore`] -- bump allocation per
35//!   function frame for non-escaping temporaries.
36//!
37//! # Module Organization
38//!
39//! | Layer | Modules |
40//! |-------|---------|
41//! | Core types | [`value`], [`error`], [`buffer`], [`tensor`], [`tensor_dtype`] |
42//! | Builtins | [`builtins`] -- shared stateless dispatch for both executors |
43//! | Accumulation | [`accumulator`], [`dispatch`] |
44//! | Linear algebra | [`linalg`], [`sparse`], [`sparse_solvers`], [`sparse_eigen`] |
45//! | Statistics | [`stats`], [`distributions`], [`hypothesis`] |
46//! | Data | [`json`], [`datetime`], [`window`], [`timeseries`] |
47//! | ML / NN | [`ml`], [`fft`], [`clustering`], [`optimize`], [`interpolate`] |
48//! | Memory | [`gc`], [`object_slab`], [`frame_arena`], [`binned_alloc`], [`aligned_pool`] |
49//! | SIMD / Perf | [`tensor_simd`], [`tensor_tiled`], [`tensor_pool`] |
50//!
51//! [`BinnedAccumulatorF64`]: accumulator::BinnedAccumulatorF64
52//! [`BTreeMap`]: std::collections::BTreeMap
53//! [`BTreeSet`]: std::collections::BTreeSet
54
55// --- Core standalone modules ---
56
57/// BinnedAccumulator for order-invariant deterministic floating-point summation.
58pub mod accumulator;
59/// Complex number arithmetic with deterministic fixed-sequence operations.
60pub mod complex;
61/// Hybrid summation strategy dispatch (Kahan vs Binned) based on execution context.
62pub mod dispatch;
63/// IEEE 754 half-precision (f16) floating-point type.
64pub mod f16;
65/// Quantized tensor storage (4-bit, 8-bit) for memory-efficient inference.
66pub mod quantized;
67
68// --- Shared builtin dispatch (used by both cjc-eval and cjc-mir-exec) ---
69
70/// Stateless builtin function dispatch shared by both interpreters.
71///
72/// Every builtin registered here is callable from CJC source code. Functions
73/// that require interpreter state (print, GC, clock, RNG) stay in the
74/// individual executors.
75pub mod builtins;
76
77// --- Core data structures ---
78
79/// COW (copy-on-write) buffer -- the memory primitive under [`Tensor`].
80pub mod buffer;
81/// N-dimensional tensor with element-wise, reduction, linalg, and NN operations.
82pub mod tensor;
83/// Deterministic binary serialization for tensors and tensor lists.
84pub mod tensor_snap;
85/// Pre-allocated KV-cache scratchpad for zero-allocation transformer inference.
86pub mod scratchpad;
87/// 16-byte-aligned memory pool for SIMD-friendly byte buffers.
88pub mod aligned_pool;
89/// Internal bridge to compiled SIMD/tiled kernel functions.
90mod kernel_bridge;
91pub use kernel_bridge::kernel;
92/// Block-paged KV-cache (vLLM-style) for efficient autoregressive decoding.
93pub mod paged_kv;
94/// Size-class binned allocator for deterministic memory management.
95pub mod binned_alloc;
96/// Bump-arena per function frame for non-escaping temporaries.
97pub mod frame_arena;
98/// RC-backed object slab for class instances (replaces mark-sweep GC).
99pub mod object_slab;
100/// GC heap abstraction wrapping the RC-backed object slab.
101pub mod gc;
102/// Sparse matrix types: CSR and COO representations.
103pub mod sparse;
104/// Direct sparse solvers (LU factorization, triangular solve).
105pub mod sparse_solvers;
106/// L2-cache-friendly tiled matrix multiplication engine.
107pub mod tensor_tiled;
108/// AVX2 SIMD kernels for element-wise and unary tensor operations.
109pub mod tensor_simd;
110/// Tensor memory pool for reducing allocation pressure in hot loops.
111pub mod tensor_pool;
112/// Deterministic hash map using MurmurHash3 -- iteration order is fixed.
113pub mod det_map;
114/// Dense linear algebra: determinant, solve, eigenvalues, SVD, QR, LU.
115pub mod linalg;
116/// The universal [`Value`] tagged union and supporting types ([`Bf16`], [`FnValue`]).
117pub mod value;
118/// [`RuntimeError`] enum for all fallible runtime operations.
119pub mod error;
120/// Library registry for module-system symbol lookup.
121pub mod lib_registry;
122/// JSON parse/stringify builtins for CJC values.
123pub mod json;
124/// Pure-arithmetic datetime manipulation (epoch-based, no system clock).
125pub mod datetime;
126/// Rolling window aggregations (sum, mean, min, max).
127pub mod window;
128/// Descriptive and inferential statistics functions.
129pub mod stats;
130/// Probability distribution functions (CDF, PDF, PPF) for Normal, t, chi2, F.
131pub mod distributions;
132/// Hypothesis testing: t-test, chi-squared test, paired t-test.
133pub mod hypothesis;
134/// Machine learning loss functions and optimizer state types.
135pub mod ml;
136/// Fast Fourier Transform (radix-2 Cooley-Tukey).
137pub mod fft;
138/// Time-series stationarity tests (ADF).
139pub mod stationarity;
140/// ODE solver primitives (Euler, RK4 step functions).
141pub mod ode;
142/// Sparse eigenvalue solvers (Lanczos, Arnoldi).
143pub mod sparse_eigen;
144/// Interpolation primitives (linear, cubic spline).
145pub mod interpolate;
146/// Numerical optimization (gradient descent, L-BFGS, Nelder-Mead).
147pub mod optimize;
148/// Clustering algorithms (k-means, DBSCAN).
149pub mod clustering;
150/// Typed tensor storage: [`DType`] enum and byte-first [`TypedStorage`].
151pub mod tensor_dtype;
152/// Time-series analysis utilities (autocorrelation, differencing).
153pub mod timeseries;
154/// Numerical integration (trapezoidal, Simpson's rule).
155pub mod integrate;
156/// Numerical differentiation (finite differences).
157pub mod differentiate;
158/// Deterministic profile counters (Tier 2 of Chess RL v2.3). Write-only
159/// timing sink that does not perturb program state, RNG, or weight hashes.
160pub mod profile;
161
162// --- Re-exports for backward compatibility ---
163// All downstream crates that were doing `use cjc_runtime::Tensor` etc. continue to work.
164
165/// Re-export: COW buffer with deterministic copy-on-write semantics.
166pub use buffer::Buffer;
167/// Re-export: N-dimensional tensor -- the primary numerical type.
168pub use tensor::Tensor;
169/// Re-export: Pre-allocated KV-cache scratchpad.
170pub use scratchpad::Scratchpad;
171/// Re-export: 16-byte-aligned memory pool and byte slice.
172pub use aligned_pool::{AlignedPool, AlignedByteSlice};
173/// Re-export: Block-paged KV-cache types.
174pub use paged_kv::{KvBlock, PagedKvCache};
175/// Re-export: GC heap and reference types.
176pub use gc::{GcRef, GcHeap};
177/// Re-export: Size-class binned allocator.
178pub use binned_alloc::BinnedAllocator;
179/// Re-export: Bump-arena and arena store types.
180pub use frame_arena::{FrameArena, ArenaStore};
181/// Re-export: Object slab and slab reference types.
182pub use object_slab::{ObjectSlab, SlabRef};
183/// Re-export: Sparse matrix types (CSR and COO).
184pub use sparse::{SparseCsr, SparseCoo};
185/// Re-export: Tiled matrix multiplication engine.
186pub use tensor_tiled::TiledMatmul;
187/// Re-export: Deterministic map, MurmurHash3, and value hashing utilities.
188pub use det_map::{DetMap, murmurhash3, murmurhash3_finalize, value_hash, values_equal_static};
189/// Re-export: Universal value type and supporting types.
190pub use value::{Value, Bf16, FnValue};
191/// Re-export: Runtime error type.
192pub use error::RuntimeError;
193/// Re-export: Typed tensor storage types.
194pub use tensor_dtype::{DType, TypedStorage};
195
196// ---------------------------------------------------------------------------
197// Tests — remain here so they can use `super::*` to access all re-exports.
198// ---------------------------------------------------------------------------
199
200#[cfg(test)]
201mod tests {
202    use super::*;
203    use std::rc::Rc;
204    use cjc_repro::Rng;
205
206    // -- Buffer tests -------------------------------------------------------
207
208    #[test]
209    fn test_buffer_alloc_get_set() {
210        let mut buf = Buffer::alloc(5, 0.0f64);
211        assert_eq!(buf.len(), 5);
212        assert_eq!(buf.get(0), Some(0.0));
213        assert_eq!(buf.get(4), Some(0.0));
214        assert_eq!(buf.get(5), None);
215
216        buf.set(2, 42.0).unwrap();
217        assert_eq!(buf.get(2), Some(42.0));
218
219        assert!(buf.set(10, 1.0).is_err());
220    }
221
222    #[test]
223    fn test_buffer_from_vec() {
224        let buf = Buffer::from_vec(vec![1, 2, 3, 4, 5]);
225        assert_eq!(buf.len(), 5);
226        assert_eq!(buf.get(0), Some(1));
227        assert_eq!(buf.get(4), Some(5));
228        assert_eq!(buf.as_slice(), vec![1, 2, 3, 4, 5]);
229    }
230
231    #[test]
232    fn test_buffer_cow_behavior() {
233        let buf_a = Buffer::from_vec(vec![10, 20, 30]);
234        let mut buf_b = buf_a.clone();
235
236        assert_eq!(buf_a.refcount(), 2);
237        assert_eq!(buf_b.refcount(), 2);
238
239        buf_b.set(0, 99).unwrap();
240
241        assert_eq!(buf_a.refcount(), 1);
242        assert_eq!(buf_b.refcount(), 1);
243        assert_eq!(buf_a.get(0), Some(10));
244        assert_eq!(buf_b.get(0), Some(99));
245    }
246
247    #[test]
248    fn test_buffer_clone_buffer_forces_deep_copy() {
249        let buf_a = Buffer::from_vec(vec![1, 2, 3]);
250        let buf_b = buf_a.clone_buffer();
251
252        assert_eq!(buf_a.refcount(), 1);
253        assert_eq!(buf_b.refcount(), 1);
254        assert_eq!(buf_a.as_slice(), buf_b.as_slice());
255    }
256
257    // -- Tensor tests -------------------------------------------------------
258
259    #[test]
260    fn test_tensor_creation_and_indexing() {
261        let t = Tensor::zeros(&[2, 3]);
262        assert_eq!(t.shape(), &[2, 3]);
263        assert_eq!(t.ndim(), 2);
264        assert_eq!(t.len(), 6);
265        assert_eq!(t.get(&[0, 0]).unwrap(), 0.0);
266        assert_eq!(t.get(&[1, 2]).unwrap(), 0.0);
267
268        assert!(t.get(&[2, 0]).is_err());
269        assert!(t.get(&[0]).is_err());
270    }
271
272    #[test]
273    fn test_tensor_from_vec_and_set() {
274        let mut t = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0], &[2, 3]).unwrap();
275        assert_eq!(t.get(&[0, 0]).unwrap(), 1.0);
276        assert_eq!(t.get(&[0, 2]).unwrap(), 3.0);
277        assert_eq!(t.get(&[1, 0]).unwrap(), 4.0);
278        assert_eq!(t.get(&[1, 2]).unwrap(), 6.0);
279
280        t.set(&[1, 1], 99.0).unwrap();
281        assert_eq!(t.get(&[1, 1]).unwrap(), 99.0);
282    }
283
284    #[test]
285    fn test_tensor_elementwise_ops() {
286        let a = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0], &[2, 2]).unwrap();
287        let b = Tensor::from_vec(vec![5.0, 6.0, 7.0, 8.0], &[2, 2]).unwrap();
288
289        let sum = a.add(&b).unwrap();
290        assert_eq!(sum.to_vec(), vec![6.0, 8.0, 10.0, 12.0]);
291
292        let diff = a.sub(&b).unwrap();
293        assert_eq!(diff.to_vec(), vec![-4.0, -4.0, -4.0, -4.0]);
294
295        let prod = a.mul_elem(&b).unwrap();
296        assert_eq!(prod.to_vec(), vec![5.0, 12.0, 21.0, 32.0]);
297
298        let quot = b.div_elem(&a).unwrap();
299        assert_eq!(quot.to_vec(), vec![5.0, 3.0, 7.0 / 3.0, 2.0]);
300    }
301
302    #[test]
303    fn test_tensor_matmul_correctness() {
304        let a = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0], &[2, 2]).unwrap();
305        let b = Tensor::from_vec(vec![5.0, 6.0, 7.0, 8.0], &[2, 2]).unwrap();
306
307        let c = a.matmul(&b).unwrap();
308        assert_eq!(c.shape(), &[2, 2]);
309        assert_eq!(c.get(&[0, 0]).unwrap(), 19.0);
310        assert_eq!(c.get(&[0, 1]).unwrap(), 22.0);
311        assert_eq!(c.get(&[1, 0]).unwrap(), 43.0);
312        assert_eq!(c.get(&[1, 1]).unwrap(), 50.0);
313    }
314
315    #[test]
316    fn test_tensor_matmul_nonsquare() {
317        let a = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0], &[2, 3]).unwrap();
318        let b = Tensor::from_vec(vec![7.0, 8.0, 9.0, 10.0, 11.0, 12.0], &[3, 2]).unwrap();
319
320        let c = a.matmul(&b).unwrap();
321        assert_eq!(c.shape(), &[2, 2]);
322        assert_eq!(c.get(&[0, 0]).unwrap(), 58.0);
323        assert_eq!(c.get(&[0, 1]).unwrap(), 64.0);
324        assert_eq!(c.get(&[1, 0]).unwrap(), 139.0);
325        assert_eq!(c.get(&[1, 1]).unwrap(), 154.0);
326    }
327
328    #[test]
329    fn test_tensor_reshape_shares_buffer() {
330        let t = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0], &[2, 3]).unwrap();
331        let r = t.reshape(&[3, 2]).unwrap();
332
333        assert_eq!(r.shape(), &[3, 2]);
334        assert_eq!(r.get(&[0, 0]).unwrap(), 1.0);
335        assert_eq!(r.get(&[2, 1]).unwrap(), 6.0);
336
337        assert_eq!(t.buffer.refcount(), 2);
338
339        assert!(t.reshape(&[4, 2]).is_err());
340    }
341
342    #[test]
343    fn test_tensor_sum_and_mean() {
344        let t = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0], &[4]).unwrap();
345        assert!((t.sum() - 10.0).abs() < 1e-12);
346        assert!((t.mean() - 2.5).abs() < 1e-12);
347    }
348
349    // -- GC tests -----------------------------------------------------------
350
351    #[test]
352    fn test_gc_alloc_and_read() {
353        let mut heap = GcHeap::new(100);
354        let r1 = heap.alloc(42i64);
355        let r2 = heap.alloc("hello".to_string());
356
357        assert_eq!(heap.live_count(), 2);
358        assert_eq!(*heap.get::<i64>(r1).unwrap(), 42);
359        assert_eq!(heap.get::<String>(r2).unwrap().as_str(), "hello");
360
361        assert!(heap.get::<f64>(r1).is_none());
362    }
363
364    #[test]
365    fn test_gc_collect_is_noop_rc_backed() {
366        // In the RC-backed ObjectSlab, collect() is a no-op.
367        // All objects survive regardless of roots provided.
368        let mut heap = GcHeap::new(100);
369        let r1 = heap.alloc(1i64);
370        let r2 = heap.alloc(2i64);
371        let r3 = heap.alloc(3i64);
372
373        assert_eq!(heap.live_count(), 3);
374
375        // collect with partial roots — all objects survive (RC, not GC)
376        heap.collect(&[r1, r2]);
377
378        assert_eq!(heap.live_count(), 3, "RC keeps all objects alive");
379        assert_eq!(*heap.get::<i64>(r1).unwrap(), 1);
380        assert_eq!(*heap.get::<i64>(r2).unwrap(), 2);
381        assert_eq!(*heap.get::<i64>(r3).unwrap(), 3);
382    }
383
384    #[test]
385    fn test_gc_explicit_free_and_slot_reuse() {
386        // Slot reuse now requires explicit free() — no automatic GC collection.
387        let mut heap = GcHeap::new(100);
388        let r1 = heap.alloc(1i64);
389        let r2 = heap.alloc(2i64);
390        let r3 = heap.alloc(3i64);
391
392        // Explicitly free all three slots
393        heap.free(r1);
394        heap.free(r2);
395        heap.free(r3);
396        assert_eq!(heap.live_count(), 0);
397        assert_eq!(heap.free_list().len(), 3);
398
399        // New alloc reuses freed slot (LIFO)
400        let r4 = heap.alloc(99i64);
401        assert!(r4.index < 3, "should reuse a freed slot");
402        assert_eq!(*heap.get::<i64>(r4).unwrap(), 99);
403    }
404
405    // -- Stable summation test ----------------------------------------------
406
407    #[test]
408    fn test_stable_summation_via_tensor() {
409        let n = 100_000;
410        let data: Vec<f64> = (0..n).map(|_| 0.00001).collect();
411        let t = Tensor::from_vec(data, &[n]).unwrap();
412        let result = t.sum();
413        let expected = 0.00001 * n as f64;
414        assert!(
415            (result - expected).abs() < 1e-10,
416            "Kahan sum drift: expected {expected}, got {result}"
417        );
418    }
419
420    // -- Tensor randn determinism test --------------------------------------
421
422    #[test]
423    fn test_tensor_randn_deterministic() {
424        let mut rng1 = Rng::seeded(42);
425        let mut rng2 = Rng::seeded(42);
426
427        let t1 = Tensor::randn(&[3, 4], &mut rng1);
428        let t2 = Tensor::randn(&[3, 4], &mut rng2);
429
430        assert_eq!(t1.to_vec(), t2.to_vec());
431    }
432
433    // -- Value display test -------------------------------------------------
434
435    #[test]
436    fn test_value_display() {
437        assert_eq!(format!("{}", Value::Int(42)), "42");
438        assert_eq!(format!("{}", Value::Bool(true)), "true");
439        assert_eq!(format!("{}", Value::Void), "void");
440        assert_eq!(format!("{}", Value::String(Rc::new("hi".into()))), "hi");
441    }
442
443    #[test]
444    fn test_cow_string_clone_shares() {
445        let s = Value::String(Rc::new("hello".into()));
446        let s2 = s.clone();
447        if let (Value::String(a), Value::String(b)) = (&s, &s2) {
448            assert!(Rc::ptr_eq(a, b));
449        } else {
450            panic!("expected String values");
451        }
452    }
453
454    #[test]
455    fn test_cow_string_display() {
456        let s = Value::String(Rc::new("world".into()));
457        assert_eq!(format!("{}", s), "world");
458    }
459
460    // -- ByteSlice / StrView / U8 tests ------------------------------------
461
462    #[test]
463    fn test_byteslice_value_display_utf8() {
464        let bs = Value::ByteSlice(Rc::new(b"hello".to_vec()));
465        assert_eq!(format!("{}", bs), r#"b"hello""#);
466    }
467
468    #[test]
469    fn test_byteslice_value_display_hex() {
470        let bs = Value::ByteSlice(Rc::new(vec![0xff, 0x00, 0x41]));
471        assert_eq!(format!("{}", bs), r#"b"\xff\x00A""#);
472    }
473
474    #[test]
475    fn test_strview_value_display() {
476        let sv = Value::StrView(Rc::new(b"world".to_vec()));
477        assert_eq!(format!("{}", sv), "world");
478    }
479
480    #[test]
481    fn test_u8_value_display() {
482        assert_eq!(format!("{}", Value::U8(65)), "65");
483    }
484
485    #[test]
486    fn test_byteslice_hash_deterministic() {
487        let a = Value::ByteSlice(Rc::new(b"hello".to_vec()));
488        let b = Value::ByteSlice(Rc::new(b"hello".to_vec()));
489        assert_eq!(value_hash(&a), value_hash(&b));
490    }
491
492    #[test]
493    fn test_byteslice_hash_different_content() {
494        let a = Value::ByteSlice(Rc::new(b"hello".to_vec()));
495        let b = Value::ByteSlice(Rc::new(b"world".to_vec()));
496        assert_ne!(value_hash(&a), value_hash(&b));
497    }
498
499    #[test]
500    fn test_byteslice_equality() {
501        let a = Value::ByteSlice(Rc::new(b"abc".to_vec()));
502        let b = Value::ByteSlice(Rc::new(b"abc".to_vec()));
503        let c = Value::ByteSlice(Rc::new(b"def".to_vec()));
504        assert!(values_equal_static(&a, &b));
505        assert!(!values_equal_static(&a, &c));
506    }
507
508    #[test]
509    fn test_strview_equality() {
510        let a = Value::StrView(Rc::new(b"test".to_vec()));
511        let b = Value::StrView(Rc::new(b"test".to_vec()));
512        assert!(values_equal_static(&a, &b));
513    }
514
515    #[test]
516    fn test_u8_hash_and_equality() {
517        let a = Value::U8(42);
518        let b = Value::U8(42);
519        let c = Value::U8(99);
520        assert_eq!(value_hash(&a), value_hash(&b));
521        assert_ne!(value_hash(&a), value_hash(&c));
522        assert!(values_equal_static(&a, &b));
523        assert!(!values_equal_static(&a, &c));
524    }
525
526    #[test]
527    fn test_byteslice_clone_shares_rc() {
528        let bs = Value::ByteSlice(Rc::new(b"data".to_vec()));
529        let bs2 = bs.clone();
530        if let (Value::ByteSlice(a), Value::ByteSlice(b)) = (&bs, &bs2) {
531            assert!(Rc::ptr_eq(a, b));
532        } else {
533            panic!("expected ByteSlice values");
534        }
535    }
536
537    #[test]
538    fn test_byteslice_in_detmap() {
539        let mut map = DetMap::new();
540        let key = Value::ByteSlice(Rc::new(b"token".to_vec()));
541        map.insert(key.clone(), Value::Int(1));
542
543        let lookup = Value::ByteSlice(Rc::new(b"token".to_vec()));
544        assert!(map.contains_key(&lookup));
545        match map.get(&lookup) {
546            Some(Value::Int(1)) => {},
547            _ => panic!("expected Int(1)"),
548        }
549    }
550
551    #[test]
552    fn test_murmurhash3_byteslice_stability() {
553        let h1 = murmurhash3(b"hello");
554        let h2 = murmurhash3(b"hello");
555        assert_eq!(h1, h2);
556
557        let h3 = murmurhash3(b"");
558        let h4 = murmurhash3(b"");
559        assert_eq!(h3, h4);
560
561        assert_ne!(murmurhash3(b"hello"), murmurhash3(b"world"));
562    }
563}