# vlib **Repository Path**: Lamdonn/vlib ## Basic Information - **Project Name**: vlib - **Description**: C语言版STL,包含通用数据类型的队列、堆栈、双端队列、向量、列表、集合、映射等容器,以及通用的排序算法 - **Primary Language**: C - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 11 - **Forks**: 6 - **Created**: 2022-12-03 - **Last Updated**: 2025-12-05 ## Categories & Tags **Categories**: utils **Tags**: None ## README # vlib介绍 [English version](README.md) ## 介绍 vlib(we-library,意为我们的代码库),这是一个C语言模板库,在C语言开发中很多功能模块都是重复开发的,重复开发就意味着开发的成本升高,可靠性降低。 vlib作为一个模板库,提供了类似C++ STL的功能,包含了常用的容器,而且容器在合理使用的情况下可以通用任意的数据类型。比如,链表的使用,常用的用法就是需要int型的链表,就针对int型的写一遍增删改查,换一种类型char型,又要重新写一套,如果一个项目中只需用到一个类型的链表就还好,万一项目要用到多种类型的呢。而在C++STL里面,就用list来封装了链表,想要什么类型就创建什么类型即可。 vlib的最初目的也就是提高在C语言开发中代码的复用性、通用性、便利性,方便在其他项目直接拿来就用。 ## 组成 从广义上讲分为三类:algorithm(算法)、container(容器)和iterator(迭代器)。 * 容器 | vlib容器 | 封装对象 | | :------: | :-----: | | str | 字符串 | | vector | 数组 | | queue | 队列 | | stack | 堆栈 | | deque | 双端队列 | | list | 链表 | | set | 集合 | | map | 映射 | * 迭代器 在vlib里面,提供了针对各个容器的通用迭代器。在在连续地址的容器中可以直接随机访问地址来遍历容器,但是在链式结构的容器中,容器的遍历就需要通过迭代器来访问。 迭代器为算法和容器之间提供了对接媒介。 * 算法 各个容器里面基本都包含了其对应的增删改查的操作,除此vlib提供了通用的算法,包含排序、计数、查找等。 ## 框架 ### 编程思想 vlib采用了面向对象的编程思想,所有的容器都被定义成了一个类(比如,queue类),每个类包含了这个类专属的方法和成员(比如,queue的queue_xxx进行命名),vlib所有的类都是继承于`vobject_t`父类的,也就是所有的容器都可以强转为`vobject_t`类来使用需要传入`vobject_t`参数的方法(比如,`int vtype(vobject_t object);`方法,可以将一个对象强转为`vobject_t`类获取这个对象是哪个类)。 ### 命名规范 vlib所有容器的类命名都是采用名字加上`_t`的形式,`_t`,比如,queue的类名为`queue_t`,list的类名为`list_t`。 vlib类的方法一般就是以名字加上功能关键字作为函数名的形式,`_()`,比如,`queue_create()`、`queue_push()`。 vlib采用面向对象的编程思想,一个对象就就会有其构造和析构方法,构造方法的命名格式为`()`,析构方法的命名格式为`_()`,比如,`queue_t`的构造方法和析构方法分别是`queue()`和`_queue()`,**这里注意析构方法不像C++中结束使用自动调用,而是需要手动调用进行析构**。 # 使用 [str使用说明](doc/str_zh.md) [vector使用说明](doc/vector_zh.md) [queue使用说明](doc/queue_zh.md) [stack使用说明](doc/stack_zh.md) [deque使用说明](doc/deque_zh.md) [list使用说明](doc/list_zh.md) [set使用说明](doc/set_zh.md) [map使用说明](doc/map_zh.md) [iterator使用说明](doc/iterator_zh.md) [algorithm使用说明](doc/algorithm_zh.md) # 安装 * linux ``` make && make install ``` # 修订历史 ``` +---------+------------+-------------------+----------------------------------------------------------+ | Version | Date | Module | Describe | +---------+------------+-----------+-------+----------------------------------------------------------+ | 1.0.0 | 2023/10/16 | queue | 1.1.0 | 1.Integrate various modules to form vlib 1.0.0 version. | | | | stack | 1.1.0 | 2.New addition of iterators and algorithm modules. | | | | deque | 1.1.0 | 3.Adjust the code of the original module to agree on | | | | str | 1.1.0 | style and specifications. | | | | vector | 1.1.0 | | | | | list | 1.1.0 | | | | | set | 1.1.0 | | | | | map | 1.1.0 | | | | | iterator | 1.0.0 | | | | | algorithm | 1.0.0 | | +---------+------------+-----------+-------+----------------------------------------------------------+ | x.x.x | xxxx/xx/xx | queue | x.x.x | Templete | | | | stack | x.x.x | | | | | deque | x.x.x | | | | | str | x.x.x | | | | | vector | x.x.x | | | | | list | x.x.x | | | | | set | x.x.x | | | | | map | x.x.x | | | | | iterator | x.x.x | | | | | algorithm | x.x.x | | +---------+------------+-----------+-------+----------------------------------------------------------+ ``` # 联系方式 Lamdonn@163.com