summaryrefslogtreecommitdiff
path: root/sys/src/libndb
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2018-09-16 15:27:17 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2018-09-16 15:27:17 +0200
commit9d60ece81651aedea9136615f40cbee27e1eda97 (patch)
tree5abea22a3cc381d84b1d0a32fe3d712e9ccc4e67 /sys/src/libndb
parented41dd5b288d95dc11ff87e97bade9859bde6c07 (diff)
libndb: add missing ndbdedup.c
Diffstat (limited to 'sys/src/libndb')
-rw-r--r--sys/src/libndb/ndbdedup.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/sys/src/libndb/ndbdedup.c b/sys/src/libndb/ndbdedup.c
new file mode 100644
index 000000000..7c0c4284a
--- /dev/null
+++ b/sys/src/libndb/ndbdedup.c
@@ -0,0 +1,30 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+#include <ndb.h>
+
+/*
+ * remove duplicates
+ */
+Ndbtuple*
+ndbdedup(Ndbtuple *t)
+{
+ Ndbtuple *nt, *last, *tt;
+
+ for(nt = t; nt != nil; nt = nt->entry){
+ last = nt;
+ for(tt = nt->entry; tt != nil; tt = last->entry){
+ if(strcmp(nt->attr, tt->attr) != 0
+ || strcmp(nt->val, tt->val) != 0){
+ last = tt;
+ continue;
+ }
+ if(last->line == tt)
+ last->line = tt->line;
+ last->entry = tt->entry;
+ tt->entry = nil;
+ ndbfree(tt);
+ }
+ }
+ return t;
+}