<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/getorput-with-string-keys-wkzqdse3e" -->

---
title: GetOrPut With String Keys | daily.dev
description: This post explains Zig's `getOrPut` hashmap method, detailing its ability to return pointers to values and keys, and how it simplifies incrementing counters...
canonical: https://daily.dev/posts/getorput-with-string-keys-wkzqdse3e
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: GetOrPut With String Keys | daily.dev
og:description: This post explains Zig's `getOrPut` hashmap method, detailing its ability to return pointers to values and keys, and how it simplifies incrementing counters...
og:url: https://daily.dev/posts/getorput-with-string-keys-wkzqdse3e
og:image: https://api.daily.dev/og/posts/wkzqdsE3E.png
og:image:alt: GetOrPut With String Keys
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# GetOrPut With String Keys

**[openmymind](https://daily.dev/sources/Karl Seguin)** · 7 min read · 1 upvotes · 0 comments

## Summary

This post explains Zig's `getOrPut` hashmap method, detailing its ability to return pointers to values and keys, and how it simplifies incrementing counters with a single hash lookup. It also discusses the importance of key ownership, the potential for memory leaks, and the correct use of getOrPut to avoid such issues.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.openmymind.net/GetOrPut_With_String_Keys/>

---

Tags: [#performance](https://daily.dev/tags/performance), [#data-structures](https://daily.dev/tags/data-structures), [#zig](https://daily.dev/tags/zig)

[View this post on daily.dev](https://daily.dev/posts/getorput-with-string-keys-wkzqdse3e)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"GetOrPut With String Keys","url":"https://daily.dev/posts/getorput-with-string-keys-wkzqdse3e","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/getorput-with-string-keys-wkzqdse3e"},"datePublished":"2025-02-28T02:54:11.826Z","dateModified":"2025-02-28T02:54:28.014Z","description":"This post explains Zig's `getOrPut` hashmap method, detailing its ability to return pointers to values and keys, and how it simplifies incrementing counters...","image":"https://media.daily.dev/image/upload/s--58gMhC4P--/f_auto/v1722860399/public/Placeholder%2012","thumbnailUrl":"https://media.daily.dev/image/upload/s--58gMhC4P--/f_auto/v1722860399/public/Placeholder%2012","isAccessibleForFree":true,"articleSection":"openmymind","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"openmymind","logo":"https://media.daily.dev/image/upload/s--Dey09a13--/f_auto/v1723789434/logos/Karl%20Seguin","url":"https://daily.dev/sources/Karl Seguin"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/getorput-with-string-keys-wkzqdse3e","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"performance,data-structures,zig","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"openmymind","item":"https://daily.dev/sources/Karl Seguin"},{"@type":"ListItem","position":3,"name":"GetOrPut With String Keys"}]}
```

