src/lib/common.c 1.149
1.149 2010/05/29 20:23:41 larrym
add slNameIntersection
Index: src/lib/common.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/common.c,v
retrieving revision 1.148
retrieving revision 1.149
diff -b -B -U 4 -r1.148 -r1.149
--- src/lib/common.c 20 Apr 2010 15:56:50 -0000 1.148
+++ src/lib/common.c 29 May 2010 20:23:41 -0000 1.149
@@ -7,8 +7,9 @@
#include "common.h"
#include "errabort.h"
#include "portable.h"
#include "linefile.h"
+#include "hash.h"
static char const rcsid[] = "$Id$";
void *cloneMem(void *pt, size_t size)
@@ -798,8 +799,23 @@
slReverse(&lines);
return lines;
}
+struct slName *slNameIntersection(struct slName *a, struct slName *b)
+/* return intersection of two slName lists. */
+{
+struct hash *hashA = newHash(0);
+struct slName *el, *retval = NULL;
+
+for (el = a; el != NULL; el = el->next)
+ hashAddInt(hashA, el->name, 1);
+for (el = b; el != NULL; el = el->next)
+ if(hashLookup(hashA, el->name) != NULL)
+ slNameAddHead(&retval, el->name);
+hashFree(&hashA);
+return retval;
+}
+
struct slRef *refOnList(struct slRef *refList, void *val)
/* Return ref if val is already on list, otherwise NULL. */
{
struct slRef *ref;