Add dict keys copy methods
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/* This software is licensed by the MIT License, see LICENSE file */
|
||||
/* Copyright © 2022 Gregory Lirent */
|
||||
|
||||
#include "../../include/extra/list.h"
|
||||
#include "include.h"
|
||||
|
||||
/*#####################################################################################################################*/
|
||||
@@ -167,3 +168,69 @@ int libcdsb_dict_foreach(dict_t* x, void* dt, dict_access_callback callback, boo
|
||||
end_:
|
||||
return r;
|
||||
}
|
||||
|
||||
/*#####################################################################################################################*/
|
||||
|
||||
vtype_list libcdsb_dict_copy_keys(const vtype_dict* s) {
|
||||
vtype_list x;
|
||||
dnode_t *c;
|
||||
size_t i;
|
||||
|
||||
i = s->capacity;
|
||||
|
||||
list_init(&x);
|
||||
|
||||
while (i--) {
|
||||
c = s->nodes[i];
|
||||
|
||||
while (!is_null(c)) {
|
||||
libcdsb_list_update(&x, -1, vnode_peek(&c->key, c->key_type), c->key_type, 1);
|
||||
c = c->prev;
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
vtype_list* libcdsb_dict_duplicate_keys(const vtype_dict* s) {
|
||||
vtype_list* x;
|
||||
dnode_t *c;
|
||||
size_t i;
|
||||
|
||||
x = malloc(sizeof(*x));
|
||||
i = s->capacity;
|
||||
|
||||
list_init(x);
|
||||
|
||||
while (i--) {
|
||||
c = s->nodes[i];
|
||||
|
||||
while (!is_null(c)) {
|
||||
libcdsb_list_update(x, -1, vnode_peek(&c->key, c->key_type), c->key_type, 1);
|
||||
c = c->prev;
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
void libcdsb_dict_init_keys(vtype_list* x, const vtype_dict* s) {
|
||||
dnode_t *c;
|
||||
size_t i;
|
||||
|
||||
x = malloc(sizeof(*x));
|
||||
i = s->capacity;
|
||||
|
||||
list_init(x);
|
||||
|
||||
while (i--) {
|
||||
c = s->nodes[i];
|
||||
|
||||
while (!is_null(c)) {
|
||||
libcdsb_list_update(x, -1, vnode_peek(&c->key, c->key_type), c->key_type, 1);
|
||||
c = c->prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user