Commit 3b2df1d0 authored by Michael Smith's avatar Michael Smith
Browse files

Brendan was getting pissed off about inconsistent indentation styles.

Convert all tabs to 4 spaces. All code must now use 4 space indents.

svn path=/trunk/avl/; revision=4492
parent bd9c2383
...@@ -96,7 +96,7 @@ void admin_handle_request(client_t *client, char *uri) ...@@ -96,7 +96,7 @@ void admin_handle_request(client_t *client, char *uri)
/* This is a mount request, handle it as such */ /* This is a mount request, handle it as such */
if(!connection_check_admin_pass(client->parser)) { if(!connection_check_admin_pass(client->parser)) {
if(!connection_check_source_pass(client->parser, mount)) { if(!connection_check_source_pass(client->parser, mount)) {
INFO1("Bad or missing password on mount modification admin " INFO1("Bad or missing password on mount modification admin "
"request (command: %s)", command_string); "request (command: %s)", command_string);
client_send_401(client); client_send_401(client);
return; return;
...@@ -122,7 +122,7 @@ void admin_handle_request(client_t *client, char *uri) ...@@ -122,7 +122,7 @@ void admin_handle_request(client_t *client, char *uri)
else { else {
if(!connection_check_admin_pass(client->parser)) { if(!connection_check_admin_pass(client->parser)) {
INFO1("Bad or missing password on admin command " INFO1("Bad or missing password on admin command "
"request (command: %s)", command_string); "request (command: %s)", command_string);
client_send_401(client); client_send_401(client);
return; return;
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* *
*/ */
/* $Id: avl.c,v 1.3 2003/03/08 16:05:38 karl Exp $ */ /* $Id: avl.c,v 1.4 2003/03/15 02:10:18 msmith Exp $ */
/* /*
* This is a fairly straightfoward translation of a prototype * This is a fairly straightfoward translation of a prototype
...@@ -39,8 +39,8 @@ ...@@ -39,8 +39,8 @@
#include "avl.h" #include "avl.h"
avl_node * avl_node *
avl_node_new (void * key, avl_node_new (void * key,
avl_node * parent) avl_node * parent)
{ {
avl_node * node = (avl_node *) malloc (sizeof (avl_node)); avl_node * node = (avl_node *) malloc (sizeof (avl_node));
...@@ -57,11 +57,11 @@ avl_node_new (void * key, ...@@ -57,11 +57,11 @@ avl_node_new (void * key,
thread_rwlock_create(&node->rwlock); thread_rwlock_create(&node->rwlock);
return node; return node;
} }
} }
avl_tree * avl_tree *
avl_tree_new (avl_key_compare_fun_type compare_fun, avl_tree_new (avl_key_compare_fun_type compare_fun,
void * compare_arg) void * compare_arg)
{ {
avl_tree * t = (avl_tree *) malloc (sizeof (avl_tree)); avl_tree * t = (avl_tree *) malloc (sizeof (avl_tree));
...@@ -111,7 +111,7 @@ avl_tree_free (avl_tree * tree, avl_free_key_fun_type free_key_fun) ...@@ -111,7 +111,7 @@ avl_tree_free (avl_tree * tree, avl_free_key_fun_type free_key_fun)
int int
avl_insert (avl_tree * ob, avl_insert (avl_tree * ob,
void * key) void * key)
{ {
if (!(ob->root->right)) { if (!(ob->root->right)) {
avl_node * node = avl_node_new (key, ob->root); avl_node * node = avl_node_new (key, ob->root);
...@@ -131,42 +131,42 @@ avl_insert (avl_tree * ob, ...@@ -131,42 +131,42 @@ avl_insert (avl_tree * ob,
while (1) { while (1) {
if (ob->compare_fun (ob->compare_arg, key, p->key) < 1) { if (ob->compare_fun (ob->compare_arg, key, p->key) < 1) {
/* move left */ /* move left */
AVL_SET_RANK (p, (AVL_GET_RANK (p) + 1)); AVL_SET_RANK (p, (AVL_GET_RANK (p) + 1));
q = p->left; q = p->left;
if (!q) { if (!q) {
/* insert */ /* insert */
avl_node * q_node = avl_node_new (key, p); avl_node * q_node = avl_node_new (key, p);
if (!q_node) { if (!q_node) {
return (-1); return (-1);
} else {
q = q_node;
p->left = q;
break;
}
} else if (AVL_GET_BALANCE(q)) {
t = p;
s = q;
}
p = q;
} else { } else {
/* move right */ q = q_node;
q = p->right; p->left = q;
if (!q) { break;
/* insert */ }
avl_node * q_node = avl_node_new (key, p); } else if (AVL_GET_BALANCE(q)) {
if (!q_node) { t = p;
return -1; s = q;
} else { }
q = q_node; p = q;
p->right = q; } else {
break; /* move right */
} q = p->right;
} else if (AVL_GET_BALANCE(q)) { if (!q) {
t = p; /* insert */
s = q; avl_node * q_node = avl_node_new (key, p);
} if (!q_node) {
p = q; return -1;
} else {
q = q_node;
p->right = q;
break;
}
} else if (AVL_GET_BALANCE(q)) {
t = p;
s = q;
}
p = q;
} }
} }
...@@ -180,11 +180,11 @@ avl_insert (avl_tree * ob, ...@@ -180,11 +180,11 @@ avl_insert (avl_tree * ob,
} }
while (p != q) { while (p != q) {
if (ob->compare_fun (ob->compare_arg, key, p->key) < 1) { if (ob->compare_fun (ob->compare_arg, key, p->key) < 1) {
AVL_SET_BALANCE (p, -1); AVL_SET_BALANCE (p, -1);
p = p->left; p = p->left;
} else { } else {
AVL_SET_BALANCE (p, +1); AVL_SET_BALANCE (p, +1);
p = p->right; p = p->right;
} }
} }
...@@ -205,79 +205,79 @@ avl_insert (avl_tree * ob, ...@@ -205,79 +205,79 @@ avl_insert (avl_tree * ob,
return 0; return 0;
} else if (AVL_GET_BALANCE(s) == a) { } else if (AVL_GET_BALANCE(s) == a) {
if (AVL_GET_BALANCE (r) == a) { if (AVL_GET_BALANCE (r) == a) {
/* single rotation */ /* single rotation */
p = r; p = r;
if (a == -1) { if (a == -1) {
s->left = r->right; s->left = r->right;
if (r->right) { if (r->right) {
r->right->parent = s; r->right->parent = s;
} }
r->right = s; r->right = s;
s->parent = r; s->parent = r;
AVL_SET_RANK (s, (AVL_GET_RANK (s) - AVL_GET_RANK (r))); AVL_SET_RANK (s, (AVL_GET_RANK (s) - AVL_GET_RANK (r)));
} else { } else {
s->right = r->left; s->right = r->left;
if (r->left) { if (r->left) {
r->left->parent = s; r->left->parent = s;
} }
r->left = s; r->left = s;
s->parent = r; s->parent = r;
AVL_SET_RANK (r, (AVL_GET_RANK (r) + AVL_GET_RANK (s))); AVL_SET_RANK (r, (AVL_GET_RANK (r) + AVL_GET_RANK (s)));
} }
AVL_SET_BALANCE (s, 0); AVL_SET_BALANCE (s, 0);
AVL_SET_BALANCE (r, 0); AVL_SET_BALANCE (r, 0);
} else if (AVL_GET_BALANCE (r) == -a) { } else if (AVL_GET_BALANCE (r) == -a) {
/* double rotation */ /* double rotation */
if (a == -1) { if (a == -1) {
p = r->right; p = r->right;
r->right = p->left; r->right = p->left;
if (p->left) { if (p->left) {
p->left->parent = r; p->left->parent = r;
} }
p->left = r; p->left = r;
r->parent = p; r->parent = p;
s->left = p->right; s->left = p->right;
if (p->right) { if (p->right) {
p->right->parent = s; p->right->parent = s;
} }
p->right = s; p->right = s;
s->parent = p; s->parent = p;
AVL_SET_RANK (p, (AVL_GET_RANK (p) + AVL_GET_RANK (r))); AVL_SET_RANK (p, (AVL_GET_RANK (p) + AVL_GET_RANK (r)));
AVL_SET_RANK (s, (AVL_GET_RANK (s) - AVL_GET_RANK (p))); AVL_SET_RANK (s, (AVL_GET_RANK (s) - AVL_GET_RANK (p)));
} else { } else {
p = r->left; p = r->left;
r->left = p->right; r->left = p->right;
if (p->right) { if (p->right) {
p->right->parent = r; p->right->parent = r;
} }
p->right = r; p->right = r;
r->parent = p; r->parent = p;
s->right = p->left; s->right = p->left;
if (p->left) { if (p->left) {
p->left->parent = s; p->left->parent = s;
} }
p->left = s; p->left = s;
s->parent = p; s->parent = p;
AVL_SET_RANK (r, (AVL_GET_RANK (r) - AVL_GET_RANK (p))); AVL_SET_RANK (r, (AVL_GET_RANK (r) - AVL_GET_RANK (p)));
AVL_SET_RANK (p, (AVL_GET_RANK (p) + AVL_GET_RANK (s))); AVL_SET_RANK (p, (AVL_GET_RANK (p) + AVL_GET_RANK (s)));
} }
if (AVL_GET_BALANCE (p) == a) { if (AVL_GET_BALANCE (p) == a) {
AVL_SET_BALANCE (s, -a); AVL_SET_BALANCE (s, -a);
AVL_SET_BALANCE (r, 0); AVL_SET_BALANCE (r, 0);
} else if (AVL_GET_BALANCE (p) == -a) { } else if (AVL_GET_BALANCE (p) == -a) {
AVL_SET_BALANCE (s, 0); AVL_SET_BALANCE (s, 0);
AVL_SET_BALANCE (r, a); AVL_SET_BALANCE (r, a);
} else { } else {
AVL_SET_BALANCE (s, 0); AVL_SET_BALANCE (s, 0);
AVL_SET_BALANCE (r, 0); AVL_SET_BALANCE (r, 0);
} }
AVL_SET_BALANCE (p, 0); AVL_SET_BALANCE (p, 0);
} }
/* finishing touch */ /* finishing touch */
if (s == t->right) { if (s == t->right) {
t->right = p; t->right = p;
} else { } else {
t->left = p; t->left = p;
} }
p->parent = t; p->parent = t;
} }
...@@ -287,8 +287,8 @@ avl_insert (avl_tree * ob, ...@@ -287,8 +287,8 @@ avl_insert (avl_tree * ob,
int int
avl_get_by_index (avl_tree * tree, avl_get_by_index (avl_tree * tree,
unsigned long index, unsigned long index,
void ** value_address) void ** value_address)
{ {
avl_node * p = tree->root->right; avl_node * p = tree->root->right;
unsigned long m = index + 1; unsigned long m = index + 1;
...@@ -307,11 +307,11 @@ avl_get_by_index (avl_tree * tree, ...@@ -307,11 +307,11 @@ avl_get_by_index (avl_tree * tree,
} }
} }
} }
int int
avl_get_by_key (avl_tree * tree, avl_get_by_key (avl_tree * tree,
void * key, void * key,
void **value_address) void **value_address)
{ {
avl_node * x = tree->root->right; avl_node * x = tree->root->right;
if (!x) { if (!x) {
...@@ -321,15 +321,15 @@ avl_get_by_key (avl_tree * tree, ...@@ -321,15 +321,15 @@ avl_get_by_key (avl_tree * tree,
int compare_result = tree->compare_fun (tree->compare_arg, key, x->key); int compare_result = tree->compare_fun (tree->compare_arg, key, x->key);
if (compare_result < 0) { if (compare_result < 0) {
if (x->left) { if (x->left) {
x = x->left; x = x->left;
} else { } else {
return -1; return -1;
} }
} else if (compare_result > 0) { } else if (compare_result > 0) {
if (x->right) { if (x->right) {
x = x->right; x = x->right;
} else { } else {
return -1; return -1;
} }
} else { } else {
*value_address = x->key; *value_address = x->key;
...@@ -356,33 +356,33 @@ int avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun) ...@@ -356,33 +356,33 @@ int avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun)
*/ */
AVL_SET_RANK (x, (AVL_GET_RANK(x) - 1)); AVL_SET_RANK (x, (AVL_GET_RANK(x) - 1));
if (x->left) { if (x->left) {
x = x->left; x = x->left;
} else { } else {
/* Oops! now we have to undo the rank changes /* Oops! now we have to undo the rank changes
* all the way up the tree * all the way up the tree
*/ */
AVL_SET_RANK(x, (AVL_GET_RANK (x) + 1)); AVL_SET_RANK(x, (AVL_GET_RANK (x) + 1));
while (x != tree->root->right) { while (x != tree->root->right) {
if (x->parent->left == x) { if (x->parent->left == x) {
AVL_SET_RANK(x->parent, (AVL_GET_RANK (x->parent) + 1)); AVL_SET_RANK(x->parent, (AVL_GET_RANK (x->parent) + 1));
} }
x = x->parent; x = x->parent;
} }
return -1; /* key not in tree */ return -1; /* key not in tree */
} }
} else if (compare_result > 0) { } else if (compare_result > 0) {
/* move right */ /* move right */
if (x->right) { if (x->right) {
x = x->right; x = x->right;
} else { } else {
AVL_SET_RANK(x, (AVL_GET_RANK (x) + 1)); AVL_SET_RANK(x, (AVL_GET_RANK (x) + 1));
while (x != tree->root->right) { while (x != tree->root->right) {
if (x->parent->left == x) { if (x->parent->left == x) {
AVL_SET_RANK(x->parent, (AVL_GET_RANK (x->parent) + 1)); AVL_SET_RANK(x->parent, (AVL_GET_RANK (x->parent) + 1));
} }
x = x->parent; x = x->parent;
} }
return -1; /* key not in tree */ return -1; /* key not in tree */
} }
} else { } else {
break; break;
...@@ -453,15 +453,15 @@ int avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun) ...@@ -453,15 +453,15 @@ int avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun)
/* case 1: height unchanged */ /* case 1: height unchanged */
if (AVL_GET_BALANCE(p) == 0) { if (AVL_GET_BALANCE(p) == 0) {
if (shortened_side == -1) { if (shortened_side == -1) {
/* we removed a left child, the tree is now heavier /* we removed a left child, the tree is now heavier
* on the right * on the right
*/ */
AVL_SET_BALANCE (p, +1); AVL_SET_BALANCE (p, +1);
} else { } else {
/* we removed a right child, the tree is now heavier /* we removed a right child, the tree is now heavier
* on the left * on the left
*/ */
AVL_SET_BALANCE (p, -1); AVL_SET_BALANCE (p, -1);
} }
shorter = 0; shorter = 0;
...@@ -473,125 +473,125 @@ int avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun) ...@@ -473,125 +473,125 @@ int avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun)
top = p->parent; top = p->parent;
/* set <q> to the taller of the two subtrees of <p> */ /* set <q> to the taller of the two subtrees of <p> */
if (shortened_side == 1) { if (shortened_side == 1) {
q = p->left; q = p->left;
} else { } else {
q = p->right; q = p->right;
} }
if (AVL_GET_BALANCE (q) == 0) { if (AVL_GET_BALANCE (q) == 0) {
/* case 3a: height unchanged */ /* case 3a: height unchanged */
if (shortened_side == -1) { if (shortened_side == -1) {
/* single rotate left */ /* single rotate left */
q->parent = p->parent; q->parent = p->parent;
p->right = q->left; p->right = q->left;
if (q->left) { if (q->left) {
q->left->parent = p; q->left->parent = p;
} }
q->left = p; q->left = p;
p->parent = q; p->parent = q;
AVL_SET_RANK (q, (AVL_GET_RANK (q) + AVL_GET_RANK (p))); AVL_SET_RANK (q, (AVL_GET_RANK (q) + AVL_GET_RANK (p)));
} else { } else {
/* single rotate right */ /* single rotate right */
q->parent = p->parent; q->parent = p->parent;
p->left = q->right; p->left = q->right;
if (q->right) { if (q->right) {
q->right->parent = p; q->right->parent = p;
} }
q->right = p; q->right = p;
p->parent = q; p->parent = q;
AVL_SET_RANK (p, (AVL_GET_RANK (p) - AVL_GET_RANK (q))); AVL_SET_RANK (p, (AVL_GET_RANK (p) - AVL_GET_RANK (q)));
} }
shorter = 0; shorter = 0;
AVL_SET_BALANCE (q, shortened_side); AVL_SET_BALANCE (q, shortened_side);
AVL_SET_BALANCE (p, (- shortened_side)); AVL_SET_BALANCE (p, (- shortened_side));
} else if (AVL_GET_BALANCE (q) == AVL_GET_BALANCE (p)) { } else if (AVL_GET_BALANCE (q) == AVL_GET_BALANCE (p)) {
/* case 3b: height reduced */ /* case 3b: height reduced */
if (shortened_side == -1) { if (shortened_side == -1) {
/* single rotate left */ /* single rotate left */
q->parent = p->parent; q->parent = p->parent;
p->right = q->left; p->right = q->left;
if (q->left) { if (q->left) {
q->left->parent = p; q->left->parent = p;
} }
q->left = p; q->left = p;
p->parent = q; p->parent = q;
AVL_SET_RANK (q, (AVL_GET_RANK (q) + AVL_GET_RANK (p))); AVL_SET_RANK (q, (AVL_GET_RANK (q) + AVL_GET_RANK (p)));
} else { } else {
/* single rotate right */ /* single rotate right */
q->parent = p->parent; q->parent = p->parent;
p->left = q->right; p->left = q->right;
if (q->right) { if (q->right) {
q->right->parent = p; q->right->parent = p;
} }
q->right = p; q->right = p;
p->parent = q; p->parent = q;
AVL_SET_RANK (p, (AVL_GET_RANK (p) - AVL_GET_RANK (q))); AVL_SET_RANK (p, (AVL_GET_RANK (p) - AVL_GET_RANK (q)));
} }
shorter = 1; shorter = 1;
AVL_SET_BALANCE (q, 0); AVL_SET_BALANCE (q, 0);
AVL_SET_BALANCE (p, 0); AVL_SET_BALANCE (p, 0);
} else { } else {
/* case 3c: height reduced, balance factors opposite */ /* case 3c: height reduced, balance factors opposite */
if (shortened_side == 1) { if (shortened_side == 1) {
/* double rotate right */ /* double rotate right */
/* first, a left rotation around q */ /* first, a left rotation around q */
r