summaryrefslogtreecommitdiffstats
path: root/nest
diff options
context:
space:
mode:
authorPavel Machek <pavel@ucw.cz>2000-04-17 13:34:38 +0200
committerPavel Machek <pavel@ucw.cz>2000-04-17 13:34:38 +0200
commit9c400ec9dd0ee74f1f350ead87dcd7366dbab7b1 (patch)
tree8a610e3d07c2004248bd0b247c7a7b2d9af1585d /nest
parente3558ab14ee60c8c9792bc3ed54d9f0c3eaa8ea8 (diff)
downloadbird-9c400ec9dd0ee74f1f350ead87dcd7366dbab7b1.tar
bird-9c400ec9dd0ee74f1f350ead87dcd7366dbab7b1.zip
Int sets moved to core. It is now possible to have variable of type clist.
Diffstat (limited to 'nest')
-rw-r--r--nest/a-set.c43
-rw-r--r--nest/attrs.h4
2 files changed, 47 insertions, 0 deletions
diff --git a/nest/a-set.c b/nest/a-set.c
index deef5df..1d2cebf 100644
--- a/nest/a-set.c
+++ b/nest/a-set.c
@@ -38,3 +38,46 @@ int_set_format(struct adata *set, byte *buf, unsigned int size)
}
*buf = 0;
}
+
+struct adata *
+int_set_add(struct linpool *pool, struct adata *list, u32 val)
+{
+ struct adata *res = lp_alloc(pool, list->length + sizeof(struct adata) + 4);
+ res->length = list->length+4;
+ * (u32 *) res->data = val;
+ memcpy((char *) res->data + 4, list->data, list->length);
+ return res;
+}
+
+int
+int_set_contains(struct adata *list, u32 val)
+{
+ u32 *l = &(list->data);
+ int i;
+ for (i=0; i<list->length/4; i++)
+ if (*l++ == val)
+ return 1;
+ return 0;
+}
+
+struct adata *
+int_set_del(struct linpool *pool, struct adata *list, u32 val)
+{
+ struct adata *res;
+ u32 *l, *k;
+ int i;
+
+ if (!int_set_contains(list, val))
+ return list;
+
+ res = lp_alloc(pool, list->length + sizeof(struct adata) - 4);
+ res->length = list->length-4;
+
+ l = &(list->data);
+ k = &(res->data);
+ for (i=0; i<list->length/4; i++)
+ if (l[i] != val)
+ *k++ = l[i];
+
+ return res;
+}
diff --git a/nest/attrs.h b/nest/attrs.h
index ede152c..630550f 100644
--- a/nest/attrs.h
+++ b/nest/attrs.h
@@ -29,5 +29,9 @@ int as_path_match(struct adata *path, struct f_path_mask *mask);
/* a-set.c */
void int_set_format(struct adata *set, byte *buf, unsigned int size);
+struct adata *int_set_add(struct linpool *pool, struct adata *list, u32 val);
+int int_set_contains(struct adata *list, u32 val);
+struct adata *int_set_del(struct linpool *pool, struct adata *list, u32 val);
+
#endif