qlibs:constmap

Section: C Library Functions (3)
Index Return to Main Contents
 

NAME

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

SYNTAX

#include "constmap.h"  

SYNOPSIS

int constmap_init(struct constmap *cm,char *string,int len,int flagcolon);
int constmap_init_char(struct constmap *cm,char *string,int len,int flagcolon,char flagchar);
char *constmap(struct constmap *cm,char *string,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)


 

Index

NAME
SYNTAX
SYNOPSIS
DESCRIPTION
EXAMPLE
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 14:55:38 GMT, December 15, 2024