qlibs:constmap(3)
β¨ 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
- alpine 3.24: fehqlibs-doc 31-r0 Β· Public-Domain
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms