Commit 476269ca authored by Yoni Fogel's avatar Yoni Fogel

Addresses #479

Modified instructions inside of log_nooverlap.c
to optimally implement everything using the modified reblack API

git-svn-id: file:///svn/tokudb@2675 c7de825b-a66e-492c-adef-691d508d4ae1
parent ee7e4070
...@@ -24,72 +24,56 @@ struct __toku_range_tree_local { ...@@ -24,72 +24,56 @@ struct __toku_range_tree_local {
#include "rangetree-internal.h" #include "rangetree-internal.h"
/* /*
Changes required in red black tree for max performance: Redblack tree.
Add finger object.. or keep track of it local?
(or keep it local?)
Finger ops: lookup (type) returns:
New Finger.. or equivalent. pointer to data (or NULL if not found)
These overwrite the finger: 'elementpointer' (to be used in finger_delete, finger_predecessor, finger_successor)
FINGER_FIND_LESS_THAN_OR_EQUAL 'insertpointer' (to be used in finger_insert)
FINGER_FIND_EQUAL
FINGER_FIND_LESS_THAN
FINGER_FIND_GREATER_THAN
These use the finger, with boolean (overwrite or leave alone)
FINGER_NEXT
FINGER_PREV
These use the finger
FINGER_INSERT
FINGER_DELETE
Subset of this that would just support FindOverlaps:
These overwrite the finger:
FINGER_FIND_LESS_THAN_OR_EQUAL
FINGER_NEXT
Almost for free:
FINGER_FIND_LESS_THAN_OR_EQUAL
FINGER_FIND_EQUAL
FINGER_FIND_LESS_THAN
FINGER_FIND_GREATER_THAN
FINGER_NEXT
FINGER_PREV
Not for free:
FINGER_INSERT
FINGER_DELETE
Things to add if we want to be nice to redblacklib
FINGER_FIND_GREATER_THAN_OR_EQUAL
Finger usefulness: Finger usefulness:
1- Insert 1- Insert
O(lg N) CMPs We do a find <=. If found and overlaps (found.right >= query.left) return error O(lg N) CMPs We do a lookup(<=) (out elementpointer, out found, out insertpointer)
Next op is either NO_UPDATE, or alternatively, use a copy of the finger. (Return to original finger for INSERT) If found
(0+1) CMPs Do a FINGER_NEXT_NO_UPDATE. If found and overlaps (found.left <= query.right) return error If overlaps (found.right >= query.left) return error
(0) CMPs Do a FINGER_INSERT Do a finger_successor(elementpointer) (out found2)
(0+1) CMPs if (found2 and overlaps (found2.left <= query.right) return error
else
Do a lookup(First) (out found2)
if (found2 and overlaps (found2.left <= query.right) return error
(0) CMPs Do a finger_insert(data, insertpointer)
2- Delete 2- Delete
O(lg N) CMPs We do a find ==. If !found return error. O(lg N) CMPs We do a lookup (==). (out found, out elementpointer)
If !found return error.
(== already checks for left end point) (== already checks for left end point)
Data cmp is free (pointer) Data cmp is free (pointer)
(0+1) CMPs if (found.right != to_insert.data || found.data != to_delete.data), return error. (0+1) CMPs if (found.right != to_insert.data || found.data != to_delete.data), return error.
(0) CMPs Do a FINGER_DELETE (0) CMPs Do a finger_delete(element_pointer)
3- Predecessor: 3- Predecessor:
O(lg N) CMPs Do a find < O(lg N) CMPs Do a lookup(<) (out found, out elementpointer)
If !found return not found If !found return "not found"
(0+1) CMPs If overlaps (found.right >= query) (0+1) CMPs If overlaps (found.right >= query)
(0) CMPs Do a FINGER_PREV. If found return it. (0) CMPs do a finger_predecessor(elementpointer) (out found2)
Return not found. If found2 return found2.
return it. else return "not found"
else return found.
4- Successor: 4- Successor:
O(lg N) CMPs Do a find >. O(lg N) CMPs Do a lookup (>) (out found)
If found, return it. If found, return found.
return not found. return "not found."
5- FindOverlaps 5- FindOverlaps
O(lg N+1) CMPs Do a find <=. If found (test for overlap (if found.right >= query.left) if so, Increaes buffer, add to buffer) O(lg N+1) CMPs Do a lookup (<=) (out found, out elementpointer)
while (Do a FINGER_NEXT_AND_UPDATE) { If found
If not found, DONE (return what we've found) (0+1) CMPs if overlap (if found.right >= query.left)
if not overlap (if found.left > query.right) then DONE (return what we've found) Increaes buffer
Increase buffer add found to buffer
Add to buffer (0) CMPs do a finger_successor(elementpointer) (out found, out elementpointer)
} else
do a lookup (FIRST) (out found, out elementpointer)
O(min(k,K))CMPs while (found && found.left <= query.right
Increaes buffer
add found to buffer
(0) CMPs do a finger_successor(elementpointer) (out found, out elementpointer)
*/ */
static BOOL toku__rt_overlap(toku_range_tree* tree, static BOOL toku__rt_overlap(toku_range_tree* tree,
......
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