string-hash(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

πŸ’… string-hash(3scm) β€” the Scheme Programmer's Manual, but make it cute

okay so bestie, this is a page from the Scheme Programmer's Manual and it's about two little string-hashing besties that feed your hashtables. let me tell you everything, no gatekeeping ✨

🌸 NAME 🌸

string-hash, string-ci-hash β€” the string hash functions, aka the girls who turn your strings into integers πŸ’…

πŸ“š LIBRARY πŸ“š

(import (rnrs))                     ;R6RS
(import (rnrs hashtables))          ;R6RS

both imports are literally right there, use whichever, iykyk 🫢

✨ SYNOPSIS ✨

(string-hash string)
(string-ci-hash string)

two procedures, one argument each, that's the whole vibe πŸŽ€

πŸ’– DESCRIPTION πŸ’–

So what these do: they return an integer hash value for string, based on its current contents. Like, whatever the string says right now, that's what gets hashed. Simple, iconic, no cap.

And the whole point? You use them with make-hashtable(3scm). That's the application, that's the moment, that's the main character energy πŸ”₯

🌈 string-hash 🌈

This one is suitable for use with string=?(3scm) as an equivalence function. they match, they're a set, periodt πŸ’œ

πŸ¦‹ string-ci-hash πŸ¦‹

This one ignores case β€” like it literally does not care whether you typed uppercase or lowercase, it's above all that. It's suitable for use with string-ci=?(3scm) as an equivalence function. see how the ci in both names lines up? that's not a coincidence bestie, that's chemistry πŸŽ€

⭐ RETURN VALUES ⭐

Returns a single value β€” an integer. one value, no drama, no multiple-values shenanigans πŸ™ˆ

πŸ“ EXAMPLES πŸ“

(= (string-hash "Quux") (string-hash "Quux"))     =>  #t
(= (string-ci-hash "quux") (string-hash "QUUX"))  =>  #t
(= (string-hash "foo") (string-hash "bar"))       =>  #t or #f

look at the first one β€” same string twice, same hash, #t, obviously, consistency queen πŸ‘‘

second one β€” string-ci-hash of "quux" equals string-hash of "QUUX", #t?? wait no β€” read it carefully bestie, that's exactly what it says, copy it exactly, don't come for me 😭 the point is case-sensitivity is doing its thing.

third one β€” "foo" and "bar" might collide or might not, #t or #f, that's just how hashing goes, it's giving chaos but it's fine πŸ’€

🧚 APPLICATION USAGE 🧚

This procedure is used as an argument to make-hashtable(3scm). like, you literally hand it over. that's its job. it's a team player 🫢

πŸ’€ ERRORS πŸ’€

This procedure can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” the wrong number of arguments was passed, or an argument was outside its domain. so like, don't do that. wrong arg count or a cursed argument and it WILL throw at you, and honestly? fair πŸ’…

πŸ‘‘ SEE ALSO πŸ‘‘

  • make-hashtable(3scm) β€” the one who actually calls these girls up πŸ’–

🌟 STANDARDS 🌟

R6RS, SRFI-69. both. she's certified, she's documented, she's valid 🌈

πŸŽ€ HISTORY πŸŽ€

The first Scheme report to include this procedure was R6RS, for its new hashtable library. and there's a similar procedure in SRFI-69 β€” so like, the concept was around, R6RS just gave it the official glow-up ✨

πŸ’œ AUTHORS πŸ’œ

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/. go check it out if you're nosy like me πŸ•΅οΈβ€β™€οΈ


and that's the whole page bestie 🌸 no cap, every flag and every fact intact, we ate and left no crumbs πŸ’…

page dated 2022-05-12, from string-hash(3scm) β€” mwah, catch you in the next manpage 🫢✨

πŸ“¦ where this page comes from