Skip to content

Commit

Permalink
add test for node_loader class
Browse files Browse the repository at this point in the history
add api for getting all keys and values in adt_set and adt_map
  • Loading branch information
rxbryan committed Feb 20, 2023
1 parent 145e5c1 commit e44e0ab
Show file tree
Hide file tree
Showing 11 changed files with 1,620 additions and 370 deletions.
4 changes: 4 additions & 0 deletions source/adt/include/adt/adt_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ ADT_API int map_insert_array(map m, map_key keys[], map_value values[], size_t s

ADT_API vector map_get(map m, map_key key);

ADT_API vector map_get_keys(map m);

ADT_API vector map_get_values(map m);

ADT_API int map_contains(map m, map_key key);

ADT_API int map_contains_any(map dest, map src);
Expand Down
5 changes: 5 additions & 0 deletions source/adt/include/adt/adt_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <adt/adt_comparable.h>
#include <adt/adt_hash.h>
#include <adt/adt_vector.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -62,6 +63,10 @@ ADT_API int set_insert_array(set s, set_key keys[], set_value values[], size_t s

ADT_API set_value set_get(set s, set_key key);

ADT_API vector set_get_keys(set s);

ADT_API vector set_get_values(set s);

ADT_API int set_contains(set s, set_key key);

ADT_API int set_contains_any(set dest, set src);
Expand Down
42 changes: 42 additions & 0 deletions source/adt/source/adt_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,48 @@ vector map_get(map m, map_key key)
return NULL;
}

vector map_get_keys(map m)
{
vector v = vector_create(sizeof(void *));
bucket b;
pair p;
for (size_t iterator = 0; iterator < m->capacity; iterator++)
{
b = &m->buckets[iterator];

if (b->pairs != NULL && b->count > 0)
{
for (size_t index = 0; index < b->count; index++)
{
p = &b->pairs[index];
vector_push_back(v, &p->key);
}
}
}
return v;
}

vector map_get_values(map m)
{
vector v = vector_create(sizeof(void *));
bucket b;
pair p;
for (size_t iterator = 0; iterator < m->capacity; iterator++)
{
b = &m->buckets[iterator];

if (b->pairs != NULL && b->count > 0)
{
for (size_t index = 0; index < b->count; index++)
{
p = &b->pairs[index];
vector_push_back(v, &p->value);
}
}
}
return v;
}

int map_contains(map m, map_key key)
{
if (m != NULL && key != NULL)
Expand Down
42 changes: 42 additions & 0 deletions source/adt/source/adt_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,48 @@ set_value set_get(set s, set_key key)
return NULL;
}

vector set_get_keys(set s)
{
vector v = vector_create(sizeof(void *));
bucket b;
pair p;
for (size_t iterator = 0; iterator < s->capacity; iterator++)
{
b = &s->buckets[iterator];

if (b->pairs != NULL && b->count > 0)
{
for (size_t index = 0; index < b->count; index++)
{
p = &b->pairs[index];
vector_push_back(v, &p->key);
}
}
}
return v;
}

vector set_get_values(set s)
{
vector v = vector_create(sizeof(void *));
bucket b;
pair p;
for (size_t iterator = 0; iterator < s->capacity; iterator++)
{
b = &s->buckets[iterator];

if (b->pairs != NULL && b->count > 0)
{
for (size_t index = 0; index < b->count; index++)
{
p = &b->pairs[index];
vector_push_back(v, &p->value);
}
}
}
return v;
}

int set_contains(set s, set_key key)
{
if (s != NULL && key != NULL)
Expand Down
Loading

0 comments on commit e44e0ab

Please sign in to comment.