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/// Phase 2b — typed-ID newtypes for ML metadata. Currently provides
162/// only `ParamIdx`, used by `crate::ml::AdamState` and `SgdState`.
163pub mod idx;
164
165// --- Re-exports for backward compatibility ---
166// All downstream crates that were doing `use cjc_runtime::Tensor` etc. continue to work.
167
168/// Re-export: COW buffer with deterministic copy-on-write semantics.
169pub use buffer::Buffer;
170/// Re-export: N-dimensional tensor -- the primary numerical type.
171pub use tensor::Tensor;
172/// Re-export: Pre-allocated KV-cache scratchpad.
173pub use scratchpad::Scratchpad;
174/// Re-export: 16-byte-aligned memory pool and byte slice.
175pub use aligned_pool::{AlignedPool, AlignedByteSlice};
176/// Re-export: Block-paged KV-cache types.
177pub use paged_kv::{KvBlock, PagedKvCache};
178/// Re-export: GC heap and reference types.
179pub use gc::{GcRef, GcHeap};
180/// Re-export: Size-class binned allocator.
181pub use binned_alloc::BinnedAllocator;
182/// Re-export: Bump-arena and arena store types.
183pub use frame_arena::{FrameArena, ArenaStore};
184/// Re-export: Object slab and slab reference types.
185pub use object_slab::{ObjectSlab, SlabRef};
186/// Re-export: Sparse matrix types (CSR and COO).
187pub use sparse::{SparseCsr, SparseCoo};
188/// Re-export: Tiled matrix multiplication engine.
189pub use tensor_tiled::TiledMatmul;
190/// Re-export: Deterministic map, MurmurHash3, and value hashing utilities.
191pub use det_map::{DetMap, murmurhash3, murmurhash3_finalize, value_hash, values_equal_static};
192/// Re-export: Universal value type and supporting types.
193pub use value::{Value, Bf16, FnValue};
194/// Re-export: Runtime error type.
195pub use error::RuntimeError;
196/// Re-export: Typed tensor storage types.
197pub use tensor_dtype::{DType, TypedStorage};
198
199// ---------------------------------------------------------------------------
200// Tests — remain here so they can use `super::*` to access all re-exports.
201// ---------------------------------------------------------------------------
202
203#[cfg(test)]
204mod tests {
205    use super::*;
206    use std::rc::Rc;
207    use cjc_repro::Rng;
208
209    // -- Buffer tests -------------------------------------------------------
210
211    #[test]
212    fn test_buffer_alloc_get_set() {
213        let mut buf = Buffer::alloc(5, 0.0f64);
214        assert_eq!(buf.len(), 5);
215        assert_eq!(buf.get(0), Some(0.0));
216        assert_eq!(buf.get(4), Some(0.0));
217        assert_eq!(buf.get(5), None);
218
219        buf.set(2, 42.0).unwrap();
220        assert_eq!(buf.get(2), Some(42.0));
221
222        assert!(buf.set(10, 1.0).is_err());
223    }
224
225    #[test]
226    fn test_buffer_from_vec() {
227        let buf = Buffer::from_vec(vec![1, 2, 3, 4, 5]);
228        assert_eq!(buf.len(), 5);
229        assert_eq!(buf.get(0), Some(1));
230        assert_eq!(buf.get(4), Some(5));
231        assert_eq!(buf.as_slice(), vec![1, 2, 3, 4, 5]);
232    }
233
234    #[test]
235    fn test_buffer_cow_behavior() {
236        let buf_a = Buffer::from_vec(vec![10, 20, 30]);
237        let mut buf_b = buf_a.clone();
238
239        assert_eq!(buf_a.refcount(), 2);
240        assert_eq!(buf_b.refcount(), 2);
241
242        buf_b.set(0, 99).unwrap();
243
244        assert_eq!(buf_a.refcount(), 1);
245        assert_eq!(buf_b.refcount(), 1);
246        assert_eq!(buf_a.get(0), Some(10));
247        assert_eq!(buf_b.get(0), Some(99));
248    }
249
250    #[test]
251    fn test_buffer_clone_buffer_forces_deep_copy() {
252        let buf_a = Buffer::from_vec(vec![1, 2, 3]);
253        let buf_b = buf_a.clone_buffer();
254
255        assert_eq!(buf_a.refcount(), 1);
256        assert_eq!(buf_b.refcount(), 1);
257        assert_eq!(buf_a.as_slice(), buf_b.as_slice());
258    }
259
260    // -- Tensor tests -------------------------------------------------------
261
262    #[test]
263    fn test_tensor_creation_and_indexing() {
264        let t = Tensor::zeros(&[2, 3]);
265        assert_eq!(t.shape(), &[2, 3]);
266        assert_eq!(t.ndim(), 2);
267        assert_eq!(t.len(), 6);
268        assert_eq!(t.get(&[0, 0]).unwrap(), 0.0);
269        assert_eq!(t.get(&[1, 2]).unwrap(), 0.0);
270
271        assert!(t.get(&[2, 0]).is_err());
272        assert!(t.get(&[0]).is_err());
273    }
274
275    #[test]
276    fn test_tensor_from_vec_and_set() {
277        let mut t = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0], &[2, 3]).unwrap();
278        assert_eq!(t.get(&[0, 0]).unwrap(), 1.0);
279        assert_eq!(t.get(&[0, 2]).unwrap(), 3.0);
280        assert_eq!(t.get(&[1, 0]).unwrap(), 4.0);
281        assert_eq!(t.get(&[1, 2]).unwrap(), 6.0);
282
283        t.set(&[1, 1], 99.0).unwrap();
284        assert_eq!(t.get(&[1, 1]).unwrap(), 99.0);
285    }
286
287    #[test]
288    fn test_tensor_elementwise_ops() {
289        let a = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0], &[2, 2]).unwrap();
290        let b = Tensor::from_vec(vec![5.0, 6.0, 7.0, 8.0], &[2, 2]).unwrap();
291
292        let sum = a.add(&b).unwrap();
293        assert_eq!(sum.to_vec(), vec![6.0, 8.0, 10.0, 12.0]);
294
295        let diff = a.sub(&b).unwrap();
296        assert_eq!(diff.to_vec(), vec![-4.0, -4.0, -4.0, -4.0]);
297
298        let prod = a.mul_elem(&b).unwrap();
299        assert_eq!(prod.to_vec(), vec![5.0, 12.0, 21.0, 32.0]);
300
301        let quot = b.div_elem(&a).unwrap();
302        assert_eq!(quot.to_vec(), vec![5.0, 3.0, 7.0 / 3.0, 2.0]);
303    }
304
305    #[test]
306    fn test_tensor_matmul_correctness() {
307        let a = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0], &[2, 2]).unwrap();
308        let b = Tensor::from_vec(vec![5.0, 6.0, 7.0, 8.0], &[2, 2]).unwrap();
309
310        let c = a.matmul(&b).unwrap();
311        assert_eq!(c.shape(), &[2, 2]);
312        assert_eq!(c.get(&[0, 0]).unwrap(), 19.0);
313        assert_eq!(c.get(&[0, 1]).unwrap(), 22.0);
314        assert_eq!(c.get(&[1, 0]).unwrap(), 43.0);
315        assert_eq!(c.get(&[1, 1]).unwrap(), 50.0);
316    }
317
318    #[test]
319    fn test_tensor_matmul_nonsquare() {
320        let a = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0], &[2, 3]).unwrap();
321        let b = Tensor::from_vec(vec![7.0, 8.0, 9.0, 10.0, 11.0, 12.0], &[3, 2]).unwrap();
322
323        let c = a.matmul(&b).unwrap();
324        assert_eq!(c.shape(), &[2, 2]);
325        assert_eq!(c.get(&[0, 0]).unwrap(), 58.0);
326        assert_eq!(c.get(&[0, 1]).unwrap(), 64.0);
327        assert_eq!(c.get(&[1, 0]).unwrap(), 139.0);
328        assert_eq!(c.get(&[1, 1]).unwrap(), 154.0);
329    }
330
331    #[test]
332    fn test_tensor_reshape_shares_buffer() {
333        let t = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0], &[2, 3]).unwrap();
334        let r = t.reshape(&[3, 2]).unwrap();
335
336        assert_eq!(r.shape(), &[3, 2]);
337        assert_eq!(r.get(&[0, 0]).unwrap(), 1.0);
338        assert_eq!(r.get(&[2, 1]).unwrap(), 6.0);
339
340        assert_eq!(t.buffer.refcount(), 2);
341
342        assert!(t.reshape(&[4, 2]).is_err());
343    }
344
345    #[test]
346    fn test_tensor_sum_and_mean() {
347        let t = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0], &[4]).unwrap();
348        assert!((t.sum() - 10.0).abs() < 1e-12);
349        assert!((t.mean() - 2.5).abs() < 1e-12);
350    }
351
352    // -- GC tests -----------------------------------------------------------
353
354    #[test]
355    fn test_gc_alloc_and_read() {
356        let mut heap = GcHeap::new(100);
357        let r1 = heap.alloc(42i64);
358        let r2 = heap.alloc("hello".to_string());
359
360        assert_eq!(heap.live_count(), 2);
361        assert_eq!(*heap.get::<i64>(r1).unwrap(), 42);
362        assert_eq!(heap.get::<String>(r2).unwrap().as_str(), "hello");
363
364        assert!(heap.get::<f64>(r1).is_none());
365    }
366
367    #[test]
368    fn test_gc_collect_is_noop_rc_backed() {
369        // In the RC-backed ObjectSlab, collect() is a no-op.
370        // All objects survive regardless of roots provided.
371        let mut heap = GcHeap::new(100);
372        let r1 = heap.alloc(1i64);
373        let r2 = heap.alloc(2i64);
374        let r3 = heap.alloc(3i64);
375
376        assert_eq!(heap.live_count(), 3);
377
378        // collect with partial roots — all objects survive (RC, not GC)
379        heap.collect(&[r1, r2]);
380
381        assert_eq!(heap.live_count(), 3, "RC keeps all objects alive");
382        assert_eq!(*heap.get::<i64>(r1).unwrap(), 1);
383        assert_eq!(*heap.get::<i64>(r2).unwrap(), 2);
384        assert_eq!(*heap.get::<i64>(r3).unwrap(), 3);
385    }
386
387    #[test]
388    fn test_gc_explicit_free_and_slot_reuse() {
389        // Slot reuse now requires explicit free() — no automatic GC collection.
390        let mut heap = GcHeap::new(100);
391        let r1 = heap.alloc(1i64);
392        let r2 = heap.alloc(2i64);
393        let r3 = heap.alloc(3i64);
394
395        // Explicitly free all three slots
396        heap.free(r1);
397        heap.free(r2);
398        heap.free(r3);
399        assert_eq!(heap.live_count(), 0);
400        assert_eq!(heap.free_list().len(), 3);
401
402        // New alloc reuses freed slot (LIFO)
403        let r4 = heap.alloc(99i64);
404        assert!(r4.index < 3, "should reuse a freed slot");
405        assert_eq!(*heap.get::<i64>(r4).unwrap(), 99);
406    }
407
408    // -- Stable summation test ----------------------------------------------
409
410    #[test]
411    fn test_stable_summation_via_tensor() {
412        let n = 100_000;
413        let data: Vec<f64> = (0..n).map(|_| 0.00001).collect();
414        let t = Tensor::from_vec(data, &[n]).unwrap();
415        let result = t.sum();
416        let expected = 0.00001 * n as f64;
417        assert!(
418            (result - expected).abs() < 1e-10,
419            "Kahan sum drift: expected {expected}, got {result}"
420        );
421    }
422
423    // -- Tensor randn determinism test --------------------------------------
424
425    #[test]
426    fn test_tensor_randn_deterministic() {
427        let mut rng1 = Rng::seeded(42);
428        let mut rng2 = Rng::seeded(42);
429
430        let t1 = Tensor::randn(&[3, 4], &mut rng1);
431        let t2 = Tensor::randn(&[3, 4], &mut rng2);
432
433        assert_eq!(t1.to_vec(), t2.to_vec());
434    }
435
436    // -- Value display test -------------------------------------------------
437
438    #[test]
439    fn test_value_display() {
440        assert_eq!(format!("{}", Value::Int(42)), "42");
441        assert_eq!(format!("{}", Value::Bool(true)), "true");
442        assert_eq!(format!("{}", Value::Void), "void");
443        assert_eq!(format!("{}", Value::String(Rc::new("hi".into()))), "hi");
444    }
445
446    #[test]
447    fn test_cow_string_clone_shares() {
448        let s = Value::String(Rc::new("hello".into()));
449        let s2 = s.clone();
450        if let (Value::String(a), Value::String(b)) = (&s, &s2) {
451            assert!(Rc::ptr_eq(a, b));
452        } else {
453            panic!("expected String values");
454        }
455    }
456
457    #[test]
458    fn test_cow_string_display() {
459        let s = Value::String(Rc::new("world".into()));
460        assert_eq!(format!("{}", s), "world");
461    }
462
463    // -- ByteSlice / StrView / U8 tests ------------------------------------
464
465    #[test]
466    fn test_byteslice_value_display_utf8() {
467        let bs = Value::ByteSlice(Rc::new(b"hello".to_vec()));
468        assert_eq!(format!("{}", bs), r#"b"hello""#);
469    }
470
471    #[test]
472    fn test_byteslice_value_display_hex() {
473        let bs = Value::ByteSlice(Rc::new(vec![0xff, 0x00, 0x41]));
474        assert_eq!(format!("{}", bs), r#"b"\xff\x00A""#);
475    }
476
477    #[test]
478    fn test_strview_value_display() {
479        let sv = Value::StrView(Rc::new(b"world".to_vec()));
480        assert_eq!(format!("{}", sv), "world");
481    }
482
483    #[test]
484    fn test_u8_value_display() {
485        assert_eq!(format!("{}", Value::U8(65)), "65");
486    }
487
488    #[test]
489    fn test_byteslice_hash_deterministic() {
490        let a = Value::ByteSlice(Rc::new(b"hello".to_vec()));
491        let b = Value::ByteSlice(Rc::new(b"hello".to_vec()));
492        assert_eq!(value_hash(&a), value_hash(&b));
493    }
494
495    #[test]
496    fn test_byteslice_hash_different_content() {
497        let a = Value::ByteSlice(Rc::new(b"hello".to_vec()));
498        let b = Value::ByteSlice(Rc::new(b"world".to_vec()));
499        assert_ne!(value_hash(&a), value_hash(&b));
500    }
501
502    #[test]
503    fn test_byteslice_equality() {
504        let a = Value::ByteSlice(Rc::new(b"abc".to_vec()));
505        let b = Value::ByteSlice(Rc::new(b"abc".to_vec()));
506        let c = Value::ByteSlice(Rc::new(b"def".to_vec()));
507        assert!(values_equal_static(&a, &b));
508        assert!(!values_equal_static(&a, &c));
509    }
510
511    #[test]
512    fn test_strview_equality() {
513        let a = Value::StrView(Rc::new(b"test".to_vec()));
514        let b = Value::StrView(Rc::new(b"test".to_vec()));
515        assert!(values_equal_static(&a, &b));
516    }
517
518    #[test]
519    fn test_u8_hash_and_equality() {
520        let a = Value::U8(42);
521        let b = Value::U8(42);
522        let c = Value::U8(99);
523        assert_eq!(value_hash(&a), value_hash(&b));
524        assert_ne!(value_hash(&a), value_hash(&c));
525        assert!(values_equal_static(&a, &b));
526        assert!(!values_equal_static(&a, &c));
527    }
528
529    #[test]
530    fn test_byteslice_clone_shares_rc() {
531        let bs = Value::ByteSlice(Rc::new(b"data".to_vec()));
532        let bs2 = bs.clone();
533        if let (Value::ByteSlice(a), Value::ByteSlice(b)) = (&bs, &bs2) {
534            assert!(Rc::ptr_eq(a, b));
535        } else {
536            panic!("expected ByteSlice values");
537        }
538    }
539
540    #[test]
541    fn test_byteslice_in_detmap() {
542        let mut map = DetMap::new();
543        let key = Value::ByteSlice(Rc::new(b"token".to_vec()));
544        map.insert(key.clone(), Value::Int(1));
545
546        let lookup = Value::ByteSlice(Rc::new(b"token".to_vec()));
547        assert!(map.contains_key(&lookup));
548        match map.get(&lookup) {
549            Some(Value::Int(1)) => {},
550            _ => panic!("expected Int(1)"),
551        }
552    }
553
554    #[test]
555    fn test_murmurhash3_byteslice_stability() {
556        let h1 = murmurhash3(b"hello");
557        let h2 = murmurhash3(b"hello");
558        assert_eq!(h1, h2);
559
560        let h3 = murmurhash3(b"");
561        let h4 = murmurhash3(b"");
562        assert_eq!(h3, h4);
563
564        assert_ne!(murmurhash3(b"hello"), murmurhash3(b"world"));
565    }
566}