Merge branch '#34-issue' of lirent/libcdsb into develop

This commit is contained in:
Gregory Lirent 2022-08-18 02:46:17 +03:00 committed by Gogs
commit 63a75549c0
2 changed files with 80 additions and 0 deletions

View File

@ -14,3 +14,16 @@ extern int libcdsb_dict_foreach (vtype_dict* x, void* data, dict_access_ca
extern bool libcdsb_dict_shrink_to_fit(vtype_dict* x) Nonnull__(1);
#endif /* LIBCDSB_EXTRA_DICT_H */
#if defined(LIBCDSB_LIST_H) && !defined(LIBCDSB_EXTRA_DICT_H_EXT)
#define LIBCDSB_EXTRA_DICT_H_EXT
#define dict_copy_keys libcdsb_dict_copy_keys
#define dict_duplicate_keys libcdsb_dict_duplicate_keys
#define dict_init_keys libcdsb_dict_init_keys
extern vtype_list libcdsb_dict_copy_keys (const vtype_dict* s) Nonnull__(1);
extern vtype_list* libcdsb_dict_duplicate_keys(const vtype_dict* s) Nonnull__(1);
extern void libcdsb_dict_init_keys (vtype_list* x, const vtype_dict* s) Nonnull__(1,2);
#endif /* LIBCDSB_EXTRA_DICT_H_EXT */

View File

@ -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;
}
}
}