HFL(3)                     Library Functions Manual                     HFL(3)



NAME
       hfl - hashtb api for C-lang

SYNOPSIS
        typedef struct hfl_node_tag {
            int tp;        // 'i'nt, 'd'bl, 'p'tr, 's'tr(or 's'truct)
            char* key;
            int i;
            double d;
            void* p;
            char* s;
            int ssz;
            //..opaque data
        } hfl_nt;

        typedef struct hfl_tag{
            uint32_t cnt;
            //..opaque data
        } hfl_t;

        hfl_t*   hfl_new([uint32_t sz]);
        void* hfl_free(hfl_t* obj);
        hfl_nt* hfl_unset(hfl_t* obj, char* key);
        hfl_nt* hfl_find(hfl_t* obj, char* key);
        hfl_t* hfl_clear(hfl_t* obj);

        #define  hfl_set_i(obj,k,v)
        #define  hfl_set_d(obj,k,v)
        #define  hfl_set_p(obj,k,v)
        #define  hfl_set_s(obj,k,ptr,[sz])
        #define  hfl_foreach(node, obj)




TL_DR
        #include "hfl.h"

        int main(int argc, char** argv){
            hfl_t* obj = hfl_new();
            hfl_nt* np = hfl_set_i(obj, "k1", 12);
            puts(rp->key); // "k1"
            int tp = rp->tp;    // int == 'i'
            hfl_unset(obj, "k1");    //del

            np = hfl_set_s(obj, "k2", "hw");
            puts(np->s);   // "hw"
            np = hfl_find(obj, "k2");
            puts(np->s);   // "hw", np->ssz == 0 (nochange, ag4 isnt)

            hfl_set_s(obj, "k3", "hi\0gw", 5); //ag4 isnt/is == strdup/malloc
            np = hfl_find(obj, "k3");
            strncmp(np->s, "hi\0gw", np->ssz); // == 0, np->ssz==5

            hfl_foreach(p, obj){
                 puts(p->key);
                 hfl_set_i(obj, p->key, 2);    //ok, replace/update
                 hfl_unset(obj, p->key);  //ok
                 // hfl_set_i(obj, "new", 2);  //NG, add newkey
                 p->i = 10;     // allow direct set, not recommend
            }

            np = hfl_unset(obj, "k2");
            np = hfl_find(obj, "k2");     //np == NULL;
            int cnt = obj->cnt; //holding keys

            obj = hfl_clear(obj);    //del allkeys, obj->cnt == 0

            hfl_free(obj);
            return 0;
        }
        //~$ cc src.c libhfl.a


DESCRIPTION
       c99  hsearch()  allows  only 1 hashtb in 1 pg.  hfl allows to hold many
       hashtb.
            --- bench mark: c_arr, c99hash, hfl, gtkhash
              FAST: c_arr(1) < c99hash == hfl == ghash (20) :SLOW
       consume time of get/set is almost the same.

       hfl_set_s(obj, key, vptr, [memsz]) saves mem  using  strdup()/malloc().
       use malloc() if ag4 exist and not 0. buffmem is freed when hfl_free().

EXSAMPLE
       -

RETURN_VALUE
       suc/fail == ptr, int 0 / NULL, int not0

ERRORS
       output emsg and exit(1) if fatal err

NOTES
       -

CONFORMING_TO
       POSIX.1-2001+ (-D_XOPEN_SOURCE=600/_POSIX_C_SOURCE=200112L)

COPYRIGHT
       Copyright 2022 momi-g, GPLv3+

VERSION
       2022-07-11 v1.0.6 (2022-05-29 v1.0.0)

SEE_ALSO
       https://probablydance.com/2017/02/26/i-wrote-the-fastest-hashtable/
       https://github.com/skarupke/flat_hash_map




                                                                        HFL(3)
