2015-11-07 11:20:19 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <core/set.h>
|
|
|
|
|
2015-11-07 11:40:25 -05:00
|
|
|
void set_copy(const struct set *lhs, struct set *rhs)
|
|
|
|
{
|
|
|
|
struct set_iter it_lhs;
|
|
|
|
|
|
|
|
set_for_each(lhs, &it_lhs)
|
|
|
|
set_insert(rhs, it_lhs.it_val);
|
|
|
|
}
|
|
|
|
|
2015-11-07 11:20:19 -05:00
|
|
|
void set_inline_intersect(const struct set *lhs, struct set *rhs)
|
|
|
|
{
|
|
|
|
struct set_iter it_rhs;
|
|
|
|
|
|
|
|
set_for_each(rhs, &it_rhs) {
|
|
|
|
if (!set_has(lhs, it_rhs.it_val))
|
|
|
|
g_hash_table_iter_remove(&it_rhs.it_iter);
|
|
|
|
}
|
|
|
|
}
|
2015-11-09 08:12:28 -05:00
|
|
|
|
|
|
|
void set_read(struct file *file, struct set *set)
|
|
|
|
{
|
|
|
|
unsigned int num, val, i;
|
|
|
|
|
|
|
|
file_readf(file, "%u ", &num);
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
file_readf(file, "%u ", &val);
|
|
|
|
set_insert(set, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_write(struct file *file, struct set *set)
|
|
|
|
{
|
|
|
|
struct set_iter it;
|
|
|
|
|
|
|
|
file_writef(file, "%u ", set_size(set));
|
|
|
|
set_for_each(set, &it)
|
|
|
|
file_writef(file, "%u ", it.it_val);
|
|
|
|
}
|