qlibs:constmap(3)

πŸ“¦ version 31, in alpine 3.24

✨ NAME ✨

constmap β€” fetch matching strings from a hashed data structure in constant time πŸ’–

omg hi bestie!! welcome to qlibs:constmap(3) from the Library Functions Manual β€” yes, we're doing hashed data structure string fetching in constant time, and we're gonna make it make sense. 🫢


πŸŽ€ SYNTAX πŸŽ€

#include "constmap.h"

πŸ¦‹ SYNOPSIS πŸ¦‹

okay so here's the whole function squad, signatures kept exactly as they are, no cap:

int constmap_init(struct constmap *cm,const char *string,int len,int flagcolon);
int constmap_init_char(struct constmap *cm,const char *string,int len,int flagcolon,char flagchar);
int constmap_index(struct constmap *cm,const char *string,int len);
char *constmap(struct constmap *cm,const char *string,int len);
char *constmap_get(struct constmap *cm,int len);
void constmap_free(struct constmap *cm);

πŸ’… DESCRIPTION πŸ’…

Okay so picture this: you read a file β€” perhaps with control_readfile(&cmap,"path/filename",0) πŸ‘€ β€” and then constmap_init can turn its content into a constant time search map: constmap. Iconic behavior, honestly.

Here's the tea β˜•: you can specify whether the entries in constmap are plain or key/value structured by setting flagcolon to one, and it assumes the delimiter equals a colon: :. If the delimiter needs to be particularly tailored, use constmap_init_char instead. Periodt. πŸ’…

Now the main character energy: given the search string and providing its length len (without the trailing \0), constmap will now retrieve the information in constant time, returning a pointer to the search result or 0. Ngl, that's the whole vibe check. ✨

The datastructure can be freed by means of constmap_free. Cleanup slay. 🧚


🌈 EXAMPLE 🌈

here's the example, kept character-for-character β€” don't come for me about the double )), it's literally in the original 🫢:

#include <constmap.h>

 struct constmap cmap;
 stralloc result = {0};
 char *info;
 char *search;

 if (control_readfile(&cmap,"control/conf",0))
   constmap_init(&cmap,result.s,result.len,1));

 info = constmap(&cmap,search,str_len(search));
 if (!info) return 0;

πŸ‘‘ SEE ALSO πŸ‘‘

cdbread(3), cdbmake(3) β€” go read those too, bestie 🫢


Catch u later!! This page is qlibs:constmap(3) from the Library Functions Manual β€” the footer only brought the qlibs:constmap(3) source/version tag, no date, no drama. Mwah πŸ’‹

πŸ“¦ where this page comes from