EC_DICT_SET(3)

πŸ’– EC_DICT_SET(3) β€” the libecoli era πŸ’–

okay bestie, so this is a page from the Libecoli Programmer's Manual, and it's all about ec_dict_set from <ecoli/dict.h>. yes we're doing C today. yes it's giving low-level. yes you're gonna slay it. πŸ¦‹


✨ NAME ✨

ec_dict_set β€” put a thing in the hash table, or swap out the thing that's already there. add or replace, your call, she does both. πŸ’…


🌸 SYNOPSIS 🌸

#include <ecoli/dict.h>

int ec_dict_set(
    struct ec_dict     *dict,     /* The hash table. */
    const char         *key,      /* The key string. Must not be NULL. */
    void               *val,      /* The pointer to be saved in the hash table. */
    /*
     * An optional pointer to a destructor function called when an object is
     * destroyed (ec_dict_del() or ec_dict_free()).
     */
    ec_dict_elt_free_t  free_cb
);

so like, four things go in:

  • dict β€” the hash table itself. the main character. πŸ‘‘
  • key β€” the key string. and bestie, listen, it must NOT be NULL. no cap, that's a hard rule, don't test her. πŸ™ˆ
  • val β€” the pointer you want her to hold onto inside the hash table. that's the whole point, that's the vibe. ✨
  • free_cb β€” an optional pointer to a destructor function. it gets called whenever an object is destroyed, aka when ec_dict_del() or ec_dict_free() comes for it. it's giving cleanup crew energy. 🧹

πŸ’œ RETURN VALUE πŸ’œ

0 when it works. -1 when it doesn't, and then errno gets set because of course it does. 😭

okay but here's the tea: on error, the value you passed in gets freed β€” literally free_cb(val) is called. so don't go touching that pointer afterwards, she's gone, she's been freed, rest in peace. πŸ’€

🫢 SEE ALSO 🫢

the whole friend group, go say hi:


Copyright (C) 2010-2026 Olivier Matz, Robin Jarry.


and that's the whole page bestie, written by the libecoli girlies, dated 2026-06-11, version libecoli. mwah. go forth and set some dicts. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from