MCPcopy Create free account
hub / github.com/argumentcomputer/ix / decode_hashmap

Function decode_hashmap

crates/ffi/src/ix/env.rs:108–129  ·  view source on GitHub ↗

Decode a Lean HashMap into a Vec of key-value pairs. HashMap structure (after unboxing): Raw { size : Nat, buckets : Array (AssocList α β) } Due to single-field struct unboxing: - HashMap { inner : DHashMap } unboxes to DHashMap - DHashMap { inner : Raw, wf : Prop } unboxes to Raw (Prop is erased) - Raw { size : Nat, buckets : Array } - field 0 = size, field 1 = buckets

(
  obj: LeanBorrowed<'_>,
  decode_key: FK,
  decode_val: FV,
)

Source from the content-addressed store, hash-verified

106/// - DHashMap { inner : Raw, wf : Prop } unboxes to Raw (Prop is erased)
107/// - Raw { size : Nat, buckets : Array } - field 0 = size, field 1 = buckets
108fn decode_hashmap<K, V, FK, FV>(
109 obj: LeanBorrowed<'_>,
110 decode_key: FK,
111 decode_val: FV,
112) -> Vec<(K, V)>
113where
114 FK: Fn(LeanBorrowed<'_>) -> K + Copy,
115 FV: Fn(LeanBorrowed<'_>) -> V + Copy,
116{
117 let ctor = obj.as_ctor();
118 // Raw layout: field 0 = size (Nat), field 1 = buckets (Array)
119 let _size = ctor.get(0); // unused but needed for layout
120 let buckets = ctor.get(1).as_array();
121
122 let mut pairs = Vec::new();
123 for bucket in buckets.iter() {
124 let bucket_pairs = decode_assoc_list(bucket, decode_key, decode_val);
125 pairs.extend(bucket_pairs);
126 }
127
128 pairs
129}
130
131impl LeanIxRawEnvironment<LeanOwned> {
132 /// Build a Ix.RawEnvironment from collected caches.

Callers 1

decodeMethod · 0.85

Calls 4

decode_assoc_listFunction · 0.85
as_arrayMethod · 0.80
getMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected