# set
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![GitHub release](https://img.shields.io/github/v/release/barrust/set.svg)](https://github.com/barrust/set/releases)
[![C/C++ CI](https://github.com/barrust/set/workflows/C/C++%20CI/badge.svg?branch=master)](https://github.com/barrust/set/actions)
[![codecov](https://codecov.io/gh/barrust/set/branch/master/graph/badge.svg)](https://codecov.io/gh/barrust/set)
A simple set implementation in **C**
Sets allow for quick checks for inclusion and exclusion
This implementation provides a simple and generally quick method to get set functionality into a C program quickly. It was developed to provide a basis for testing and benchmarking performance along with providing a purposeful, low overhead library. Currently only supports strings.
To use the library, copy the `src/set.h` and `src/set.c` files into your project and include it where needed.
## License
MIT 2016
# Main Features
* Union, intersection, difference, and semantic difference
* Standard and Strict subset and superset checks
* Simple method to change the hashing function if desired
* Add, check, and remove elements in a the set
## Future Enhancements
* In place union - add to an already created Set
* Print statistics about the set
## Usage:
``` c
#include "set.h"
#include <stdio.h>
int main(int argc, char** argv) {
SimpleSet set;
set_init(&set);
set_add(&set, "orange");
set_add(&set, "blue");
set_add(&set, "red");
set_add(&set, "green");
set_add(&set, "yellow");
if (set_contains(&set, "yellow") == SET_TRUE) {
printf("Set contains 'yellow'!\n");
} else {
printf("Set does not contains 'yellow'!\n");
}
if (set_contains(&set, "purple") == SET_TRUE) {
printf("Set contains 'purple'!\n");
} else {
printf("Set does not contains 'purple'!\n");
}
set_destroy(&set);
}
```
## Thread safety
Due to the the overhead of enforcing thread safety, it is up to the user to
ensure that each thread has controlled access to the set. For **OpenMP** code,
the following should suffice.
``` c
#include "set.h"
#include <omp.h>
int main(int argc, char** argv) {
SimpleSet set;
set_init(&set);
int i;
#pragma omp parallel for private(i)
for (i = 0; i < 500000; i++) {
char key[KEY_LEN] = {0};
sprintf(key, "%d", i);
#pragma omp critical (set_lock)
{
set_add(&set, key);
}
}
set_destroy(&set);
}
```
All but `set_contains` needs to be guarded against race conditions as the set
will grow as needed. Set comparison functions (union, intersect, etc.) should
be done on non-changing sets.
## Required Compile Flags:
None
没有合适的资源?快使用搜索试试~ 我知道了~
set:C语言中的简单集实现
共14个文件
c:3个
h:3个
md:2个
需积分: 28 3 下载量 35 浏览量
2021-05-19
05:56:22
上传
评论
收藏 21KB ZIP 举报
温馨提示
放 用C语言实现的简单集合 集允许快速检查是否包含和排除 此实现提供了一种简单且通常快速的方法,可将设置的功能快速获取到C程序中。 它的开发旨在为测试和基准测试性能提供基础,并提供有目的的,低开销的库。 当前仅支持字符串。 要使用该库,请将src/set.h和src/set.c文件复制到您的项目中,并在需要时将其包括在内。 执照 麻省理工学院2016 主要特点 并集,交集,差异和语义差异 标准和严格子集和超集检查 根据需要更改哈希函数的简单方法 添加,检查和删除集合中的元素 未来增强 就地联合-添加到已创建的Set中 打印有关集合的统计信息 用法: # include " set.h " # include < stdio> int main ( int argc, char ** argv) { SimpleSet set; set_init (&set);
资源推荐
资源详情
资源评论
收起资源包目录
set-master.zip (14个子文件)
set-master
codecov.yml 532B
.github
workflows
ci.yml 2KB
src
set.h 6KB
set.c 10KB
LICENSE 1KB
README.md 3KB
Makefile 1020B
dist
.gitkeep 0B
tests
timing.h 6KB
minunit.h 17KB
set_test.c 14KB
testsuite.c 12KB
.gitignore 494B
CHANGELOG.md 843B
共 14 条
- 1
资源评论
茶了不几
- 粉丝: 30
- 资源: 4772
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 南京邮电大学数学实验:熟练掌握 Matlab 软件的基本命令和操作
- 2017校招真题校园招聘真题算法题(37道)Python源码.zip
- 基于单片机protues仿真的多功能自动饮水机系统设计(仿真图、源代码、演示视频)
- 二叉树7-1-1.cpp
- android 9.0 原生模拟器 签名文件
- 技术面试最后反问面试官的话 校招面试非技术问题有哪些 非技术问题如何回答.png
- NB-IOT-BC26全网通模块Altium+ CADENCE +PADS三种格式(原理图SCH+PCB封装库)文件.zip
- 基于微信小程序开发的校园失物招领系统源码毕业设计(优质项目源码).zip
- 词向量是一种将自然语言中的单词转换为数值向量的技术,它能够捕捉词义和上下文信息
- nmap与masscan的简单使用
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功