4 Star 7 Fork 3

Gitee 极速下载/c-compiler

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/rui314/8cc
克隆/下载
set.c 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
Rui Ueyama 提交于 2015-03-28 10:51 . Update copyright notice.
// Copyright 2014 Rui Ueyama. Released under the MIT license.
// Sets are containers that store unique strings.
//
// The data structure is functional. Because no destructive
// operation is defined, it's guranteed that a set will never
// change once it's created.
//
// A null pointer represents an empty set.
//
// Set is designed with simplicity in mind.
// It should be very fast for small number of items.
// However, if you plan to add a lot of items to a set,
// you should consider using Map as a set.
#include <stdlib.h>
#include <string.h>
#include "8cc.h"
Set *set_add(Set *s, char *v) {
Set *r = malloc(sizeof(Set));
r->next = s;
r->v = v;
return r;
}
bool set_has(Set *s, char *v) {
for (; s; s = s->next)
if (!strcmp(s->v, v))
return true;
return false;
}
Set *set_union(Set *a, Set *b) {
Set *r = b;
for (; a; a = a->next)
if (!set_has(b, a->v))
r = set_add(r, a->v);
return r;
}
Set *set_intersection(Set *a, Set *b) {
Set *r = NULL;
for (; a; a = a->next)
if (set_has(b, a->v))
r = set_add(r, a->v);
return r;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/mirrors/c-compiler.git
git@gitee.com:mirrors/c-compiler.git
mirrors
c-compiler
c-compiler
master

搜索帮助