Skip to content
Snippets Groups Projects
Commit 88bad7c5 authored by Toby Murray's avatar Toby Murray
Browse files

working again

parent 70451048
No related branches found
No related tags found
No related merge requests found
......@@ -64,12 +64,12 @@ static node_t *node_new(const char *url, const cred_t cred){
/* updates a node's credential in place:
replaces p's credential with that from q and frees q */
static void node_edit_cred(node_t * p, const node_t q){
static void node_edit_cred(node_t * p, node_t *q){
free(p->cred.username);
free(p->cred.password);
p->cred.username = q->username;
p->cred.password = q->password;
p->cred.username = q->cred.username;
p->cred.password = q->cred.password;
free(q);
}
......@@ -84,7 +84,7 @@ static void node_free(node_t *p){
we assume that if q has children then it cannot already
be present in p. Otherwise, if q has no children and we find its url in p,
then we edit the found entry in place while preserving its children */
static node_t * node_insert(node_t *p, const node_t *q){
static node_t * node_insert(node_t *p, node_t *q){
if (p == NULL){
return q;
}
......@@ -94,10 +94,9 @@ static node_t * node_insert(node_t *p, const node_t *q){
node_t ** new = NULL;
node_t * const start = p;
while (new == NULL) {
int ret = strcmp(p->url,p->url);
int ret = strcmp(q->url,p->url);
if (ret == 0){
assert (q->left == NULL && q->right == NULL && "illegal insertion");
/* edit the node in place */
node_edit_cred(p,q);
/* q is now freed so cannot be used anymore */
......@@ -121,40 +120,10 @@ static node_t * node_insert(node_t *p, const node_t *q){
return start;
}
/* FIXME: UP TO HERE. Now need to make this use node_insert */
/* returns a pointer to the tree with the node added or with the existing
node updated if it was already present */
static node_t * put(node_t *p, const char *url, const cred_t cred){
if (p == NULL){
return node_new(url,cred);
}
/* we store a pointer to a node pointer that remembers where in the
tree the new node needs to be added */
node_t ** new = NULL;
node_t * const start = p;
while (new == NULL) {
int ret = strcmp(url,p->url);
if (ret == 0){
/* edit the node in place */
node_edit(p,cred);
return start;
}else if (ret < 0){
if (p->left == NULL){
new = &(p->left);
}else{
p = p->left;
}
}else{
if (p->right == NULL){
new = &(p->right);
}else{
p = p->right;
}
}
}
*new = node_new(url,cred);
return start;
return node_insert(p,node_new(url,cred));
}
/* returns a pointer to the tree with the node removed (if it was present) */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment