/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 2000-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* Phong Vo <[email protected]> *18* *19***********************************************************************/20#pragma prototyped2122#include "ptlib.h"2324/*25* return the table intersection of a and b26*/2728Pt_t*29ptintersect(Pt_t* a, Pt_t* b)30{31Pt_t* t;32Ptprefix_t* ap;33Ptprefix_t* bp;3435if (!(t = ptopen(a->disc)))36return 0;37ap = (Ptprefix_t*)dtfirst(a->dict);38bp = (Ptprefix_t*)dtfirst(b->dict);39while (ap && bp)40{41if (ap->max < bp->min)42ap = (Ptprefix_t*)dtnext(a->dict, ap);43else if (ap->min > bp->max)44bp = (Ptprefix_t*)dtnext(b->dict, bp);45else46{47if (!ptinsert(t, (ap->min > bp->min) ? ap->min : bp->min, (ap->max < bp->max) ? ap->max : bp->max))48break;49if (ap->max < bp->max)50ap = (Ptprefix_t*)dtnext(a->dict, ap);51else if (ap->max > bp->max)52bp = (Ptprefix_t*)dtnext(b->dict, bp);53else54{55ap = (Ptprefix_t*)dtnext(a->dict, ap);56bp = (Ptprefix_t*)dtnext(b->dict, bp);57}58}59}60return t;61}626364