Skip to content

Commit

Permalink
make array interface more compatible with OOP-style programming
Browse files Browse the repository at this point in the history
  • Loading branch information
generic-github-user committed Nov 2, 2022
1 parent a55b295 commit 506e495
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions c-adts/vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,29 @@ Option None = { NULL, 0, is_none, is_none_, unwrap_uint };
struct Array {
unsigned int size;
unsigned int real_size;
Option (*free) (struct Array* self);
Option (*free) ();
Option (*cast) (struct Array* self, Type Q);
void** data;
Type T;
};
typedef struct Array Array;
Array* new_allocated_array (unsigned int size, Type T);
Array new_array (unsigned int size, Type T);
Option array_free ();
Option array_free_ (Array* self);
Option array_cast (Array* self, Type Q);

Option array_free (Array* self) {
Option array_free_ (Array* self) {
free(self -> data);
self -> size = 0;
init_self(&None);
return None;
}

Option array_cast (Array* self, Type Q);
Option array_free () {
return array_free_((Array*) self_);
}

Array new_array (unsigned int size, Type T) {
return (Array) {
size,
Expand Down

0 comments on commit 506e495

Please sign in to comment.