inc/binRange.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  binElement
struct  binKeeper
struct  binKeeperCookie

Defines

#define BINRANGE_MAXEND_512M   (512*1024*1024)
#define _binOffsetOldToExtended   4681

Functions

int binLevelsExtended ()
int binLevels ()
int binFirstShift ()
int binNextShift ()
int binOffsetExtended (int level)
int binOffset (int level)
int binFromRange (int start, int end)
int binElementCmpStart (const void *va, const void *vb)
binKeeperbinKeeperNew (int minPos, int maxPos)
void binKeeperFree (struct binKeeper **pBk)
void binKeeperAdd (struct binKeeper *bk, int start, int end, void *val)
void binKeeperRemove (struct binKeeper *bk, int start, int end, void *val)
binElementbinKeeperFind (struct binKeeper *bk, int start, int end)
binElementbinKeeperFindSorted (struct binKeeper *bk, int start, int end)
binElementbinKeeperFindAll (struct binKeeper *bk)
boolean binKeeperAnyOverlap (struct binKeeper *bk, int start, int end)
void binKeeperReplaceVal (struct binKeeper *bk, int start, int end, void *oldVal, void *newVal)
binElementbinKeeperFindLowest (struct binKeeper *bk, int start, int end)
binKeeperCookie binKeeperFirst (struct binKeeper *bk)
binElementbinKeeperNext (struct binKeeperCookie *cookie)


Define Documentation

#define _binOffsetOldToExtended   4681

Definition at line 17 of file binRange.h.

Referenced by binFromRangeExtended(), and binOffsetExtended().

#define BINRANGE_MAXEND_512M   (512*1024*1024)

Definition at line 16 of file binRange.h.

Referenced by binFromRange().


Function Documentation

int binElementCmpStart ( const void *  va,
const void *  vb 
)

Definition at line 189 of file binRange.c.

References binElement::start.

Referenced by binKeeperFindSorted().

00191 {
00192 const struct binElement *a = *((struct binElement **)va);
00193 const struct binElement *b = *((struct binElement **)vb);
00194 return a->start - b->start;
00195 }

Here is the caller graph for this function:

int binFirstShift (  ) 

Definition at line 40 of file binRange.c.

References _binFirstShift.

00042 {
00043 return _binFirstShift;
00044 }

int binFromRange ( int  start,
int  end 
)

Definition at line 111 of file binRange.c.

References binFromRangeExtended(), binFromRangeStandard(), and BINRANGE_MAXEND_512M.

00113 {
00114 if (end <= BINRANGE_MAXEND_512M)
00115     return binFromRangeStandard(start, end);
00116 else
00117     return binFromRangeExtended(start, end);
00118 }

Here is the call graph for this function:

void binKeeperAdd ( struct binKeeper bk,
int  start,
int  end,
void *  val 
)

Definition at line 172 of file binRange.c.

References AllocVar, binFromRangeBinKeeperExtended(), binKeeper::binLists, binElement::end, errAbort(), binKeeper::maxPos, binKeeper::minPos, slAddHead, binElement::start, and binElement::val.

Referenced by mergeAdd(), and readPslToBinKeeper().

00174 {
00175 int bin;
00176 struct binElement *el;
00177 if (start < bk->minPos || end > bk->maxPos || start > end)
00178     errAbort("(%d %d) out of range (%d %d) in binKeeperAdd", 
00179         start, end, bk->minPos, bk->maxPos);
00180 bin = binFromRangeBinKeeperExtended(start, end);
00181 assert(bin < bk->binCount);
00182 AllocVar(el);
00183 el->start = start;
00184 el->end = end;
00185 el->val = val;
00186 slAddHead(&bk->binLists[bin], el);
00187 }

Here is the call graph for this function:

Here is the caller graph for this function:

boolean binKeeperAnyOverlap ( struct binKeeper bk,
int  start,
int  end 
)

Definition at line 230 of file binRange.c.

References _binFirstShift, ArraySize, binKeeper::binLists, binOffsetsExtended, binElement::end, FALSE, binKeeper::maxPos, binKeeper::minPos, binElement::next, rangeIntersection(), binElement::start, and TRUE.

00232 {
00233 struct binElement *el;
00234 int startBin, endBin;
00235 int i,j;
00236 
00237 if (start < bk->minPos) start = bk->minPos;
00238 if (end > bk->maxPos) end = bk->maxPos;
00239 if (start >= end) return FALSE;
00240 startBin = (start>>_binFirstShift);
00241 endBin = ((end-1)>>_binFirstShift);
00242 for (i=0; i<ArraySize(binOffsetsExtended); ++i)
00243     {
00244     int offset = binOffsetsExtended[i];
00245     for (j=startBin+offset; j<=endBin+offset; ++j)
00246         {
00247         for (el=bk->binLists[j]; el != NULL; el = el->next)
00248             {
00249             if (rangeIntersection(el->start, el->end, start, end) > 0)
00250                 {
00251                 return TRUE;
00252                 }
00253             }
00254         }
00255     startBin >>= _binNextShift;
00256     endBin >>= _binNextShift;
00257     }
00258 return FALSE;
00259 }

Here is the call graph for this function:

struct binElement* binKeeperFind ( struct binKeeper bk,
int  start,
int  end 
) [read]

Definition at line 197 of file binRange.c.

References _binFirstShift, ArraySize, binKeeper::binLists, binOffsetsExtended, CloneVar, binKeeper::maxPos, binKeeper::minPos, binElement::next, rangeIntersection(), and slAddHead.

Referenced by binKeeperFindSorted(), and mergeAdd().

00200 {
00201 struct binElement *list = NULL, *newEl, *el;
00202 int startBin, endBin;
00203 int i,j;
00204 
00205 if (start < bk->minPos) start = bk->minPos;
00206 if (end > bk->maxPos) end = bk->maxPos;
00207 if (start >= end) return NULL;
00208 startBin = (start>>_binFirstShift);
00209 endBin = ((end-1)>>_binFirstShift);
00210 for (i=0; i<ArraySize(binOffsetsExtended); ++i)
00211     {
00212     int offset = binOffsetsExtended[i];
00213     for (j=startBin+offset; j<=endBin+offset; ++j)
00214         {
00215         for (el=bk->binLists[j]; el != NULL; el = el->next)
00216             {
00217             if (rangeIntersection(el->start, el->end, start, end) > 0)
00218                 {
00219                 newEl = CloneVar(el);
00220                 slAddHead(&list, newEl);
00221                 }
00222             }
00223         }
00224     startBin >>= _binNextShift;
00225     endBin >>= _binNextShift;
00226     }
00227 return list;
00228 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct binElement* binKeeperFindAll ( struct binKeeper bk  )  [read]

Definition at line 304 of file binRange.c.

References binKeeperFindSorted(), binKeeper::maxPos, and binKeeper::minPos.

Referenced by pcrClumps().

00306 {
00307 return binKeeperFindSorted(bk, bk->minPos, bk->maxPos);
00308 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct binElement* binKeeperFindLowest ( struct binKeeper bk,
int  start,
int  end 
) [read]

Definition at line 310 of file binRange.c.

References _binFirstShift, ArraySize, binKeeper::binLists, binOffsetsExtended, binElement::end, FALSE, binElement::next, rangeIntersection(), binElement::start, and TRUE.

00312 {
00313 struct binElement *first = NULL, *el;
00314 int startBin = (start>>_binFirstShift), endBin = ((end-1)>>_binFirstShift);
00315 int i,j;
00316 
00317 /* Search the possible range of bins at each level, looking for lowest.  Once
00318  * an overlaping range is found at a level, continue with next level, however
00319  * must search an entire bin as they are not ordered. */
00320 for (i=0; i<ArraySize(binOffsetsExtended); ++i)
00321     {
00322     int offset = binOffsetsExtended[i];
00323     boolean foundOne = FALSE;
00324     for (j=startBin+offset; (j<=endBin+offset) && (!foundOne); ++j)
00325         {
00326         for (el=bk->binLists[j]; el != NULL; el = el->next)
00327             {
00328             if ((rangeIntersection(el->start, el->end, start, end) > 0)
00329                 && ((first == NULL) || (el->start < first->start)
00330                     || ((el->start == first->start)
00331                         && (el->end < first->end))))
00332                 {
00333                 first = el;
00334                 foundOne = TRUE;
00335                 }
00336             }
00337         }
00338     startBin >>= _binNextShift;
00339     endBin >>= _binNextShift;
00340     }
00341 return first;
00342 }

Here is the call graph for this function:

struct binElement* binKeeperFindSorted ( struct binKeeper bk,
int  start,
int  end 
) [read]

Definition at line 296 of file binRange.c.

References binElementCmpStart(), binKeeperFind(), and slSort().

Referenced by binKeeperFindAll().

00298 {
00299 struct binElement *list = binKeeperFind(bk, start, end);
00300 slSort(&list, binElementCmpStart);
00301 return list;
00302 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct binKeeperCookie binKeeperFirst ( struct binKeeper bk  )  [read]

Definition at line 366 of file binRange.c.

References binKeeper::binLists, and binKeeperCookie::bk.

00370 {
00371 struct binKeeperCookie cookie;
00372 cookie.bk = bk;
00373 cookie.blIdx = 0;
00374 cookie.nextBel = bk->binLists[0];
00375 return cookie;
00376 }

void binKeeperFree ( struct binKeeper **  pBk  ) 

Definition at line 158 of file binRange.c.

References binKeeper::binCount, binKeeper::binLists, freeMem(), freez(), and slFreeList().

Referenced by pcrClumps().

00160 {
00161 struct binKeeper *bk = *pBk;
00162 if (bk != NULL)
00163     {
00164     int i;
00165     for (i=0; i<bk->binCount; ++i)
00166         slFreeList(&bk->binLists[i]);
00167     freeMem(bk->binLists);
00168     freez(pBk);
00169     }
00170 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct binKeeper* binKeeperNew ( int  minPos,
int  maxPos 
) [read]

Definition at line 141 of file binRange.c.

References AllocArray, AllocVar, binKeeper::binCount, binFromRangeBinKeeperExtended(), binKeeper::binLists, errAbort(), binKeeper::maxPos, and binKeeper::minPos.

Referenced by pcrClumps(), and readPslToBinKeeper().

00143 {
00144 int binCount;
00145 struct binKeeper *bk;
00146 if (minPos < 0 || maxPos < 0 || minPos > maxPos)
00147     errAbort("bad range %d,%d in binKeeperNew", minPos, maxPos);
00148 
00149 binCount = binFromRangeBinKeeperExtended(maxPos-1, maxPos) + 1;
00150 AllocVar(bk);
00151 bk->minPos = minPos;
00152 bk->maxPos = maxPos;
00153 bk->binCount = binCount;
00154 AllocArray(bk->binLists, binCount);
00155 return bk;
00156 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct binElement* binKeeperNext ( struct binKeeperCookie cookie  )  [read]

Definition at line 378 of file binRange.c.

References binKeeper::binCount, binKeeper::binLists, binKeeperCookie::bk, binKeeperCookie::blIdx, binElement::next, and binKeeperCookie::nextBel.

00380 {
00381 /* if we don't have a next, move down bin list until we find one */
00382 while ((cookie->nextBel == NULL)
00383        && (++cookie->blIdx < cookie->bk->binCount))
00384     cookie->nextBel = cookie->bk->binLists[cookie->blIdx];
00385 if (cookie->blIdx >= cookie->bk->binCount)
00386     return NULL;  /* no more */
00387 else
00388     {
00389     struct binElement* bel = cookie->nextBel;
00390     cookie->nextBel = cookie->nextBel->next;
00391     return bel;
00392     }
00393 }

void binKeeperRemove ( struct binKeeper bk,
int  start,
int  end,
void *  val 
)

Definition at line 345 of file binRange.c.

References binFromRangeBinKeeperExtended(), binKeeper::binLists, freeMem(), binElement::next, and slAddHead.

Referenced by mergeAdd().

00347 {
00348 int bin = binFromRangeBinKeeperExtended(start, end);
00349 struct binElement **pList = &bk->binLists[bin], *newList = NULL, *el, *next;
00350 for (el = *pList; el != NULL; el = next)
00351     {
00352     next = el->next;
00353     if (el->val == val && el->start == start && el->end == end)
00354         {
00355         freeMem(el);
00356         }
00357     else
00358         {
00359         slAddHead(&newList, el);
00360         }
00361     }
00362 slReverse(&newList);
00363 *pList = newList;
00364 }

Here is the call graph for this function:

Here is the caller graph for this function:

void binKeeperReplaceVal ( struct binKeeper bk,
int  start,
int  end,
void *  oldVal,
void *  newVal 
)

Definition at line 261 of file binRange.c.

References _binFirstShift, ArraySize, binKeeper::binLists, binOffsetsExtended, binElement::end, binKeeper::maxPos, binKeeper::minPos, binElement::next, rangeIntersection(), binElement::start, and binElement::val.

00264 {
00265 struct binElement *el;
00266 int startBin, endBin;
00267 int i,j;
00268 
00269 if (start < bk->minPos) start = bk->minPos;
00270 if (end > bk->maxPos) end = bk->maxPos;
00271 if (start >= end) return;
00272 startBin = (start>>_binFirstShift);
00273 endBin = ((end-1)>>_binFirstShift);
00274 for (i=0; i<ArraySize(binOffsetsExtended); ++i)
00275     {
00276     int offset = binOffsetsExtended[i];
00277     for (j=startBin+offset; j<=endBin+offset; ++j)
00278         {
00279         for (el=bk->binLists[j]; el != NULL; el = el->next)
00280             {
00281             if (rangeIntersection(el->start, el->end, start, end) > 0)
00282                 {
00283                 if (el->val == oldVal)
00284                     {
00285                     el->val = newVal;
00286                     }
00287                 }
00288             }
00289         }
00290     startBin >>= _binNextShift;
00291     endBin >>= _binNextShift;
00292     }
00293 }

Here is the call graph for this function:

int binLevels (  ) 

Definition at line 34 of file binRange.c.

References ArraySize, and binOffsets.

00036 {
00037 return ArraySize(binOffsets);
00038 }

int binLevelsExtended (  ) 

Definition at line 28 of file binRange.c.

References ArraySize, and binOffsetsExtended.

00030 {
00031 return ArraySize(binOffsetsExtended);
00032 }

int binNextShift (  ) 

Definition at line 46 of file binRange.c.

References _binNextShift.

00048 {
00049 return _binNextShift;
00050 }

int binOffset ( int  level  ) 

Definition at line 59 of file binRange.c.

References ArraySize, and binOffsets.

00061 {
00062 assert(level >= 0 && level < ArraySize(binOffsets));
00063 return binOffsets[level];
00064 }

int binOffsetExtended ( int  level  ) 

Definition at line 52 of file binRange.c.

References _binOffsetOldToExtended, ArraySize, and binOffsetsExtended.

00054 {
00055 assert(level >= 0 && level < ArraySize(binOffsetsExtended));
00056 return binOffsetsExtended[level] + _binOffsetOldToExtended;
00057 }


Generated on Tue Dec 25 18:42:16 2007 for blat by  doxygen 1.5.2