Skip to content

Commit

Permalink
I to Z with a test. small string fix
Browse files Browse the repository at this point in the history
  • Loading branch information
glouw committed Jul 1, 2021
1 parent 0dac6e8 commit 435a2e6
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 100 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ CFLAGS += -DSRAND
endif

TESTS = \
tests/func/test_std_headers \
tests/func/test_c11 \
tests/func/test_container_composing \
tests/func/test_deq \
Expand Down Expand Up @@ -116,6 +117,7 @@ examples/postfix: ALWAYS; $(CC) $(CFLAGS) $@.c -o $@
examples/json: ALWAYS; $(CC) $(CFLAGS) $@.c -o $@
examples/snow: ALWAYS; $(CC) $(CFLAGS) $@.c -o $@
examples/6502: ALWAYS; $(CC) $(CFLAGS) $@.c -o $@
tests/func/test_std_headers: ALWAYS; $(CC) $(CFLAGS) $@.c -o $@
tests/func/test_c11: ALWAYS; $(CC) $(CFLAGS) $@.c -o $@
tests/func/test_container_composing: ALWAYS; $(CXX) $(CFLAGS) $@.cc -o $@
tests/func/test_deq: ALWAYS; $(CXX) $(CFLAGS) $@.cc -o $@
Expand Down
34 changes: 17 additions & 17 deletions ctl/deq.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#define A JOIN(deq, T)
#define B JOIN(A, bucket)
#define I JOIN(A, it)
#define Z JOIN(A, it)

#define DEQ_BUCKET_SIZE (512)

Expand All @@ -34,17 +34,17 @@ typedef struct A
}
A;

typedef struct I
typedef struct Z
{
void (*step)(struct I*);
void (*step)(struct Z*);
A* container;
T* ref;
size_t index;
size_t index_next;
size_t index_last;
int done;
}
I;
Z;

static inline B**
JOIN(A, first)(A* self)
Expand Down Expand Up @@ -99,7 +99,7 @@ JOIN(A, end)(A* self)
}

static inline void
JOIN(I, step)(I* self)
JOIN(Z, step)(Z* self)
{
self->index = self->index_next;
if(self->index == self->index_last)
Expand All @@ -111,15 +111,15 @@ JOIN(I, step)(I* self)
}
}

static inline I
JOIN(I, range)(A* container, T* begin, T* end)
static inline Z
JOIN(Z, range)(A* container, T* begin, T* end)
{
static I zero;
I self = zero;
static Z zero;
Z self = zero;
if(begin && end)
{
self.container = container;
self.step = JOIN(I, step);
self.step = JOIN(Z, step);
self.index = begin - JOIN(A, begin)(container);
self.index_next = self.index + 1;
self.index_last = container->size - (JOIN(A, end)(container) - end);
Expand All @@ -136,12 +136,12 @@ JOIN(A, empty)(A* self)
return self->size == 0;
}

static inline I
JOIN(I, each)(A* a)
static inline Z
JOIN(Z, each)(A* a)
{
return JOIN(A, empty)(a)
? JOIN(I, range)(a, NULL, NULL)
: JOIN(I, range)(a, JOIN(A, begin)(a), JOIN(A, end)(a));
? JOIN(Z, range)(a, NULL, NULL)
: JOIN(Z, range)(a, JOIN(A, begin)(a), JOIN(A, end)(a));
}

static inline T
Expand All @@ -155,8 +155,8 @@ JOIN(A, equal)(A* self, A* other, int _equal(T*, T*))
{
if(self->size != other->size)
return 0;
I a = JOIN(I, each)(self);
I b = JOIN(I, each)(other);
Z a = JOIN(Z, each)(self);
Z b = JOIN(Z, each)(other);
while(!a.done && !b.done)
{
if(!_equal(a.ref, b.ref))
Expand Down Expand Up @@ -465,6 +465,6 @@ JOIN(A, find)(A* self, T key, int _equal(T*, T*))
#undef T
#undef A
#undef B
#undef I
#undef Z

#undef DEQ_BUCKET_SIZE
34 changes: 17 additions & 17 deletions ctl/lst.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#define A JOIN(lst, T)
#define B JOIN(A, node)
#define I JOIN(A, it)
#define Z JOIN(A, it)

typedef struct B
{
Expand All @@ -30,17 +30,17 @@ typedef struct A
}
A;

typedef struct I
typedef struct Z
{
void (*step)(struct I*);
void (*step)(struct Z*);
T* ref;
B* begin;
B* node;
B* next;
B* end;
int done;
}
I;
Z;

static inline T*
JOIN(A, front)(A* self)
Expand Down Expand Up @@ -68,7 +68,7 @@ JOIN(A, end)(A* self)
}

static inline void
JOIN(I, step)(I* self)
JOIN(Z, step)(Z* self)
{
if(self->next == self->end)
self->done = 1;
Expand All @@ -80,15 +80,15 @@ JOIN(I, step)(I* self)
}
}

static inline I
JOIN(I, range)(A* container, B* begin, B* end)
static inline Z
JOIN(Z, range)(A* container, B* begin, B* end)
{
(void) container;
static I zero;
I self = zero;
static Z zero;
Z self = zero;
if(begin)
{
self.step = JOIN(I, step);
self.step = JOIN(Z, step);
self.begin = begin;
self.end = end;
self.next = begin->next;
Expand All @@ -106,12 +106,12 @@ JOIN(A, empty)(A* self)
return self->size == 0;
}

static inline I
JOIN(I, each)(A* a)
static inline Z
JOIN(Z, each)(A* a)
{
return JOIN(A, empty)(a)
? JOIN(I, range)(a, NULL, NULL)
: JOIN(I, range)(a, JOIN(A, begin)(a), JOIN(A, end)(a));
? JOIN(Z, range)(a, NULL, NULL)
: JOIN(Z, range)(a, JOIN(A, begin)(a), JOIN(A, end)(a));
}

static inline T
Expand All @@ -125,8 +125,8 @@ JOIN(A, equal)(A* self, A* other, int _equal(T*, T*))
{
if(self->size != other->size)
return 0;
I a = JOIN(I, each)(self);
I b = JOIN(I, each)(other);
Z a = JOIN(Z, each)(self);
Z b = JOIN(Z, each)(other);
while(!a.done && !b.done)
{
if(!_equal(a.ref, b.ref))
Expand Down Expand Up @@ -414,4 +414,4 @@ JOIN(A, find)(A* self, T key, int _equal(T*, T*))
#undef T
#undef A
#undef B
#undef I
#undef Z
36 changes: 18 additions & 18 deletions ctl/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#define A JOIN(set, T)
#define B JOIN(A, node)
#define I JOIN(A, it)
#define Z JOIN(A, it)

typedef struct B
{
Expand All @@ -32,16 +32,16 @@ typedef struct A
}
A;

typedef struct I
typedef struct Z
{
void (*step)(struct I*);
void (*step)(struct Z*);
B* end;
B* node;
T* ref;
B* next;
int done;
}
I;
Z;

static inline B*
JOIN(A, begin)(A* self)
Expand Down Expand Up @@ -95,7 +95,7 @@ JOIN(B, next)(B* self)
}

static inline void
JOIN(I, step)(I* self)
JOIN(Z, step)(Z* self)
{
if(self->next == self->end)
self->done = 1;
Expand All @@ -107,15 +107,15 @@ JOIN(I, step)(I* self)
}
}

static inline I
JOIN(I, range)(A* container, B* begin, B* end)
static inline Z
JOIN(Z, range)(A* container, B* begin, B* end)
{
(void) container;
static I zero;
I self = zero;
static Z zero;
Z self = zero;
if(begin)
{
self.step = JOIN(I, step);
self.step = JOIN(Z, step);
self.node = JOIN(B, min)(begin);
self.ref = &self.node->key;
self.next = JOIN(B, next)(self.node);
Expand All @@ -132,12 +132,12 @@ JOIN(A, empty)(A* self)
return self->size == 0;
}

static inline I
JOIN(I, each)(A* a)
static inline Z
JOIN(Z, each)(A* a)
{
return JOIN(A, empty)(a)
? JOIN(I, range)(a, NULL, NULL)
: JOIN(I, range)(a, JOIN(A, begin)(a), JOIN(A, end)(a));
? JOIN(Z, range)(a, NULL, NULL)
: JOIN(Z, range)(a, JOIN(A, begin)(a), JOIN(A, end)(a));
}

static inline T
Expand All @@ -151,8 +151,8 @@ JOIN(A, equal)(A* self, A* other, int _equal(T*, T*))
{
if(self->size != other->size)
return 0;
I a = JOIN(I, each)(self);
I b = JOIN(I, each)(other);
Z a = JOIN(Z, each)(self);
Z b = JOIN(Z, each)(other);
while(!a.done && !b.done)
{
if(!_equal(a.ref, b.ref))
Expand Down Expand Up @@ -689,7 +689,7 @@ JOIN(A, free)(A* self)
static inline A
JOIN(A, copy)(A* self)
{
I it = JOIN(I, each)(self);
Z it = JOIN(Z, each)(self);
A copy = JOIN(A, init)(self->compare);
while(!it.done)
{
Expand Down Expand Up @@ -754,7 +754,7 @@ JOIN(A, symmetric_difference)(A* a, A* b)
#undef T
#undef A
#undef B
#undef I
#undef Z

#ifdef USE_INTERNAL_VERIFY
#undef USE_INTERNAL_VERIFY
Expand Down

0 comments on commit 435a2e6

Please sign in to comment.