Back to index

python3.2  3.2.2
Classes | Defines | Typedefs | Functions
rotatingtree.h File Reference
#include <stdlib.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rotating_node_s

Defines

#define EMPTY_ROTATING_TREE   ((rotating_node_t *)NULL)

Typedefs

typedef struct rotating_node_s
typedef int(* rotating_tree_enum_fn )(rotating_node_t *node, void *arg)

Functions

void RotatingTree_Add (rotating_node_t **root, rotating_node_t *node)
rotating_node_t * RotatingTree_Get (rotating_node_t **root, void *key)
int RotatingTree_Enum (rotating_node_t *root, rotating_tree_enum_fn enumfn, void *arg)

Class Documentation

struct rotating_node_s

Definition at line 18 of file rotatingtree.h.

Class Members
void * key
rotating_node_t * left
rotating_node_t * right

Define Documentation

#define EMPTY_ROTATING_TREE   ((rotating_node_t *)NULL)

Definition at line 13 of file rotatingtree.h.


Typedef Documentation

typedef struct rotating_node_s

Definition at line 15 of file rotatingtree.h.

typedef int(* rotating_tree_enum_fn)(rotating_node_t *node, void *arg)

Definition at line 16 of file rotatingtree.h.


Function Documentation

void RotatingTree_Add ( rotating_node_t **  root,
rotating_node_t *  node 
)

Definition at line 31 of file rotatingtree.c.

{
    while (*root != NULL) {
        if (KEY_LOWER_THAN(node->key, (*root)->key))
            root = &((*root)->left);
        else
            root = &((*root)->right);
    }
    node->left = NULL;
    node->right = NULL;
    *root = node;
}

Here is the caller graph for this function:

int RotatingTree_Enum ( rotating_node_t *  root,
rotating_tree_enum_fn  enumfn,
void arg 
)

Definition at line 107 of file rotatingtree.c.

{
    int result;
    rotating_node_t *node;
    while (root != NULL) {
        result = RotatingTree_Enum(root->left, enumfn, arg);
        if (result != 0) return result;
        node = root->right;
        result = enumfn(root, arg);
        if (result != 0) return result;
        root = node;
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

rotating_node_t* RotatingTree_Get ( rotating_node_t **  root,
void key 
)

Definition at line 48 of file rotatingtree.c.

{
    if (randombits(3) != 4) {
        /* Fast path, no rebalancing */
        rotating_node_t *node = *root;
        while (node != NULL) {
            if (node->key == key)
                return node;
            if (KEY_LOWER_THAN(key, node->key))
                node = node->left;
            else
                node = node->right;
        }
        return NULL;
    }
    else {
        rotating_node_t **pnode = root;
        rotating_node_t *node = *pnode;
        rotating_node_t *next;
        int rotate;
        if (node == NULL)
            return NULL;
        while (1) {
            if (node->key == key)
                return node;
            rotate = !randombits(1);
            if (KEY_LOWER_THAN(key, node->key)) {
                next = node->left;
                if (next == NULL)
                    return NULL;
                if (rotate) {
                    node->left = next->right;
                    next->right = node;
                    *pnode = next;
                }
                else
                    pnode = &(node->left);
            }
            else {
                next = node->right;
                if (next == NULL)
                    return NULL;
                if (rotate) {
                    node->right = next->left;
                    next->left = node;
                    *pnode = next;
                }
                else
                    pnode = &(node->right);
            }
            node = next;
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function: