Skip to content

Commit

Permalink
readme again
Browse files Browse the repository at this point in the history
  • Loading branch information
glouw committed Dec 29, 2020
1 parent 6200e78 commit 5aa8dc7
Showing 1 changed file with 71 additions and 51 deletions.
122 changes: 71 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,53 @@ CTL is a fast compiling, type safe, header only, template-like library for ISO C
CTL aims to improve C99 developer productivity by implementing the following
STL containers in ISO C99:

deq.h = std::deque
lst.h = std::list
pqu.h = std::priority_queue
que.h = std::queue
set.h = std::set
stk.h = std::stack
str.h = std::string
vec.h = std::vector
```
deq.h = std::deque
lst.h = std::list
pqu.h = std::priority_queue
que.h = std::queue
set.h = std::set
stk.h = std::stack
str.h = std::string
vec.h = std::vector
```

## Use

Configure a CTL container with a built-in or typedef type `T`.

#include <stdio.h>

#define P
#define T int
#include <vec.h>

int compare(int* a, int* b) { return *b < *a; }

int main(void)
{
vec_int a = vec_int_init();
vec_int_push_back(&a, 9);
vec_int_push_back(&a, 1);
vec_int_push_back(&a, 8);
vec_int_push_back(&a, 3);
vec_int_push_back(&a, 4);
vec_int_sort(&a, compare);
foreach(vec_int, &a, it,
printf("%d\n", *it.ref);
)
vec_int_free(&a);
}
```C
#include <stdio.h>

#define P
#define T int
#include <vec.h>

int compare(int* a, int* b) { return *b < *a; }

int main(void)
{
vec_int a = vec_int_init();
vec_int_push_back(&a, 9);
vec_int_push_back(&a, 1);
vec_int_push_back(&a, 8);
vec_int_push_back(&a, 3);
vec_int_push_back(&a, 4);
vec_int_sort(&a, compare);
foreach(vec_int, &a, it,
printf("%d\n", *it.ref);
)
vec_int_free(&a);
}
```
Definition `P` states type `T` is Plain Old Data (POD).
To compile, include the `ctl` directory:
gcc main.c -I ctl
```shell
gcc main.c -I ctl
```

For a much more thorough getting started guide,
see the wiki: https://github.com/glouw/ctl/wiki
Expand All @@ -58,16 +64,20 @@ Types with memory ownership require definition `P` be omitted, and require
function declarations for the C++ equivalent of the destructor and copy constructor,
prior to the inclusion of the container:

typedef struct { ... } type;
void type_free(type*);
type type_copy(type*);
#define T type
#include <vec.h>
```C
typedef struct { ... } type;
void type_free(type*);
type type_copy(type*);
#define T type
#include <vec.h>
```
Forgetting a declaration will print a human-readable error message:
tests/test_c99.c:11:11: error: ‘type_free’ undeclared (first use in this function)
11 | #define T type
```shell
tests/test_c99.c:11:11: error: ‘type_free’ undeclared (first use in this function)
11 | #define T type
```

## Performance

Expand All @@ -91,32 +101,42 @@ Note, CTL strings do not support short strings.

To run all functional tests, run:

make
```shell
make
```

To compile examples, run:

make examples
```shell
make examples
```

To generate performance graphs, run:

sh gen_images.sh
# Graphing requires python3 and the Plotly family of libraries via pip3.
```shell
sh gen_images.sh
# Graphing requires python3 and the Plotly family of libraries via pip3.
```

To do all of the above in one step, run:

./all.sh
```shell
./all.sh
```

For maintaining CTL, a container templated to type `int` can be
outputted to `stdout` by running make on the container name, eg:

make deq
make lst
make pqu
make que
make set
make stk
make str
make vec
```shell
make deq
make lst
make pqu
make que
make set
make stk
make str
make vec
```

## Other

Expand Down

0 comments on commit 5aa8dc7

Please sign in to comment.