libndb: add missing ndbdedup.c
This commit is contained in:
parent
ed41dd5b28
commit
9d60ece816
1 changed files with 30 additions and 0 deletions
30
sys/src/libndb/ndbdedup.c
Normal file
30
sys/src/libndb/ndbdedup.c
Normal file
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue