Skip to content

Commit ee5afac

Browse files
committed
Add cstl headers, comparators and docs
Introduce modular cstl headers and update comparators; add docs and small example fixes. Changes include: - Added opencstl/cstl.h and integrated cstl.h into opencstl/opencstl.h. - Refactored comparison API: renamed builtin compare functions to less_* and added greater_* counterparts; introduced CSTL_LESS/CSTL_GREATER and macros LESS(TYPE)/GREATER(TYPE) for easier comparator selection. - Exposed stable_sort/msort via cstl_msort and kept sort mapping to qsort. - Updated examples and main: switched GETLINE -> FGETLINE, updated qsort/bsearch calls to use LESS(), removed stray tokens, fixed printf format for size, added test02() which demonstrates GREATER sorting and is called from main (exits after run). - Documentation: added docs/README.md and linked it from README, README.ko.md and README.zh.md; removed mkdocs.yml. - Added amalgamate.bat and removed binary perftest. These changes reorganize compare/sort utilities, provide explicit less/greater helpers, and update examples/docs to use the new APIs.
1 parent d39698d commit ee5afac

16 files changed

Lines changed: 251 additions & 140 deletions

README.ko.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ curl -LO "https://raw.githubusercontent.com/springkim/OpenCSTL/refs/heads/master
4141
| MinGW64 || | |
4242
| Intel (icx-cc) ||||
4343

44+
## 문서
45+
46+
[문서](./docs/README.md)
47+
4448
## 예제
4549

4650
```c

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ curl -LO "https://raw.githubusercontent.com/springkim/OpenCSTL/refs/heads/master
4141
| MinGW64 || | |
4242
| Intel (icx-cc) ||||
4343

44+
## Document
45+
46+
[Document](./docs/README.md)
47+
48+
49+
4450
## Example
4551

4652
```c

README.zh.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ curl -LO "https://raw.githubusercontent.com/springkim/OpenCSTL/refs/heads/master
4141
| MinGW64 || | |
4242
| Intel (icx-cc) ||||
4343

44+
## 文档
45+
46+
[文档](./docs/README.md)
47+
48+
49+
4450
## 示例
4551

4652
```c

amalgamate.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
python amalgamate.py
2+
3+
pause

docs/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ C99 · C11 · C17 · C23
66

77
---
88

9+
10+
11+
[container document](./_containers.md)
12+
13+
14+
915
## Why OpenCSTL?
1016

1117
- **Single-header** — Just `#include "opencstl.h"` and you're done. No build steps, no linking.
@@ -131,7 +137,7 @@ int main() {
131137
| [`DEQUE`](__deque.md) | Sequence | `T*` | ✅ | `it++` |
132138
| [`SET`](__set.md) | Associative | `T**` | ❌ | `next(it)` |
133139
| [`MAP`](__map.md) | Associative | `K**` | ❌ | `next(it)` |
134-
| [`UNORDERED_SET`](__unordered_set.md) | Unordered | `T**` | ✅ (bucket) | `next(it)` |
140+
| [`UNORDERED_SET`](__unordered_set.md) | Unordered | `T**` | | `next(it)` |
135141
| [`UNORDERED_MAP`](__unordered_map.md) | Unordered | `K**` | ❌ | `next(it)` |
136142
| [`STACK`](__stack.md) | Adaptor | `T*` | ❌ | — |
137143
| [`QUEUE`](__queue.md) | Adaptor | `T*` | ❌ | — |

examples/example_02.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int main() {
66
FILE *fp = NULL;
77
FOPEN(&fp, "words_random.txt", "rt");
88
char line[1024] = {0};
9-
while (GETLINE(fp, line, 1024)) {
9+
while (FGETLINE(fp, line, 1024)) {
1010
int length = strlen(line);
1111
char *word = (char *) calloc(length + 1, sizeof(char));
1212
strncpy(word, line, length);
@@ -15,7 +15,7 @@ int main() {
1515
FCLOSE(fp);
1616

1717
// qsort example
18-
qsort(v,size(v), sizeof(char *), StringCmp);
18+
qsort(v,size(v), sizeof(char *), LESS(char*));
1919

2020

2121
for (int i = 0; i < size(v); i++) {
@@ -24,7 +24,7 @@ int main() {
2424

2525
// bsearch example
2626
char *key = "spring";
27-
void *iter = bsearch(&key, v,size(v), sizeof(char *), StringCmp);
27+
void *iter = bsearch(&key, v,size(v), sizeof(char *), LESS(char*));
2828

2929
int idx = (char **) iter - (char **) v;
3030
printf("bsearch: %s(%d)\n", *(char **) iter, idx);

examples/example_06.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include"opencstl.h"
22

33
int main() {
4-
QUEUE(int) q = new_priority_queue(int, IntCmp);
4+
QUEUE(int) q = new_priority_queue(int);
55
for (int i = 0; i < 10; i++) {
66
push(q, i);
77
}
@@ -12,5 +12,4 @@ int main() {
1212
puts("");
1313
destroy(q);
1414
return 0;
15-
qsort
1615
}

examples/example_basic_01.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ void example_map() {
4242
"vector", "list", "set", "map", "stack", "queue", "priority_queue", "unordered_map", "unordered_set"
4343
};
4444
size_t len = sizeof(containers) / sizeof(containers[0]);
45-
printf("Number of elements: %d\n", len);
46-
MAP(int) d = new_map(int, char*, COMPARE(int));
45+
printf("Number of elements: %llu\n", len);
46+
MAP(int) d = new_map(int, char*);
4747
for (int i = 0; i < len; i++) {
4848
insert(d, i, containers[i]);
4949
}

main.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void cstl_vector_test3() {
9292
}
9393

9494

95-
stable_sort(vec,size(vec), sizeof(int), COMPARE(int));
95+
stable_sort(vec,size(vec), sizeof(int), LESS(int));
9696
for (int i = 0; i < size(vec); i++) {
9797
printf("Sorted: [%lld]\n", vec[i]);
9898
}
@@ -369,6 +369,22 @@ void test01() {
369369
cstl_hash_test();
370370
}
371371

372+
void test02() {
373+
VECTOR(int) v = new_vector(int);
374+
for (int i = 0; i < 1000; i++) {
375+
push_back(v, rand32()%10000);
376+
}
377+
378+
sort(v,size(v), sizeof(int),GREATER(int));
379+
380+
381+
for (int i = 0; i < size(v); i++) {
382+
printf("%d\n", v[i]);
383+
}
384+
385+
exit(0);
386+
}
387+
372388
#include <stdio.h>
373389

374390
const char *get_c_version(void) {
@@ -423,6 +439,7 @@ void print_c_version(void) {
423439

424440

425441
int main() {
442+
test02();
426443
print_c_version();
427444
test01();
428445
//cstl_priority_queue_test();

mkdocs.yml

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)