summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J Stevens <paul@nfg.nl>2010-08-05 11:55:51 +0200
committerPaul J Stevens <paul@nfg.nl>2010-08-05 11:55:51 +0200
commit7d54aabed456dc8ba6fa9d1ae891757ecb5b212d (patch)
tree66581f2ca20f4d68bfce4cd1f86c240e7412d438
parentd8cf4e12ca5ecc6e4c672100d12475c66e3dfd03 (diff)
stub sorted set adt
-rw-r--r--src/dm_sset.c95
-rw-r--r--src/dm_sset.h49
2 files changed, 144 insertions, 0 deletions
diff --git a/src/dm_sset.c b/src/dm_sset.c
new file mode 100644
index 00000000..7fd256aa
--- /dev/null
+++ b/src/dm_sset.c
@@ -0,0 +1,95 @@
+/*
+
+ Copyright (c) 2008 NFG Net Facilities Group BV support@nfg.nl
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later
+ version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "dbmail.h"
+#include "dm_sset.h"
+
+#define THIS_MODULE "SSET"
+
+/*
+ * implements the Sorted Set interface
+ */
+
+#define T SSet_T
+
+struct T {
+ GTree *items;
+ int (*cmp)(const void *, const void *);
+ int (*hash)(const void *);
+};
+
+
+T Sset_new(int (*cmp)(const void *a, const void *b), int (*hash)(const void *c))
+{
+
+ T S;
+ S = g_malloc0(sizeof(*S));
+ S->items = g_tree_new_full((GCompareDataFunc)(cmp), NULL, (GDestroyNotify)g_free, (GDestroyNotify)g_free);
+ S->cmp = cmp;
+ S->hash = hash;
+}
+
+int Sset_has(T S, const void *a)
+{
+ return g_tree_lookup(S->items, a)?1:0;
+}
+
+
+void Sset_add(T S, const void *a)
+{
+
+}
+
+int Sset_len(T S)
+{
+
+}
+
+void * Sset_del(T S, const void * a)
+{
+
+}
+
+void Sset_free(T *S)
+{
+
+}
+
+T Sset_or(T a, T b) // a + b
+{
+
+}
+
+T Sset_and(T a, T b) // a * b
+{
+
+}
+
+T Sset_not(T a, T b) // a - b
+{
+
+}
+
+T Sset_xor(T a, T b); // a / b
+{
+
+}
+
+
diff --git a/src/dm_sset.h b/src/dm_sset.h
new file mode 100644
index 00000000..d3b50cfe
--- /dev/null
+++ b/src/dm_sset.h
@@ -0,0 +1,49 @@
+/*
+
+ Copyright (c) 2010 NFG Net Facilities Group BV support@nfg.nl
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later
+ version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ * ADT interface for Sorted Set
+ *
+ * optimized for insertion and removal of items to and from the
+ * Universe
+ */
+
+#ifndef SSET_H
+#define SSET_H
+
+#define T Sset_T
+
+typedef struct T *T;
+
+extern T Sset_new(int (*cmp)(const void *, const void *), int (*hash)(const void *));
+extern int Sset_has(T, const void *);
+extern void Sset_add(T, const void *);
+extern int Sset_len(T);
+extern void * Sset_del(T, const void *);
+extern void Sset_free(T *);
+
+extern T Sset_or(T, T); // a + b
+extern T Sset_and(T, T); // a * b
+extern T Sset_not(T, T); // a - b
+extern T Sset_xor(T, T); // a / b
+
+#undef T
+
+#endif