Manpage logo

constmap - fetch matching strings from a hashed data structure in constant time

NAME  SYNTAX  SYNOPSIS  DESCRIPTION  EXAMPLE  SEE ALSO 

NAME

constmap − fetch matching strings from a hashed data structure in constant time

SYNTAX

#include "constmap.h"

SYNOPSIS

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

Reading a file perhaps with control_readfile(&cmap,"path/filename",0) constmap_init can be used to convert its content into a constant time search map: constmap. Here, you can specify whether the entries in constmap are plain or key/value structured setting flagcolon to one and assuming the delimiter equals to a colon: :. If the delimiter needs to be particulary tailored, use constmap_init_char.

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.

The datastructure can be freed by means of constmap_free.

EXAMPLE

#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)


Updated 2026-06-01 - jenkler.se | uex.se