inc/rangeTree.h

Go to the documentation of this file.
00001 /* rangeTree - This module is a way of keeping track of
00002  * non-overlapping ranges (half-open intervals). It is
00003  * based on the self-balancing rbTree code.  Use it in
00004  * place of a bitmap when the total number of ranges
00005  * is significantly smaller than the number of bits would
00006  * be. */
00007 
00008 #ifndef RANGETREE_H
00009 #define RANGETREE_H
00010 
00011 #ifndef RBTREE_H
00012 #include "rbTree.h"
00013 #endif
00014 
00015 struct range
00016 /* An interval in a list of intervals. */
00017     {
00018     struct range *next;
00019     int start,end;      /* Zero based half open interval. */
00020     void *val;          /* Some value associated with range. */
00021     };
00022 
00023 struct rbTree *rangeTreeNew();
00024 /* Create a new, empty, rangeTree.  Free with rbFreeTree. */
00025 
00026 #define rangeTreeFree(a) rbTreeFree(a)
00027 /* Free up range tree.  */
00028 
00029 int rangeCmp(void *va, void *vb);
00030 /* Return -1 if a before b,  0 if a and b overlap,
00031  * and 1 if a after b. */
00032 
00033 struct range *rangeTreeAdd(struct rbTree *tree, int start, int end);
00034 /* Add range to tree, merging with existing ranges if need be. */
00035 
00036 boolean rangeTreeOverlaps(struct rbTree *tree, int start, int end);
00037 /* Return TRUE if start-end overlaps anything in tree */
00038 
00039 int rangeTreeOverlapSize(struct rbTree *tree, int start, int end);
00040 /* Return the total size of intersection between interval
00041  * from start to end, and items in range tree. Sadly not
00042  * thread-safe. */
00043 
00044 struct range *rangeTreeFindEnclosing(struct rbTree *tree, int start, int end);
00045 /* Find item in range tree that encloses range between start and end 
00046  * if there is any such item. */
00047 
00048 struct range *rangeTreeAllOverlapping(struct rbTree *tree, int start, int end);
00049 /* Return list of all items in range tree that overlap interval start-end.
00050  * Do not free this list, it is owned by tree.  However it is only good until
00051  * next call to rangeTreeFindInRange or rangTreeList. Not thread safe. */
00052 
00053 struct range *rangeTreeList(struct rbTree *tree);
00054 /* Return list of all ranges in tree in order.  Not thread safe. 
00055  * No need to free this when done, memory is local to tree. */
00056 
00057 struct rbTree *rangeTreeNewDetailed(struct lm *lm, struct rbTreeNode *stack[128]);
00058 /* Allocate rangeTree on an existing local memory & stack.  This is for cases
00059  * where you want a lot of trees, and don't want the overhead for each one. 
00060  * Note, to clean these up, just do freez(&rbTree) rather than rbFreeTree(&rbTree). */
00061 
00062 #endif /* RANGETREE_H */
00063 

Generated on Tue Dec 25 18:39:29 2007 for blat by  doxygen 1.5.2