Tk_GetUid(3tk)

πŸ“¦
version 9.0.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ NAME ✨

ok so we're in the Tk library manual, section 3tk, and today's main characters are Tk_GetUid and Tk_Uid β€” they take a string and turn it into a unique identifier πŸ’«


🌸 SYNOPSIS 🌸

#include <tk.h>

Tk_Uid
Tk_GetUid(string)

πŸŽ€ ARGUMENTS πŸŽ€

  • char *string (in) β€” bestie, this is literally just the string you want the matching unique identifier for. that's it, that's the whole job 🫢

πŸ’… DESCRIPTION πŸ’…

okok so Tk_GetUid hands you back the unique identifier that corresponds to string. think of unique identifiers like atoms in Lisp β€” very that. Tk uses them to make comparisons and searches go fast, like zoom zoom ⚑

a unique identifier is type Tk_Uid, and ngl it's literally a string pointer. you can use it anywhere you'd use a variable of type char *. so far so normal, right? but here's the iconic part: there is guaranteed to be exactly one unique identifier for any given string value. one. single. not two. periodt πŸ‘‘

so if you call Tk_GetUid twice β€” once with string a and once with string b β€” and a and b have the same string value, meaning strcmp(a, b) == 0, then Tk_GetUid will return exactly the same Tk_Uid value for each call:

Tk_GetUid(a) == Tk_GetUid(b)

which means πŸ‘ you can compare variables of type Tk_Uid directly with x == y and you never have to call strcmp at all. no cap, that's the whole point. it's giving efficiency, it's giving main character energy πŸ”₯

and also (because of course) the return value from Tk_GetUid will have the same string value as its argument:

strcmp(Tk_GetUid(a), a) == 0

so like, it's still the same string, it just got ✨canonised✨


πŸ’– KEYWORDS πŸ’–

atom, unique identifier


πŸ¦‹ okay that's the whole page, nothing skipped, nothing extra, we ate and left no crumbs

mwah πŸ’‹ this one comes to you straight from the Tk library docs, page Tk_GetUid(3tk) β€” see you in the next one, bestie 🌈

πŸ“¦ where this page comes from