PageSourceSearch

https://noir-lang.org/docs/assets/js/ea3c9d26.a7e5925d.js

js noir-lang.org collected 2026-10-03 22:51:50 UTC 34,243 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkdocs=globalThis.webpackChunkdocs||[]).push([[1788],{50706(e,n,s){s.r(n),s.d(n,{assets:()=>o,contentTitle:()=>l,default:()=>u,frontMatter:()=>i,metadata:()=>r,toc:()=>c});const r=JSON.parse('{"id":"libraries/standard_library/containers/uhashmap","title":"UHashMap","description":"A growable key\u2013value map with a generic hasher.","source":"@site/versioned_docs/version-v1.0.0-beta.26/libraries/standard_library/containers/uhashmap.md","sourceDirName":"libraries/standard_library/containers","slug":"/libraries/standard_library/containers/uhashmap","permalink":"/docs/v1.0.0-beta.26/libraries/standard_library/containers/uhashmap","draft":false,"unlisted":false,"editUrl":"https://github.com/noir-lang/noir/edit/master/docs/versioned_docs/version-v1.0.0-beta.26/libraries/standard_library/containers/uhashmap.md","tags":[],"version":"v1.0.0-beta.26","frontMatter":{"title":"UHashMap","description":"A growable key\u2013value map with a generic hasher.","keywords":["noir","map","hash","hashmap"]},"sidebar":"sidebar","previous":{"title":"Bounded Vectors","permalink":"/docs/v1.0.0-beta.26/libraries/standard_library/containers/boundedvec"},"next":{"title":"Cryptographic Primitives","permalink":"/docs/v1.0.0-beta.26/libraries/standard_library/cryptographic_primitives/"}}');var t=s(74848),a=s(28453);const i={title:"UHashMap",description:"A growable key\u2013value map with a generic hasher.",keywords:["noir","map","hash","hashmap"]},l=void 0,o={},c=[{value:"Methods",id:"methods",level:2},{value:"default",id:"default",level:3},{value:"with_hasher",id:"with_hasher",level:3},{value:"get",id:"get",level:3},{value:"insert",id:"insert",level:3},{value:"remove",id:"remove",level:3},{value:"is_empty",id:"is_empty",level:3},{value:"len",id:"len",level:3},{value:"clear",id:"clear",level:3},{value:"contains_key",id:"contains_key",level:3},{value:"entries",id:"entries",level:3},{value:"keys",id:"keys",level:3},{value:"values",id:"values",level:3},{value:"iter_mut",id:"iter_mut",level:3},{value:"iter_keys_mut",id:"iter_keys_mut",level:3},{value:"iter_values_mut",id:"iter_values_mut",level:3},{value:"retain",id:"retain",level:3},{value:"Trait Implementations",id:"trait-implementations",level:2},{value:"default",id:"default-1",level:3},{value:"eq",id:"eq",level:3}];function h(e){const n={a:"a",blockquote:"blockquote",code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",sub:"sub",sup:"sup",...(0,a.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"UHashMap<Key, Value, Hasher>"})," is used to efficiently store and look up key-value pairs in unconstrained\nor comptime code."]}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsxs)(n.p,{children:["Note that the results of most ",(0,t.jsx)(n.code,{children:"UHashMap"})," methods are not constrained! If returning these values into\nconstrained code, users must manually ensure they are properly constrained."]}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"UHashMap"})," is an unbounded container type implemented with vectors internally which grows as more\nentries are pushed to it."]}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",children:"// Create a mapping from Fields to u32s using a poseidon2 hasher\nuse poseidon::poseidon2::Poseidon2Hasher;\nlet mut map: UHashMap<Field, u32, BuildHasherDefault<Poseidon2Hasher>> = UHashMap::default();\n\nlet _ = map.insert(1, 2);\nlet _ = map.insert(3, 4);\n\nlet two = map.get(1).unwrap();\n"})}),"\n",(0,t.jsx)(n.h2,{id:"methods",children:"Methods"}),"\n",(0,t.jsx)(n.h3,{id:"default",children:"default"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="default" showLineNumbers ',children:"impl<K, V, B> Default for UHashMap<K, V, B>\nwhere\n    B: BuildHasher + Default,\n{\n    fn default() -> Self {\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L464-L470",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L464-L470"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Creates a fresh, empty UHashMap."}),"\n",(0,t.jsxs)(n.p,{children:["This is the same ",(0,t.jsx)(n.code,{children:"default"})," from the ",(0,t.jsx)(n.code,{children:"Default"})," implementation given further below. It is\nrepeated here for convenience since it is the recommended way to create a hash map."]}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="default_example" showLineNumbers ',children:"let hashmap: UHashMap<u8, u32, BuildHasherDefault<Poseidon2Hasher>> = UHashMap::default();\nassert(hashmap.is_empty());\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L205-L208",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L205-L208"})})})}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:["Because ",(0,t.jsx)(n.code,{children:"UHashMap"})," has so many generic arguments that are likely to be the same throughout\nyour program, it may be helpful to create a type alias:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="type_alias" showLineNumbers ',children:"type MyMap = UHashMap<u8, u32, BuildHasherDefault<Poseidon2Hasher>>;\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L199-L201",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L199-L201"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"with_hasher",children:"with_hasher"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="with_hasher" showLineNumbers ',children:"pub fn with_hasher(_build_hasher: B) -> Self\nwhere\n    B: BuildHasher,\n{\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L72-L77",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L72-L77"})})})}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:["Creates a hash map with an existing ",(0,t.jsx)(n.code,{children:"Build
1Hasher"}),". This can be used to ensure multiple\nhash maps are created with the same hasher instance."]}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="with_hasher_example" showLineNumbers ',children:"let my_hasher: BuildHasherDefault<Poseidon2Hasher> = Default::default();\nlet hashmap: UHashMap<u8, u32, BuildHasherDefault<Poseidon2Hasher>> =\n    UHashMap::with_hasher(my_hasher);\nassert(hashmap.is_empty());\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L209-L214",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L209-L214"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"get",children:"get"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="get" showLineNumbers ',children:"pub unconstrained fn get(&self, key: K) -> Option<V>\nwhere\n    K: Eq + Hash,\n    B: BuildHasher,\n{\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L275-L281",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L275-L281"})})})}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:["Retrieves a value from the hash map, returning ",(0,t.jsx)(n.code,{children:"Option::none()"})," if it was not found."]}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="get_example" showLineNumbers ',children:"unconstrained fn get_example(map: &UHashMap<Field, Field, BuildHasherDefault<Poseidon2Hasher>>) {\n    let x = map.get(12);\n\n    if x.is_some() {\n        assert(x.unwrap() == 42);\n    }\n}\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L294-L302",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L294-L302"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"insert",children:"insert"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="insert" showLineNumbers ',children:"pub unconstrained fn insert(&mut self, key: K, value: V) -> bool\nwhere\n    K: Eq + Hash,\n    B: BuildHasher,\n{\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L306-L312",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L306-L312"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Inserts a new key-value pair into the map. If the key was already in the map, its\nprevious value will be overridden with the newly provided one."}),"\n",(0,t.jsxs)(n.p,{children:["This returns whether the value was newly-inserted. In other words, if the value was\nalready present in the map, ",(0,t.jsx)(n.code,{children:"false"})," is returned. Otherwise, ",(0,t.jsx)(n.code,{children:"true"})," is returned."]}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="insert_example" showLineNumbers ',children:"let mut map: UHashMap<Field, Field, BuildHasherDefault<Poseidon2Hasher>> = UHashMap::default();\nmap.insert(12, 42);\nassert(map.len() == 1);\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L215-L219",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L215-L219"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"remove",children:"remove"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="remove" showLineNumbers ',children:"pub unconstrained fn remove(&mut self, key: K)\nwhere\n    K: Eq + Hash,\n    B: BuildHasher,\n{\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L374-L380",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L374-L380"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Removes the given key-value pair from the map. If the key was not already present\nin the map, this does nothing."}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="remove_example" showLineNumbers ',children:"map.remove(12);\nassert(map.is_empty());\n\n// If a key was not present in the map, remove does nothing\nmap.remove(12);\nassert(map.is_empty());\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L222-L229",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L222-L229"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"is_empty",children:"is_empty"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="is_empty" showLineNumbers ',children:"pub unconstrained fn is_empty(&self) -> bool {\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L116-L118",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L116-L118"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"True if the length of the hash map is empty."}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="is_empty_example" showLineNumbers ',children:"assert(map.is_empty());\n\nmap.insert(1, 2);\nassert(!map.is_empty());\n\nmap.remove(1);\nassert(map.is_empty());\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L230-L238",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L230-L238"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"len",children:"len"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="len" showLineNumbers ',children:"pub unconstrained fn len(&self) -> u32 {\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L261-L263",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L261-L263"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Returns the current length of this hash map."}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="len_example" showLineNumbers ',children:"// This is equivalent to checking map.is_empty()\nassert(map.len() == 0);\n\nmap.insert(1, 2);\nmap.insert(3, 4);\nmap.insert(5, 6);\nassert(map.len() == 3);\n\n// 3 was already present as a key in the hash map, so the length is unchanged\nmap.insert(3, 7);\nassert(map.len() == 3);\n\nmap.remove(1);\nassert(map.len() == 2);\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L239-L254",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L239-L254"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"clear",children:"clear"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="clear" showLineNumbers ',children:"pub unconstrained fn clear(&mut self) {\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L97-L99",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L97-L99"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Clears the hash map, removing all key-value pairs from it."}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="clear_example" showLineNumbers ',children:"assert(!map.is_empty());\nmap.clear();\nassert(map.is_empty());\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L261-L265",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L261-L265"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"contains_key",children:"contains_key"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="contains_key" showLineNumbers ',children:"pub unconstrained fn contains_key(&self, key: K) -> bool\nwhere\n    K: Hash + Eq,\n    B: BuildHasher,\n{\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L105-L111",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L105-L111"})})})}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:["True if the hash map contains the given key. Unlike ",(0,t.jsx)(n.code,{children:"get"}),", this will not also return\nthe value associated with the key."]}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="contains_key_example" showLineNumbers ',children:'if map.contains_key(
17) {\n    let value = map.get(7);\n    assert(value.is_some());\n} else {\n    println("No value for key 7!");\n}\n'})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L266-L273",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L266-L273"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"entries",children:"entries"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="entries" showLineNumbers ',children:"pub unconstrained fn entries(&self) -> [(K, V)] {\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L124-L126",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L124-L126"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Returns a vector of each key-value pair present in the hash map."}),"\n",(0,t.jsx)(n.p,{children:"The length of the returned vector is always equal to the length of the hash map."}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="entries_example" showLineNumbers ',children:'let entries = map.entries();\n\n// The length of a hashmap may not be compile-time known, so we\n// need to loop over its capacity instead\nfor i in 0..map.capacity() {\n    if i < entries.len() {\n        let (key, value) = entries[i];\n        println(f"{key} -> {value}");\n    }\n}\n'})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L307-L318",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L307-L318"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"keys",children:"keys"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="keys" showLineNumbers ',children:"pub unconstrained fn keys(&self) -> [K] {\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L147-L149",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L147-L149"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Returns a vector of each key present in the hash map."}),"\n",(0,t.jsx)(n.p,{children:"The length of the returned vector is always equal to the length of the hash map."}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="keys_example" showLineNumbers ',children:'let keys = map.keys();\n\nfor key in keys {\n    let value = map.get(key).unwrap_unchecked();\n    println(f"{key} -> {value}");\n}\n'})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L319-L326",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L319-L326"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"values",children:"values"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="values" showLineNumbers ',children:"pub unconstrained fn values(&self) -> [V] {\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L169-L171",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L169-L171"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Returns a vector of each value present in the hash map."}),"\n",(0,t.jsx)(n.p,{children:"The length of the returned vector is always equal to the length of the hash map."}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="values_example" showLineNumbers ',children:'let values = map.values();\n\nfor value in values {\n    println(f"Found value {value}");\n}\n'})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L327-L333",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L327-L333"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"iter_mut",children:"iter_mut"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="iter_mut" showLineNumbers ',children:"pub unconstrained fn iter_mut(&mut self, f: fn(K, V) ->
1 (K, V))\nwhere\n    K: Eq + Hash,\n    B: BuildHasher,\n{\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L190-L196",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L190-L196"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Iterates through each key-value pair of the UHashMap, setting each key-value pair to the\nresult returned from the given function."}),"\n",(0,t.jsxs)(n.p,{children:["Note that since keys can be mutated, the UHashMap needs to be rebuilt as it is iterated\nthrough. If this is not desired, use ",(0,t.jsx)(n.code,{children:"iter_values_mut"})," if only values need to be mutated,\nor ",(0,t.jsx)(n.code,{children:"entries"})," if neither keys nor values need to be mutated."]}),"\n",(0,t.jsx)(n.p,{children:"The iteration order is left unspecified. As a result, if two keys are mutated to become\nequal, which of the two values that will be present for the key in the resulting map is also unspecified."}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="iter_mut_example" showLineNumbers ',children:"// Add 1 to each key in the map, and double the value associated with that key.\nmap.iter_mut(|k, v| (k + 1, v * 2));\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L339-L342",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L339-L342"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"iter_keys_mut",children:"iter_keys_mut"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="iter_keys_mut" showLineNumbers ',children:"pub unconstrained fn iter_keys_mut(&mut self, f: fn(K) -> K)\nwhere\n    K: Eq + Hash,\n    B: BuildHasher,\n{\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L210-L216",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L210-L216"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Iterates through the UHashMap, mutating each key to the result returned from\nthe given function."}),"\n",(0,t.jsxs)(n.p,{children:["Note that since keys can be mutated, the UHashMap needs to be rebuilt as it is iterated\nthrough. If only iteration is desired and the keys are not intended to be mutated,\nprefer using ",(0,t.jsx)(n.code,{children:"entries"})," instead."]}),"\n",(0,t.jsx)(n.p,{children:"The iteration order is left unspecified. As a result, if two keys are mutated to become\nequal, which of the two values that will be present for the key in the resulting map is also unspecified."}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="iter_keys_mut_example" showLineNumbers ',children:"// Double each key, leaving the value associated with that key untouched\nmap.iter_keys_mut(|k| k * 2);\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L343-L346",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L343-L346"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"iter_values_mut",children:"iter_values_mut"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="iter_values_mut" showLineNumbers ',children:"pub unconstrained fn iter_values_mut(&mut self, f: fn(V) -> V) {\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L232-L234",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L232-L234"})})})}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:["Iterates through the UHashMap, applying the given function to each value and mutating the\nvalue to equal the result. This function is more efficient than ",(0,t.jsx)(n.code,{children:"iter_mut"})," and ",(0,t.jsx)(n.code,{children:"iter_keys_mut"}),"\nbecause the keys are untouched and the underlying hash map thus does not need to be reordered."]}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="iter_values_mut_example" showLineNumbers ',children:"// Halve each value\nmap.iter_values_mut(|v| v / 2);\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L347-L350",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L347-L350"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"retain",children:"retain"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="retain" showLineNumbers ',children:"pub unconstrained fn retain(&mut self, f: fn(K, V) -> bool) {\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L245-L247",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L245-L247"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Retains only the key-value pairs for which the given function returns true.\nAny key-value pairs for which the function returns false will be removed from the map."}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="retain_example" showLineNumbers ',children:"map.retain(|k, v| (k != 0) & (v != 0));\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L277-L279",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L277-L279"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"trait-implementations",children:"Trait Implementations"}),"\n",(0,t.jsx)(n.h3,{id:"default-1",children:"default"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="default" showLineNumbers ',children:"impl<K, V, B> Default for UHashMap<K, V, B>\nwhere\n    B: BuildHasher + Default,\n{\n    fn default() -> Self {\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L464-L470",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L464-L470"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Constructs an empty UHashMap."}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="default_example" showLineNumbers ',children:"let hashmap: UHashMap<u8, u32, BuildHasherDefault<Poseidon2Hasher>> = UHashMap::default();\nassert(hashmap.is_empty());\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L205-L208",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L205-L208"})})})}),"\n"]}),"\n",(0,t.jsx)(n.h3,{id:"eq",children:"eq"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="eq" showLineNumbers ',children:"impl<K, V, B> Eq for UHashMap<K, V, B>\nwhere\n    K: Eq + Hash,\n    V: Eq,\n    B: BuildHasher,\n{\n    fn eq(self, other: UHashMap<K, V, B>) -> bool {\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/collections/umap.nr#L420-L428",target:"_blank",rel:"noopener noreferrer",children:"Source code: noir_stdlib/src/collections/umap.nr#L420-L428"})})})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Checks if two UHashMaps are equal."}),"\n",(0,t.jsx)(n.p,{children:"Example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rust",metastring:'title="eq_example" showLineNumbers ',children:"let mut map1: UHashMap<Field, u64, BuildHasherDefault<Poseidon2Hasher>> = UHashMap::default();\nlet mut map2: UHashMap<Field, u64, BuildHasherDefault<Poseidon2Hasher>> = UHashMap::default();\n\nmap1.insert(1, 2);\nmap1.insert(3, 4);\n\nmap2.insert(3, 4);\nmap2.insert(1, 2);\n\nassert(map1 == map2);\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.sup,{children:(0,t.jsx)(n.sub,{children:(0,t.jsx)(n.a,{href:"https://github.com/noir-lang/noir/blob/master/test_programs/execution_success/uhashmap/src/main.nr#L280-L291",target:"_blank",rel:"noopener noreferrer",children:"Source code: test_programs/execution_success/uhashmap/src/main.nr#L280-L291"})})})}),"\n"]})]})}function u(e={}){const{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(h,{...e})}):h(e)}},28453(e,n,s){s.d(n,{R:()=>i,x:()=>l});var r=s(96540);const t={},a=r.createContext(t);function i(e){const n=r.useContext(a);return r.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:i(e.components),r.createElement(a.Provider,{value:n},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.