Skip to content

Commit

Permalink
Merge branch 'master' into feat/size-bounds
Browse files Browse the repository at this point in the history
* master:
  Declare version 0.2.0
  Add double_ended example
  • Loading branch information
kdkasad committed May 14, 2024
2 parents 93f40bb + 854f58e commit 2f272eb
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
PREFIX = /usr/local

NAME = citer
VERSION = 0.1.0
VERSION = 0.2.0
LICENSE_HEADER_LENGTH = 18

# Order matters here. The "iterator" module must come first, so that when
Expand Down Expand Up @@ -58,6 +58,7 @@ EXAMPLES = \
skip_take_while \
zip \
reverse \
double_ended \
transform_reverse
EXAMPLES_BIN = $(addprefix examples/,$(EXAMPLES))

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Don't worry though; it's easy!

Simply run `make` in the root directory of the repository.

This will build three notable files: `citer.h`, `libciter.a`, and `libciter.so.0.1.0`.
This will build three notable files: `citer.h`, `libciter.a`, and `libciter.so.0.2.0`.

The examples in the `examples/` directory will also be built.
Those can be run to test CIter's features.
Expand All @@ -60,8 +60,8 @@ To install to a different location, run `make PREFIX=/path/to/install/into insta
Running `make install` will:
- install `citer.h` as `$(PREFIX)/include/citer.h`;
- install `libciter.a` as `$(PREFIX)/lib/libciter.a`;
- install `libciter.so.0.1.0` as `$(PREFIX)/lib/libciter.so.0.1.0`;
- create symbolic links `libciter.so` and `libciter.so.0` to `libciter.so.0.1.0` in `$(PREFIX)/lib`.
- install `libciter.so.0.2.0` as `$(PREFIX)/lib/libciter.so.0.2.0`;
- create symbolic links `libciter.so` and `libciter.so.0` to `libciter.so.0.2.0` in `$(PREFIX)/lib`.

### Uninstalling

Expand Down
76 changes: 76 additions & 0 deletions examples/double_ended.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* CIter - C library for lazily-evaluated iterators.
* Copyright (C) 2024 Kian Kasad <[email protected]>
*
* This file is part of CIter.
*
* CIter is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software
* Foundation, version 3 of the License.
*
* CIter is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with CIter. If not, see <https://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <stdlib.h>

#include <citer.h>

#define UNUSED(x) ((void) (x))

static void *map_deref(void *item, void *fn_data) {
(void) fn_data; /* Mark as unused. */
return *((void **) item);
}

static bool is_even(void *item, void *fn_data) {
UNUSED(fn_data);
return ((unsigned long) item) % 2 == 0;
}

static void print_item(void *item, void *fn_data) {
printf("%s: %lu\n", (const char *) fn_data, (unsigned long) item);
}

int main(int argc, char *argv[]) {
if (argc != 1) {
fprintf(stderr, "Usage: %s\n", argv[0]);
return 1;
}

unsigned long arr[] = { 1, 2, 3, 4, 5 };
iterator_t *it;

/*
* Double-ended iterators which must be tested:
* - [x] over_array
* - [ ] repeat (but we can't test this without take)
* - [x] chain
* - [x] filter
* - [x] map
* - [x] once
* - [x] flatten
* - [x] inspect
* - [x] reverse
*/

it = citer_over_array(arr, sizeof(*arr), sizeof(arr) / sizeof(*arr));
it = citer_map(it, map_deref, NULL);
it = citer_chain(it, citer_flatten(citer_once(citer_once((void *) 6ul))));
it = citer_inspect(it, print_item, "Before map");
it = citer_filter(it, is_even, NULL);
it = citer_reverse(it);

void *item;
while ((item = citer_next(it)))
printf("Got: %lu\n", (unsigned long) item);

citer_free(it);

return 0;
}
1 change: 1 addition & 0 deletions examples/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ run ./inspect {1..5}
run ./skip_take_while {1..100}
run ./zip {1..5} {a..e}
run ./reverse {a..f}
run ./double_ended
run ./transform_reverse

0 comments on commit 2f272eb

Please sign in to comment.