SplayNode<V> const *
SplayNode<V>::start() const
{
- if (this && left)
+ if (left)
return left->start();
return this;
SplayNode<V> const *
SplayNode<V>::finish() const
{
- if (this && right)
+ if (right)
return right->finish();
return this;
SplayNode<V> *
SplayNode<V>::remove(Value const dataToRemove, SPLAYCMP * compare)
{
- if (this == NULL)
- return NULL;
+ assert(this != NULL);
SplayNode<V> *result = splay(dataToRemove, compare);
/* create node to insert */
SplayNode<V> *newNode = new SplayNode<V>(dataToInsert);
- if (this == NULL) {
- splayLastResult = -1;
- newNode->left = newNode->right = NULL;
- return newNode;
- }
+ assert(this != NULL);
SplayNode<V> *newTop = splay(dataToInsert, compare);
SplayNode<V> *
SplayNode<V>::splay(FindValue const &dataToFind, int( * compare)(FindValue const &a, Value const &b)) const
{
- if (this == NULL) {
- /* can't have compared successfully :} */
- splayLastResult = -1;
- return NULL;
- }
+ assert(this != NULL);
Value temp = Value();
SplayNode<V> N(temp);
typename Splay<V>::Value const *
Splay<V>::find (FindValue const &value, int( * compare)(FindValue const &a, Value const &b)) const
{
+ if (head == NULL)
+ return NULL;
+
head = head->splay(value, compare);
if (splayLastResult != 0)