shithub: riscv

Download patch

ref: 9d60ece81651aedea9136615f40cbee27e1eda97
parent: ed41dd5b288d95dc11ff87e97bade9859bde6c07
author: cinap_lenrek <[email protected]>
date: Sun Sep 16 11:27:17 EDT 2018

libndb: add missing ndbdedup.c

--- /dev/null
+++ b/sys/src/libndb/ndbdedup.c
@@ -1,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;
+}