From: Heng Li Date: Wed, 26 Sep 2018 01:48:03 +0000 (-0400) Subject: added kavl documentation X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=refs%2Fheads%2Fgh-pages;p=klib.git added kavl documentation --- diff --git a/index.html b/index.html index 20a4379..f9b7cf7 100644 --- a/index.html +++ b/index.html @@ -185,6 +185,8 @@ Error message and password prompt
  • Generic Programming in C
  • +
  • KAVL: generic intrusive AVL tree
  • +
  • KBtree: generic ordered map
  • Kdq: double-ended queue
  • @@ -8249,7 +8251,7 @@ pre .xml .cdata {
    lh3
    -
    +
    
     
    @@ -8384,7 +8386,7 @@ pre .xml .cdata {
    classic
    -
    +
    [[Klib|https://github.com/attractivechaos/klib/]] is a standalone and lightweight C library distributed under [[MIT/X11 license|http://en.wikipedia.org/wiki/MIT_License]]. Most components are independent of external libraries, except the standard C library, and independent of each other. To use a component of this library, you only need to copy a couple of files to your source code tree without worrying about library dependencies.
     
     Klib strives for efficiency and a small memory footprint. Some components, such as hash table, B-tree, vector and sorting algorithms, are among the most efficient implementations of similar algorithms or data structures in all programming languages, in terms of both speed and memory use.
    @@ -8393,6 +8395,7 @@ Klib strives for efficiency and a small memory footprint. Some components, such
     
     * [[khash.h|Khash: generic hash table]]: generic hash table based on double hashing.
     * [[kbtree.h|KBtree: generic ordered map]]: generic search tree based on B-tree.
    +* [[kavl.h|KAVL: generic intrusive AVL tree]]: generic intrusive AVL tree.
     * [[ksort.h|Ksort: sorting, shuffling, heap and k-small]]: generic sort, including introsort, merge sort, heap sort, comb sort, Knuth shuffle and the k-small algorithm.
     * [[kseq.h|Kseq: stream buffer and FASTA/Q parser]]: generic stream buffer and a FASTA/FASTQ format parser.
     * kvec.h: generic dynamic array.
    @@ -8563,6 +8566,50 @@ as type-specific code. A generic library written with `void*` will not get such
     performance boost.
     
    +
    +
    !!Synopsis
    +* Functionality: generic intrusive AVL tree additionally supporting counting
    +* Library source code: [[kavl.h|https://github.com/attractivechaos/klib/blob/master/kavl.h]]
    +* Dependencies: none
    +* Related articles: [[A single-header generic intrusive AVL tree in ANSI C|https://attractivechaos.wordpress.com/2018/04/19/a-single-header-generic-intrusive-avl-tree-in-ansi-c/]]
    +!!Example
    +!!!Example 1: inserting letters "MNOLKQOPHIA" in order
    +```c
    +#include <stdio.h>
    +#include <string.h>
    +#include <stdlib.h>
    +#include "kavl.h"
    + 
    +struct my_node {
    +    char key;
    +    KAVL_HEAD(struct my_node) head;
    +};
    +#define my_cmp(p, q) (((q)->key < (p)->key) - ((p)->key < (q)->key))
    +KAVL_INIT(my, struct my_node, head, my_cmp)
    + 
    +int main(void)
    +{
    +    const char *str = "MNOLKQOPHIA"; // from wiki, except a duplicate
    +    struct my_node *root = 0;
    +    int i, l = strlen(str);
    +    for (i = 0; i < l; ++i) {        // insert in the input order
    +        struct my_node *q, *p = malloc(sizeof(*p));
    +        p->key = str[i];
    +        q = kavl_insert(my, &root, p, 0);
    +        if (p != q) free(p);         // if already present, free
    +    }
    +    kavl_itr_t(my) itr;
    +    kavl_itr_first(my, root, &itr);  // place at first
    +    do {                             // traverse
    +        const struct my_node *p = kavl_at(&itr);
    +        putchar(p->key);
    +        free((void*)p);              // free node
    +    } while (kavl_itr_next(my, &itr));
    +    putchar('\n');
    +    return 0;
    +}
    +```
    +
    !!Synopsis
     * Functionality: generic balanced search tree based on B-tree.
    @@ -8775,12 +8822,12 @@ int main(int argc, char *argv[])
     }
     ```
    -
    +
    !!Synopsis
     * Functionality: generic hash table with [[open addressing|http://en.wikipedia.org/wiki/Open_addressing]]
     * Library source code: [[khash.h|https://github.com/attractivechaos/klib/blob/master/khash.h]]
     * Dependencies: none
    -* Related articles: [[Implementing generic hash library in C|https://attractivechaos.wordpress.com/2008/09/02/implementing-generic-hash-library-in-c/]], [[Another look at my old benchmarks|https://attractivechaos.wordpress.com/2008/10/07/another-look-at-my-old-benchmark/]] and [[Comparison of hash table libraries|https://attractivechaos.wordpress.com/2008/08/28/comparison-of-hash-table-libraries/]]
    +* Related articles: [[Implementing generic hash library in C|https://attractivechaos.wordpress.com/2008/09/02/implementing-generic-hash-library-in-c/]], [[Another look at my old benchmarks|https://attractivechaos.wordpress.com/2008/10/07/another-look-at-my-old-benchmark/]], [[Comparison of hash table libraries|https://attractivechaos.wordpress.com/2008/08/28/comparison-of-hash-table-libraries/]] and [[Revisiting hash table performance|https://attractivechaos.wordpress.com/2018/01/13/revisiting-hash-table-performance/]]
     !!Example
     !!!Example 1: hash table for integers
     ```c