mutable SplayNode<V> *right;
void destroy(SPLAYFREE *);
void walk(SPLAYWALKEE *, void *callerState);
- bool empty() const {return false;}
+ bool empty() const { return this == NULL; }
SplayNode<V> const * start() const;
SplayNode<V> const * finish() const;
void
SplayNode<V>::walk(SPLAYWALKEE * walkee, void *state)
{
+ if (this == NULL)
+ return;
+
if (left)
left->walk(walkee, state);
SplayNode<V> const *
SplayNode<V>::start() const
{
- if (left)
+ if (this && left)
return left->start();
return this;
SplayNode<V> const *
SplayNode<V>::finish() const
{
- if (right)
+ if (this && right)
return right->finish();
return this;
void
SplayNode<V>::destroy(SPLAYFREE * free_func)
{
+ if (!this)
+ return;
+
if (left)
left->destroy(free_func);
SplayNode<V> *
SplayNode<V>::remove(Value const dataToRemove, SPLAYCMP * compare)
{
+ if (this == NULL)
+ return NULL;
+
SplayNode<V> *result = splay(dataToRemove, compare);
if (splayLastResult == 0) { /* found it */
/* create node to insert */
SplayNode<V> *newNode = new SplayNode<V>(dataToInsert);
+ if (this == NULL) {
+ splayLastResult = -1;
+ newNode->left = newNode->right = NULL;
+ return newNode;
+ }
+
SplayNode<V> *newTop = splay(dataToInsert, compare);
if (splayLastResult < 0) {
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;
+ }
+
Value temp = Value();
SplayNode<V> N(temp);
SplayNode<V> *l;