summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-12-30 12:36:13 +0100
committerTyge Løvset <[email protected]>2022-12-30 14:38:39 +0100
commit4f0f45422fb58e9b134445ad6a4ea96d806214e8 (patch)
treeea0bb95c1f82fa5ec71218ce1f6d7ce9bfcc4e29 /include
parent0761c13f316cc98ae7756f3527931aa86bed5016 (diff)
downloadSTC-modified-4f0f45422fb58e9b134445ad6a4ea96d806214e8.tar.gz
STC-modified-4f0f45422fb58e9b134445ad6a4ea96d806214e8.zip
More restructuring of files and cleanup. Moved carr2.h and carr3.h to misc/include/old/ as it is not among classic containers.
Removed stctest.h: Recommending https://github.com/bvdberg/ctest instead.
Diffstat (limited to 'include')
-rw-r--r--include/stc/algo/filter.h28
-rw-r--r--include/stc/carr2.h152
-rw-r--r--include/stc/carr3.h157
-rw-r--r--include/stc/cstack.h5
4 files changed, 16 insertions, 326 deletions
diff --git a/include/stc/algo/filter.h b/include/stc/algo/filter.h
index 486568f2..10aeb7e7 100644
--- a/include/stc/algo/filter.h
+++ b/include/stc/algo/filter.h
@@ -23,24 +23,26 @@
/*
#include <stdio.h>
#define i_val int
-#define i_capacity 10
#include <stc/cstack.h>
#include <stc/algo/filter.h>
int main()
{
- cstack_int stk = cstack_INITIALIZER(int, {1, 2, 3, 4, 5, 6, 7, 8, 9});
-
- c_foreach (i, cstack_int, stk)
- printf(" %d", *i.ref);
- puts("");
-
- c_forfilter (i, cstack_int, stk
- , c_flt_skipwhile(i, *i.ref < 3)
- && (*i.ref & 1) == 0 // even only
- , c_flt_take(i, 2)) // break after 2
- printf(" %d", *i.ref);
- puts("");
+ c_WITH (cstack_int stk = {0}, cstack_int_drop(&stk)) {
+ c_FORLIST (i, int, {1, 2, 3, 4, 5, 6, 7, 8, 9})
+ cstack_int_push(&stk, i);
+
+ c_FOREACH (i, cstack_int, stk)
+ printf(" %d", *i.ref);
+ puts("");
+
+ c_FORFILTER (i, cstack_int, stk
+ , c_flt_skipwhile(i, *i.ref < 3)
+ && (*i.ref & 1) == 0 // even only
+ , c_flt_take(i, 2)) // break after 2
+ printf(" %d", *i.ref);
+ puts("");
+ }
}
*/
#ifndef STC_FILTER_H_INCLUDED
diff --git a/include/stc/carr2.h b/include/stc/carr2.h
deleted file mode 100644
index 89ae9b77..00000000
--- a/include/stc/carr2.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/* MIT License
- *
- * Copyright (c) 2022 Tyge Løvset, NORCE, www.norceresearch.no
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-#include "ccommon.h"
-
-#ifndef CARR2_H_INCLUDED
-#define CARR2_H_INCLUDED
-#include "forward.h"
-#include <stdlib.h>
-#endif
-/*
-// carr2- 2D dynamic array in one memory block with easy indexing.
-#define i_key int
-#include <stc/carr2.h>
-#include <stdio.h>
-
-int main() {
- int w = 7, h = 5;
- c_with (carr2_int image = carr2_int_new_uninit(w, h), carr2_int_drop(&image))
- {
- int *dat = carr2_int_data(&image);
- for (int i = 0; i < carr2_int_size(&image); ++i)
- dat[i] = i;
-
- for (int x = 0; x < image.xdim; ++x)
- for (int y = 0; y < image.ydim; ++y)
- printf(" %d", image.data[x][y]);
- puts("\n");
-
- c_foreach (i, carr2_int, image)
- printf(" %d", *i.ref);
- puts("");
- }
-}
-*/
-
-#ifndef _i_prefix
-#define _i_prefix carr2_
-#endif
-#include "priv/template.h"
-#if !c_option(c_is_forward)
-_cx_deftypes(_c_carr2_types, _cx_self, i_key);
-#endif
-
-STC_API _cx_self _cx_memb(_with_size)(size_t xdim, size_t ydim, i_key null);
-STC_API _cx_self _cx_memb(_with_data)(size_t xdim, size_t ydim, _cx_value* storage);
-STC_API _cx_value* _cx_memb(_release)(_cx_self* self);
-STC_API void _cx_memb(_drop)(_cx_self* self);
-#if !defined i_no_clone
-STC_API _cx_self _cx_memb(_clone)(_cx_self src);
-STC_API void _cx_memb(_copy)(_cx_self *self, const _cx_self* other);
-#endif
-
-STC_INLINE _cx_self _cx_memb(_new_uninit)(size_t xdim, size_t ydim) {
- return _cx_memb(_with_data)(xdim, ydim, c_alloc_n(_cx_value, xdim*ydim));
-}
-STC_INLINE size_t _cx_memb(_size)(const _cx_self* self)
- { return self->xdim*self->ydim; }
-
-STC_INLINE _cx_value *_cx_memb(_data)(_cx_self* self)
- { return *self->data; }
-
-STC_INLINE const _cx_value *_cx_memb(_at)(const _cx_self* self, size_t x, size_t y) {
- assert(x < self->xdim && y < self->ydim);
- return *self->data + self->ydim*x + y;
-}
-
-STC_INLINE size_t _cx_memb(_idx)(const _cx_self* self, size_t x, size_t y) {
- return self->ydim*x + y;
-}
-
-
-STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
- size_t n = self->xdim*self->ydim;
- return c_INIT(_cx_iter){n ? *self->data : NULL, *self->data + n};
-}
-
-STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self)
- { return c_INIT(_cx_iter){NULL, *self->data + self->xdim*self->ydim}; }
-
-STC_INLINE void _cx_memb(_next)(_cx_iter* it)
- { if (++it->ref == it->end) it->ref = NULL; }
-
-/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_implement)
-
-STC_DEF _cx_self _cx_memb(_with_data)(size_t xdim, size_t ydim, _cx_value* block) {
- _cx_self _arr = {c_alloc_n(_cx_value*, xdim), xdim, ydim};
- for (size_t x = 0; x < xdim; ++x, block += ydim)
- _arr.data[x] = block;
- return _arr;
-}
-
-STC_DEF _cx_self _cx_memb(_with_size)(size_t xdim, size_t ydim, i_key null) {
- _cx_self _arr = _cx_memb(_new_uninit)(xdim, ydim);
- for (_cx_value* p = _arr.data[0], *e = p + xdim*ydim; p != e; ++p)
- *p = null;
- return _arr;
-}
-
-#if !defined i_no_clone
-
-STC_DEF _cx_self _cx_memb(_clone)(_cx_self src) {
- _cx_self _arr = _cx_memb(_new_uninit)(src.xdim, src.ydim);
- for (_cx_value* p = _arr.data[0], *q = src.data[0], *e = p + _cx_memb(_size)(&src); p != e; ++p, ++q)
- *p = i_keyclone((*q));
- return _arr;
-}
-
-STC_DEF void _cx_memb(_copy)(_cx_self *self, const _cx_self* other) {
- if (self->data == other->data) return;
- _cx_memb(_drop)(self); *self = _cx_memb(_clone)(*other);
-}
-#endif
-
-STC_DEF _cx_value *_cx_memb(_release)(_cx_self* self) {
- _cx_value *values = self->data[0];
- c_free(self->data);
- self->data = NULL;
- return values;
-}
-
-STC_DEF void _cx_memb(_drop)(_cx_self* self) {
- if (!self->data) return;
- for (_cx_value* p = self->data[0], *q = p + _cx_memb(_size)(self); p != q; ) {
- --q; i_keydrop(q);
- }
- c_free(self->data[0]); /* values */
- c_free(self->data); /* pointers */
-}
-
-#endif
-#include "priv/template.h"
diff --git a/include/stc/carr3.h b/include/stc/carr3.h
deleted file mode 100644
index d167dd69..00000000
--- a/include/stc/carr3.h
+++ /dev/null
@@ -1,157 +0,0 @@
-/* MIT License
- *
- * Copyright (c) 2022 Tyge Løvset, NORCE, www.norceresearch.no
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-#include "ccommon.h"
-
-#ifndef CARR3_H_INCLUDED
-#define CARR3_H_INCLUDED
-#include "forward.h"
-#include <stdlib.h>
-#endif
-/*
-// carr3 - 3D dynamic array in one memory block with easy indexing.
-#define i_key int
-#include <stc/carr3.h>
-#include <stdio.h>
-
-int main() {
- int w = 7, h = 5, d = 3;
- c_with (carr3_int image = carr3_int_new_uninit(w, h, d), carr3_int_drop(&image))
- {
- int *dat = carr3_int_data(&image);
- for (int i = 0; i < carr3_int_size(&image); ++i)
- dat[i] = i;
-
- for (int x = 0; x < image.xdim; ++x)
- for (int y = 0; y < image.ydim; ++y)
- for (int z = 0; z < image.zdim; ++z)
- printf(" %d", image.data[x][y][z]);
- puts("\n");
-
- c_foreach (i, carr3_int, image)
- printf(" %d", *i.ref);
- puts("");
- }
-}
-*/
-
-#ifndef _i_prefix
-#define _i_prefix carr3_
-#endif
-#include "priv/template.h"
-
-#if !c_option(c_is_forward)
-_cx_deftypes(_c_carr3_types, _cx_self, i_key);
-#endif
-
-STC_API _cx_self _cx_memb(_with_size)(size_t xdim, size_t ydim, size_t zdim, i_key null);
-STC_API _cx_self _cx_memb(_with_data)(size_t xdim, size_t ydim, size_t zdim, _cx_value* storage);
-STC_API _cx_value* _cx_memb(_release)(_cx_self* self);
-STC_API void _cx_memb(_drop)(_cx_self* self);
-#if !defined i_no_clone
-STC_API _cx_self _cx_memb(_clone)(_cx_self src);
-STC_API void _cx_memb(_copy)(_cx_self *self, const _cx_self* other);
-#endif
-
-STC_INLINE _cx_self _cx_memb(_new_uninit)(size_t xdim, size_t ydim, size_t zdim) {
- return _cx_memb(_with_data)(xdim, ydim, zdim, c_alloc_n(_cx_value, xdim*ydim*zdim));
-}
-
-STC_INLINE size_t _cx_memb(_size)(const _cx_self* self)
- { return self->xdim*self->ydim*self->zdim; }
-
-STC_INLINE _cx_value* _cx_memb(_data)(_cx_self* self)
- { return **self->data; }
-
-STC_INLINE const _cx_value* _cx_memb(_at)(const _cx_self* self, size_t x, size_t y, size_t z) {
- assert(x < self->xdim && y < self->ydim && z < self->zdim);
- return **self->data + self->zdim*(self->ydim*x + y) + z;
-}
-
-STC_INLINE size_t _cx_memb(_idx)(const _cx_self* self, size_t x, size_t y, size_t z) {
- return self->zdim*(self->ydim*x + y) + z;
-}
-
-
-STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) {
- size_t n = _cx_memb(_size)(self);
- return c_INIT(_cx_iter){n ? **self->data : NULL, **self->data + n};
-}
-
-STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self)
- { return c_INIT(_cx_iter){NULL, **self->data + _cx_memb(_size)(self)}; }
-
-STC_INLINE void _cx_memb(_next)(_cx_iter* it)
- { if (++it->ref == it->end) it->ref = NULL; }
-
-/* -------------------------- IMPLEMENTATION ------------------------- */
-#if defined(i_implement)
-
-STC_DEF _cx_self _cx_memb(_with_data)(size_t xdim, size_t ydim, size_t zdim, _cx_value* block) {
- _cx_self _arr = {c_alloc_n(_cx_value**, xdim*(ydim + 1)), xdim, ydim, zdim};
- _cx_value** p = (_cx_value**) &_arr.data[xdim];
- for (size_t x = 0, y; x < xdim; ++x, p += ydim)
- for (y = 0, _arr.data[x] = p; y < ydim; ++y, block += zdim)
- p[y] = block;
- return _arr;
-}
-
-STC_DEF _cx_self _cx_memb(_with_size)(size_t xdim, size_t ydim, size_t zdim, i_key null) {
- _cx_self _arr = _cx_memb(_new_uninit)(xdim, ydim, zdim);
- for (_cx_value* p = **_arr.data, *e = p + xdim*ydim*zdim; p != e; ++p)
- *p = null;
- return _arr;
-}
-
-#if !defined i_no_clone
-
-STC_DEF _cx_self _cx_memb(_clone)(_cx_self src) {
- _cx_self _arr = _cx_memb(_new_uninit)(src.xdim, src.ydim, src.zdim);
- for (_cx_value* p = **_arr.data, *q = **src.data, *e = p + _cx_memb(_size)(&src); p != e; ++p, ++q)
- *p = i_keyclone((*q));
- return _arr;
-}
-
-STC_DEF void _cx_memb(_copy)(_cx_self *self, const _cx_self* other) {
- if (self->data == other->data) return;
- _cx_memb(_drop)(self); *self = _cx_memb(_clone)(*other);
-}
-#endif
-
-STC_DEF _cx_value* _cx_memb(_release)(_cx_self* self) {
- _cx_value *values = self->data[0][0];
- c_free(self->data);
- self->data = NULL;
- return values;
-}
-
-STC_DEF void _cx_memb(_drop)(_cx_self* self) {
- if (!self->data) return;
- for (_cx_value* p = **self->data, *q = p + _cx_memb(_size)(self); p != q; ) {
- --q; i_keydrop(q);
- }
- c_free(self->data[0][0]); /* data */
- c_free(self->data); /* pointers */
-}
-
-#endif
-#include "priv/template.h"
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index e4b64848..5e87cf9f 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -52,9 +52,6 @@ STC_INLINE _cx_self _cx_memb(_init)(void) {
}
#ifdef i_capacity
-#define cstack_INITIALIZER(T, ...) \
- {.data=__VA_ARGS__, ._len=sizeof((T[])__VA_ARGS__)/sizeof(T)}
-
STC_INLINE void _cx_memb(_create)(_cx_self* self)
{ self->_len = 0; }
#else
@@ -71,7 +68,7 @@ STC_INLINE _cx_self _cx_memb(_with_size)(size_t size, i_key null) {
while (size) out.data[--size] = null;
return out;
}
-#endif
+#endif // i_capacity
STC_INLINE void _cx_memb(_clear)(_cx_self* self) {
_cx_value *p = self->data + self->_len;