• 【Nginx】基本数据结构


    整型的封装

    typedef intptr_t ngx_int _t;//有符号整型

    typedef uintptr_t ngx_uint_t;//无符号整型

    字符串的封装

    typedef struct
    {
        size_t len;
        u_char *data;      
    }ngx_str_t;

    链表容器的封装

    typedef struct ngx_list_part_s ngx_list_part_t;
    //链表结点
    struct ngx_list_part_s
    {
        void *elts;//数组的起始地址
        ngx_uint_t nelts;//数组中已经使用的元素个数,必须小于nalloc
        ngx_list_part_t *next;//
    };
    
    typedef struct
    {
        ngx_list_part_t *last;
        ngx_list_part_t part;
        size_t size;//ngx_list_part_t中元素的大小上限
        ngx_uint_t nalloc;//每个ngx_list_part数组的容量
        ngx_pool_t *pool;//链表中管理内存分配的内存池对象
    }ngx_list_t;

    对于链表,Nginx提供的接口包括:

    //pool为内存池对象,size是结点中数组的每个元素的大小,n是数组中可容纳元素的个数,即结点大小为n*size

    ngx_list_t *ngx_list_create(ngx_pool_t *pool,ngx_uint_t n,size_t size);

    //初始化一个已有的链表

    static ngx_inline ngx_int_t ngx_list_init(ngx_list_t *list,ngx_pool_t *pool,ngx_uint_t n,size_t size);

    //添加新的元素

    void *ngx_list_push(ngx_list_t *list);

    ngx_table_elt_t数据成员

    typedef struct

    {

        ngx_uint_t hash;

        ngx_str_t key;

        ngx_str_t value;

        u_char *lowcase_key;

    }ngx_table_elt_t;

    ngx_table_elt_t常用于http头部。

    ngx_buf_t数据结构

    缓冲区ngx_buf_t是Nginx处理大数据的关键数据结构,它既应用于内存数据也应用于磁盘数据。

    ngx_chain_t数据结构

    ngx_chain_t是与ngx_buf_t配合使用的链表数据结构。

    typedef struct ngx_chain_s ngx_chain_t;

    struct ngx_chain_s

    {

      ngx_buf_t *buf;

      ngx_chain_t *next;

    };

  • 相关阅读:
    [leetcode] Combinations
    [leetcode] Search for a Range
    [leetcode] Combination Sum II
    [leetcode] Combination Sum
    [leetcode] Reverse Bits
    [leetcode] Number of 1 Bits
    [leetcode] Longest Substring Without Repeating Characters
    [leetcode] Reverse Words in a String
    [leetcode] Rotate Array
    习题8-3 数组循环右移
  • 原文地址:https://www.cnblogs.com/ljygoodgoodstudydaydayup/p/3826304.html
Copyright © 2020-2023  润新知