Commit fe038531 authored by Vincenzo Liberatore's avatar Vincenzo Liberatore

Addresses 289

Added doxygen file and the generated doxygen documentation for range trees

git-svn-id: file:///svn/tokudb@1801 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0f4e712f
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it." #ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
/* /**
* Range trees \file linear.c
* \brief Range tree implementation
* This is the header file for range trees. */
See rangetree.h for documentation on the following. */
//Currently this is a stub implementation just so we can write and compile tests //Currently this is a stub implementation just so we can write and compile tests
//before actually implementing the range tree. //before actually implementing the range tree.
......
...@@ -4,27 +4,45 @@ ...@@ -4,27 +4,45 @@
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it." #ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
/** /**
* Range trees \file rangetree.h
* \brief Range trees: header and comments
* This is the header file for range trees. */
Range trees are an ordered data structure to hold intervals.
You can learn about range trees at
http://en.wikipedia.org/wiki/Interval_tree
or by consulting the textbooks, e.g.,
Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and
Clifford Stein. Introduction to Algorithms, Second Edition.
MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7
*/
#include <brttypes.h> #include <brttypes.h>
/** Represents a range of data with an extra value. /** \brief Range with value
* Parameters are never modified on failure with the exception of Represents a range of data with an associated value.
* buf and buflen. Parameters are never modified on failure with the exception of
buf and buflen.
*/ */
typedef struct { typedef struct {
void* left; void* left; /**< Left end-point */
void* right; void* right; /**< Right end-point */
void* data; void* data; /**< Data associated with the range */
} toku_range; } toku_range;
/** \brief Internal range representation
Internal representation of a range tree. Some fields depend on the
implementation of range trees, and some others are shared. */
struct __toku_range_tree_internal { struct __toku_range_tree_internal {
//Shared fields: //Shared fields:
int (*end_cmp)(void*,void*); /** A comparison function, as in bsearch(3), to compare the end-points of
a range */
int (*end_cmp)(void*,void*);
/** A comparison function, as in bsearch(3), to compare the data associated
with a range */
int (*data_cmp)(void*,void*); int (*data_cmp)(void*,void*);
/** Whether this tree allows ranges to overlap */
BOOL allow_overlaps; BOOL allow_overlaps;
/** The number of ranges in the range tree */
unsigned numelements; unsigned numelements;
#if defined(TOKU_LINEAR_RANGE_TREE) #if defined(TOKU_LINEAR_RANGE_TREE)
#if defined(TOKU_LOG_RANGE_TREE) #if defined(TOKU_LOG_RANGE_TREE)
...@@ -41,143 +59,143 @@ struct __toku_range_tree_internal { ...@@ -41,143 +59,143 @@ struct __toku_range_tree_internal {
#endif #endif
}; };
/* These lines will remain. */ /** Export the internal representation to a sensible name */
struct __toku_range_tree_internal; /* These lines will remain. */
typedef struct __toku_range_tree_internal toku_range_tree; typedef struct __toku_range_tree_internal toku_range_tree;
/** /**
* Creates a range tree. Creates a range tree.
* Parameters:
* ptree: *ptree will point to the new range tree if successful. \param ptree Points to the new range tree if create is successful
* end_cmp: User provided function to compare end points. \param end_cmp User provided function to compare end points.
* Return value conforms to cmp in qsort(3). Return value conforms to cmp in qsort(3).
* data_cmp: User provided function to compare data values. \param data_cmp User provided function to compare data values.
* Return value conforms to cmp in qsort(3). Return value conforms to cmp in qsort(3).
* allow_overlaps: Whether ranges in this range tree are permitted to \param allow_overlaps Whether ranges in this range tree are permitted
* overlap. to overlap.
* Exit codes:
* 0: Success. \return
* EINVAL: If any pointer argument is NULL. - 0: Success.
* Other exit codes may be forwarded from underlying system calls. - EINVAL: If any pointer argument is NULL.
*/ - Other exit codes may be forwarded from underlying system calls. */
int toku_rt_create(toku_range_tree** ptree, int toku_rt_create(toku_range_tree** ptree, int (*end_cmp)(void*,void*),
int (*end_cmp)(void*,void*), int (*data_cmp)(void*,void*), int (*data_cmp)(void*,void*), BOOL allow_overlaps);
BOOL allow_overlaps);
/** /**
* Destroys and frees a range tree. Destroys and frees a range tree.
* Parameters: \return
* tree: The range tree to free. - 0: Success.
* Exit codes: - EINVAL: If tree is NULL.
* 0: Success. - Other exit codes may be forwarded from underlying system calls.
* EINVAL: If tree is NULL.
* Other exit codes may be forwarded from underlying system calls.
*/ */
int toku_rt_close(toku_range_tree* tree); int toku_rt_close(toku_range_tree* tree /**< The range tree to free */);
/** /**
* Finds ranges in the range tree that overlap a query range. Finds ranges in the range tree that overlap a query range.
* Parameters:
* tree: The range tree to search in. \param tree The range tree to search in.
* k: The maximum number of ranges to return. \param query The range to query. range.data must be NULL.
* The special value '0' is used to request ALL overlapping \param k The maximum number of ranges to return.
* ranges. The special value '0' is used to request ALL overlapping
* query: The range to query. ranges.
* range.data must be NULL. \param buf A pointer to the buffer used to return ranges.
* buf: A pointer to the buffer used to return ranges. The buffer will be increased using realloc(3) if necessary.
* The buffer will be increased using realloc(3) if NOTE: buf must have been dynamically allocated i.e. via
* necessary. malloc(3), calloc(3), etc.
* NOTE: buf must have been dynamically allocated i.e. The buffer will not be modified unless it is too small.
* via malloc(3), calloc(3), etc. \param buflen A pointer to the lenfth of the buffer.
* The buffer will not be modified unless it is too small. If the buffer is increased, then buflen will be updated.
* buflen: A pointer to the lenfth of the buffer. If the buffer \param numfound The number of ranges found. This will necessarily be <= k.
* is increased, then buflen will be updated. If k != 0 && numfound == k, there may be additional
* numfound: The number of ranges found. ranges that overlap the queried range but were skipped
* This will necessarily be <= k. to accomodate the request of k.
* If k != 0 && numfound == k, there may be additional
* ranges that overlap the queried range but were skipped \return
* to accomodate the request of k. - 0: Success.
* Exit codes: - EINVAL: If any pointer argument is NULL. If range.data != NULL.
* 0: Success. If buflen == 0.
* EINVAL: If any pointer argument is NULL. - Other exit codes may be forwarded from underlying system calls.
* If range.data != NULL.
* If buflen == 0. Growth direction: It may be useful in the future to add an extra out
* Other exit codes may be forwarded from underlying system calls. parameter to specify whether more elements exist in the tree that overlap
* It may be useful in the future to add an extra out parameter to specify (in excess of the requested limit of k).
* whether more elements exist in the tree that overlap (in excess of the
* requested limit of k).
*/ */
int toku_rt_find(toku_range_tree* tree, toku_range* query, unsigned k, int toku_rt_find(toku_range_tree* tree,toku_range* query, unsigned k,
toku_range** buf, unsigned* buflen, unsigned* numfound); toku_range** buf, unsigned* buflen, unsigned* numfound);
/** /**
* Inserts a range into the range tree. Inserts a range into the range tree.
* Parameters:
* tree: The range tree to insert into. \param tree The range tree to insert into.
* range: The range to insert. \param range The range to insert.
* Exit codes:
* 0: Success. \return
* EINVAL: If any pointer argument is NULL. - 0: Success.
* EDOM: If the exact range (left, right, and data) already - EINVAL: If any pointer argument is NULL.
* exists in the tree. - EDOM: If the exact range (left, right, and data) already
* If an overlapping range exists in the tree and exists in the tree.
* allow_overlaps == FALSE. If an overlapping range exists in the tree and
* Other exit codes may be forwarded from underlying system calls. allow_overlaps == FALSE.
- Other exit codes may be forwarded from underlying system calls.
*/ */
int toku_rt_insert(toku_range_tree* tree, toku_range* range); int toku_rt_insert(toku_range_tree* tree, toku_range* range);
/** /**
* Deletes a range from the range tree. Deletes a range from the range tree.
* Parameters:
* tree: The range tree to delete from. \param tree The range tree to delete from.
* range: The range to delete. \param range The range to delete.
* Exit codes:
* 0: Success. \return
* EINVAL: If any pointer argument is NULL. - 0: Success.
* EDOM: If the exact range (left, right, and data) did - EINVAL: If any pointer argument is NULL.
* not exist in the tree. - EDOM: If the exact range (left, right, and data) did
* Other exit codes may be forwarded from underlying system calls. not exist in the tree.
- Other exit codes may be forwarded from underlying system calls.
*/ */
int toku_rt_delete(toku_range_tree* tree, toku_range* range); int toku_rt_delete(toku_range_tree* tree, toku_range* range);
/** /**
* Finds the strict predecessor range of a point i.e. the rightmost range Finds the strict predecessor range of a point i.e. the rightmost range
* completely to the left of the query point according to end_cmp. completely to the left of the query point according to end_cmp.
* This operation is only defined if allow_overlaps == FALSE. This operation is only defined if allow_overlaps == FALSE.
* Parameters:
* tree: The range tree to search in. \param tree The range tree to search in.
* point: The point to query. Must be a valid argument to \param point The point to query. Must be a valid argument to
* end_cmp. end_cmp.
* pred: A buffer to return the predecessor. \param pred A buffer to return the predecessor.
* wasfound: Whether a predecessor was found. \param wasfound Whether a predecessor was found.
* If no range is strictly to the left of the query point If no range is strictly to the left of the query
* this will be false. point this will be false.
* Exit codes:
* 0: Success. \return
* EINVAL: If any pointer argument is NULL. - 0: Success.
* If tree allows overlaps. - EINVAL: If any pointer argument is NULL.
* Other exit codes may be forwarded from underlying system calls. If tree allows overlaps.
- Other exit codes may be forwarded from underlying system calls.
*/ */
int toku_rt_predecessor(toku_range_tree* tree, void* point, toku_range* pred, int toku_rt_predecessor(toku_range_tree* tree, void* point, toku_range* pred,
BOOL* wasfound); BOOL* wasfound);
/** /**
* Finds the strict successor range of a point i.e. the leftmost range Finds the strict successor range of a point i.e. the leftmost range
* completely to the right of the query point according to end_cmp. completely to the right of the query point according to end_cmp.
* This operation is only defined if allow_overlaps == FALSE. This operation is only defined if allow_overlaps == FALSE.
* Parameters:
* tree: The range tree to search in. \param tree The range tree to search in.
* point: The point to query. Must be a valid argument to \param point The point to query. Must be a valid argument to
* end_cmp. end_cmp.
* succ: A buffer to return the successor range. \param succ A buffer to return the successor range.
* wasfound: Whether a predecessor was found. \param wasfound Whether a predecessor was found.
* If no range is strictly to the left of the query point If no range is strictly to the left of the query point
* this will be false. this will be false.
* Exit codes:
* 0: Success. \return
* EINVAL: If any pointer argument is NULL. - 0: Success.
* If tree allows overlaps. - EINVAL: If any pointer argument is NULL.
* Other exit codes may be forwarded from underlying system calls. If tree allows overlaps.
- Other exit codes may be forwarded from underlying system calls.
*/ */
int toku_rt_successor(toku_range_tree* tree, void* point, toku_range* succ, int toku_rt_successor(toku_range_tree* tree, void* point, toku_range* succ,
BOOL* wasfound); BOOL* wasfound);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment