开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (2)
标签 (5)
master
map-shrink
v1.0.4
v1.0.3
v1.0.2
v1.0.1
v1.0.0
master
分支 (2)
标签 (5)
master
map-shrink
v1.0.4
v1.0.3
v1.0.2
v1.0.1
v1.0.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (2)
标签 (5)
master
map-shrink
v1.0.4
v1.0.3
v1.0.2
v1.0.1
v1.0.0
sc
/
array
/
sc_array.h
sc
/
array
/
sc_array.h
sc_array.h 8.37 KB
一键复制 编辑 原始数据 按行查看 历史
Ozan Tezcan 提交于 2023年06月03日 05:37 +08:00 . Documentation (#121)
/*
* BSD-3-Clause
*
* Copyright 2021 Ozan Tezcan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SC_ARRAY_H
#define SC_ARRAY_H
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#define SC_ARRAY_VERSION "2.0.0"
#ifdef SC_HAVE_CONFIG_H
#include "config.h"
#else
#define sc_array_realloc realloc
#define sc_array_free free
#endif
#ifndef SC_ARRAY_MAX
#define SC_ARRAY_MAX SIZE_MAX
#endif
#define sc_array_def(T, name) \
struct sc_array_##name { \
bool oom; \
size_t cap; \
size_t size; \
/* NOLINTNEXTLINE */ \
T *elems; \
}
/**
* Init array
* @param a array
*/
#define sc_array_init(a) \
do { \
memset((a), 0, sizeof(*(a))); \
} while (0)
/**
* Destroy array
* @param a array
*/
#define sc_array_term(a) \
do { \
sc_array_free((a)->elems); \
sc_array_init(a); \
} while (0)
/**
* Add elem to array, call sc_array_oom(v) to see if 'add' failed because of out
* of memory.
*
* @param a array
* @param k elem
*/
#define sc_array_add(a, k) \
do { \
const size_t _max = SC_ARRAY_MAX / sizeof(*(a)->elems); \
size_t _cap; \
void *_p; \
\
if ((a)->cap == (a)->size) { \
if ((a)->cap > _max / 2) { \
(a)->oom = true; \
break; \
} \
_cap = (a)->cap == 0 ? 8 : (a)->cap * 2; \
_p = sc_array_realloc((a)->elems, \
_cap * sizeof(*((a)->elems))); \
if (_p == NULL) { \
(a)->oom = true; \
break; \
} \
(a)->cap = _cap; \
(a)->elems = _p; \
} \
(a)->oom = false; \
(a)->elems[(a)->size++] = k; \
} while (0)
/**
* Deletes items from the array without deallocating underlying memory
* @param a array
*/
#define sc_array_clear(a) \
do { \
(a)->size = 0; \
(a)->oom = false; \
} while (0)
/**
* @param a array
* @return true if last add operation failed, false otherwise.
*/
#define sc_array_oom(a) ((a)->oom)
/**
* Get element at index i, if 'i' is out of range, result is undefined.
*
* @param a array
* @param i index
* @return element at index 'i'
*/
#define sc_array_at(a, i) ((a)->elems[i])
/**
* @param a array
* @return element count
*/
#define sc_array_size(a) ((a)->size)
/**
* @param a array
* @param i element index, If 'i' is out of the range, result is undefined.
*/
#define sc_array_del(a, i) \
do { \
size_t idx = (i); \
assert(idx < (a)->size); \
\
const size_t _cnt = (a)->size - (idx) - 1; \
if (_cnt > 0) { \
memmove(&((a)->elems[idx]), &((a)->elems[idx + 1]), \
_cnt * sizeof(*((a)->elems))); \
} \
(a)->size--; \
} while (0)
/**
* Deletes the element at index i, replaces last element with the deleted
* element unless deleted element is the last element. This is faster than
* moving elements but elements will no longer be in the 'add order'
*
* arr[a,b,c,d,e,f] -> sc_array_del_unordered(arr, 2) - > arr[a,b,f,d,e]
*
* @param a array
* @param i index. If 'i' is out of the range, result is undefined.
*/
#define sc_array_del_unordered(a, i) \
do { \
size_t idx = (i); \
assert(idx < (a)->size); \
(a)->elems[idx] = (a)->elems[(--(a)->size)]; \
} while (0)
/**
* Deletes the last element. If current size is zero, result is undefined.
* @param a array
*/
#define sc_array_del_last(a) \
do { \
assert((a)->size != 0); \
(a)->size--; \
} while (0)
/**
* Sorts the array using qsort()
* @param a array
* @param cmp comparator, check qsort() documentation for details
*/
#define sc_array_sort(a, cmp) \
(qsort((a)->elems, (a)->size, sizeof(*(a)->elems), cmp))
/**
* Returns last element. If array is empty, result is undefined.
* @param a array
*/
#define sc_array_last(a) (a)->elems[(a)->size - 1]
/**
* @param a array
* @param elem elem
*/
#define sc_array_foreach(a, elem) \
for (size_t _k = 1, _i = 0; _k && _i != (a)->size; _k = !_k, _i++) \
for ((elem) = (a)->elems[_i]; _k; _k = !_k)
// (type, name)
sc_array_def(int, int);
sc_array_def(unsigned int, uint);
sc_array_def(long, long);
sc_array_def(long long, ll);
sc_array_def(unsigned long, ulong);
sc_array_def(unsigned long long, ull);
sc_array_def(uint32_t, 32);
sc_array_def(uint64_t, 64);
sc_array_def(double, double);
sc_array_def(const char *, str);
sc_array_def(void *, ptr);
#endif
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

Common libraries and data structures for C.
取消

发行版

暂无发行版

贡献者

全部

语言

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/embedded-lib/sc.git
git@gitee.com:embedded-lib/sc.git
embedded-lib
sc
sc
master
点此查找更多帮助

搜索帮助

仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /