#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <string.h>#include <sys/time.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <fcntl.h>#include <sys/ioctl.h>#include <errno.h>#include <netdb.h>#include "utils.h"Include dependency graph for utils.cc:

Go to the source code of this file.
Defines | |
| #define | LL_HEAPSIZE 50 |
| #define | AVL_ALLOC_NUM 200 |
Functions | |
| const char * | dumb_strcasestr (const char *string, const char *substr) |
| void | dump_buf (FILE *std, char *buf, int retlen) |
| tv_time | tv_timeadd (tv_time t1, tv_time t2) |
| tv_time | tv_timesub (tv_time t1, tv_time t2) |
| tv_time | tv_timemul (tv_time t1, double mult) |
| int | tv_timecmp (tv_time t1, tv_time t2) |
| ts_time | ts_timeadd (ts_time t1, ts_time t2) |
| ts_time | ts_timesub (ts_time t1, ts_time t2) |
| ts_time | ts_timemul (ts_time t1, double mult) |
| int | ts_timecmp (ts_time t1, ts_time t2) |
| ts_strtok_state * | ts_strtok_init (char *string) |
| char * | ts_strtok (char *matching, ts_strtok_state *state) |
| int | ts_strtok_finish (ts_strtok_state *state) |
| char * | dumb_strnstr (char *str, char *substr, int n) |
| int | correct_write (int s, char *data, int len) |
| int | correct_read (int s, char *data, int len) |
| ll | Allocate_ll (void) |
| void | Free_ll (ll freeMe) |
| int | ll_add_to_end (ll *addToMe, void *data) |
| int | ll_add_to_start (ll *addToMe, void *data) |
| ll | ll_find (ll *findInMe, void *data, int(*compare)(void *d1, void *d2)) |
| int | ll_sorted_insert (ll *insertme, void *data, int(*compare)(void *d1, void *d2)) |
| int | ll_del (ll *delFromMe, void *data, int(*compare)(void *d1, void *d2), void(*nukeElement)(void *nukeMe)) |
| int | ll_delfirst (ll *delFromMe, void(*nukeElement)(void *nukeMe)) |
| int | ll_destroy (ll *destroyMe, void(*nukeElement)(void *nukeMe)) |
| int | ll_build (ll *buildMe, char *buildFromMe) |
| int | chained_hash_create (int num_slots, hash_table *rt) |
| int | chained_hash_destroy (hash_table ht, deletor d) |
| int | chained_hash_insert (hash_table ht, void *element, hash_function f) |
| void * | chained_hash_search (hash_table ht, void *element, hash_function f, sc_comparator c) |
| int | chained_hash_delete (hash_table ht, void *element, hash_function f, deletor d, sc_comparator c) |
| AVL_tree | Allocate_AVL_tree (void) |
| void | Free_AVL_tree (AVL_tree freeMe) |
| int | Tree_Add (AVL_tree *addToMe, void *addMe, AVL_comparator theComp) |
| int | Tree_Delete (AVL_tree *deleteFromMe, void *deleteMe, AVL_comparator theComp, AVL_deletor theDel) |
| int | Tree_Destroy (AVL_tree *destroyMe, AVL_deletor theDel) |
| AVL_tree | Tree_Search (AVL_tree searchMe, void *searchForMe, AVL_comparator theComp) |
| AVL_tree | Tree_First (AVL_tree searchMe) |
| AVL_tree | Tree_Last (AVL_tree searchMe) |
| AVL_tree | Tree_Next (AVL_tree searchMe) |
Variables | |
| ll | heap_o_ll = NULL |
|
|
|
|
|
Definition at line 353 of file utils.cc. Referenced by Allocate_ll(). |
|
|
Definition at line 1042 of file utils.cc. Referenced by Tree_Add().
01043 {
01044 AVL_tree temp_pointer;
01045
01046 temp_pointer = (AVL_tree) malloc(sizeof(AVL_tree_element));
01047 if (temp_pointer == NULL) {
01048 fprintf(stderr, "Out of memory in Allocate_AVL_tree!\n");
01049 exit(-1);
01050 }
01051 return temp_pointer;
01052 }
|
|
|
Definition at line 512 of file utils.cc. References heap_o_ll, LL_HEAPSIZE, ll_st::next, and ll_st::prev. Referenced by ll_add_to_end(), ll_add_to_start(), and ll_sorted_insert().
00513 {
00514 int counter;
00515 ll temp_pointer;
00516
00517 /* if heap is null, am out of ll elements and must allocate more */
00518 if (heap_o_ll == NULL)
00519 {
00520 heap_o_ll = (ll_node *) malloc(LL_HEAPSIZE * sizeof(ll_node));
00521 if (heap_o_ll == NULL)
00522 {
00523 fprintf(stderr, "Out of memory in Allocate_ll!\n");
00524 exit(1);
00525 }
00526 for (counter=0; counter < LL_HEAPSIZE - 1; counter++)
00527 {
00528 (heap_o_ll + counter)->data = NULL;
00529 (heap_o_ll + counter)->prev = NULL;
00530 (heap_o_ll + counter)->next = (heap_o_ll + counter + 1);
00531 }
00532 (heap_o_ll + LL_HEAPSIZE - 1)->next = NULL;
00533 }
00534
00535 /* Have a workable heap. Splice off top and return pointer. */
00536 temp_pointer = heap_o_ll;
00537 heap_o_ll = heap_o_ll->next;
00538 temp_pointer->next = NULL;
00539 return temp_pointer;
00540 }
|
|
||||||||||||
|
Definition at line 603 of file utils.cc. References hash_el, hash_table_st::num_elements, and hash_table_st::slot_array.
00604 {
00605 hash_table retval;
00606 hash_el *sArray;
00607 int i;
00608
00609 /* Creating a chained hash table is as simple as allocating room
00610 for all of the slots. */
00611
00612 sArray = retval.slot_array = (hash_el *) malloc(num_slots*sizeof(hash_el));
00613 if (retval.slot_array == NULL)
00614 return -1;
00615
00616 retval.num_elements = num_slots;
00617 *rt = retval;
00618
00619 /* Initialize all slots to have a null entry */
00620 for (i=0; i<num_slots; i++)
00621 sArray[i] = NULL;
00622
00623 return 0;
00624 }
|
|
||||||||||||||||||||||||
|
Definition at line 698 of file utils.cc. References ll_del(), hash_table_st::num_elements, and hash_table_st::slot_array.
00700 {
00701 ll *slotList;
00702 int slotnum;
00703
00704 slotnum = f(element, ht.num_elements);
00705 if (! ((slotnum >= 0) && (slotnum < ht.num_elements)) )
00706 return 0; /* f is bad */
00707
00708 slotList = &(ht.slot_array[slotnum]);
00709 if (slotList == NULL)
00710 return 0; /* no list, no element */
00711
00712 return ll_del(slotList, element, c, d);
00713 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 626 of file utils.cc. References hash_el, ll_destroy(), hash_table_st::num_elements, and hash_table_st::slot_array.
00627 {
00628 int i, numEl;
00629 hash_el *sArray;
00630
00631 /* Destroying a hash table first implies destroying all of the
00632 lists in the table, then freeing the table itself. */
00633
00634 for (i=0, numEl=ht.num_elements, sArray=ht.slot_array; i<numEl; i++)
00635 {
00636 if (sArray[i] != NULL)
00637 {
00638 /* We must destroy the list in this slot */
00639 ll_destroy(&(sArray[i]), d);
00640 sArray[i] = NULL;
00641 }
00642 }
00643 free(sArray);
00644 return 0;
00645 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 647 of file utils.cc. References ll_add_to_start(), hash_table_st::num_elements, and hash_table_st::slot_array.
00648 {
00649 int slotnum;
00650 ll *slotList;
00651
00652 slotnum = f(element, ht.num_elements);
00653 if (! ((slotnum >= 0) && (slotnum < ht.num_elements)) )
00654 return -1; /* f is bad */
00655
00656 slotList = &(ht.slot_array[slotnum]);
00657 if (ll_add_to_start(slotList, element) != 1)
00658 return -1; /* list insert failed */
00659
00660 return 0;
00661 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 663 of file utils.cc. References ll_st::data, ll_find(), hash_table_st::num_elements, and hash_table_st::slot_array.
00665 {
00666 ll *slotList, foundEl;
00667 int slotnum;
00668
00669 #ifdef DEBUG
00670 printf("chained_hash_search: about to f element, numelements %d\n", ht.num_elements);
00671 #endif
00672
00673 slotnum = f(element, ht.num_elements);
00674
00675 #ifdef DEBUG
00676 printf("f() returned slotnum %d\n", slotnum);
00677 #endif
00678
00679 if (! ((slotnum >= 0) && (slotnum < ht.num_elements)) )
00680 return NULL; /* f is bad */
00681
00682 #ifdef DEBUG
00683 printf("in chs: slotnum %d\n", slotnum);
00684 #endif
00685 slotList = &(ht.slot_array[slotnum]);
00686 if (slotList == NULL)
00687 return NULL; /* no list, no element */
00688
00689 #ifdef DEBUG
00690 printf("about to ll_find on slotList.\n");
00691 #endif
00692 foundEl = ll_find(slotList, element, c);
00693 if (foundEl == NULL)
00694 return NULL;
00695 return foundEl->data;
00696 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 332 of file utils.cc. References len. Referenced by lf_get_next_entry().
00333 {
00334 int sofar, ret;
00335 char *tmp;
00336
00337 sofar = 0;
00338 while(sofar != len) {
00339 tmp = data + (unsigned long) sofar;
00340 ret = read(s, tmp, len-sofar);
00341 if (ret <= 0) {
00342 if (! ((ret == -1) && ((errno == EAGAIN) || (errno == EINTR))) )
00343 /* BUG:: What if another thread generates an error and trounces errno? */
00344 return ret;
00345 } else
00346 sofar += ret;
00347 }
00348 return len;
00349 }
|
|
||||||||||||||||
|
Definition at line 310 of file utils.cc. References len.
00311 {
00312 int sofar, ret;
00313 char *tmp;
00314
00315 if (len == -1)
00316 len = strlen(data);
00317
00318 sofar = 0;
00319 while (sofar != len) {
00320 tmp = data + (unsigned long) sofar;
00321 ret = write(s, tmp, len-sofar);
00322 if (ret <= 0) {
00323 if (! ((ret == -1) && ((errno == EAGAIN) || (errno == EINTR))) )
00324 /* BUG:: What if another thread generates an error and trounces errno? */
00325 return ret;
00326 } else
00327 sofar += ret;
00328 }
00329 return len;
00330 }
|
|
||||||||||||
|
Definition at line 64 of file utils.cc.
00065 {
00066 int str_len, substr_len, cmplen, i;
00067 const char *ptr;
00068
00069 str_len = strlen(string);
00070 substr_len = strlen(substr);
00071 cmplen = str_len - substr_len + 1;
00072
00073 for (ptr = string, i=0; i<cmplen; i++, ptr++) {
00074 if (strncasecmp(ptr, substr, substr_len) == 0)
00075 return ptr;
00076 }
00077 return NULL;
00078 }
|
|
||||||||||||||||
|
Definition at line 292 of file utils.cc.
00293 {
00294 int i, substrlen, ml;
00295 char *tmp;
00296
00297 substrlen = strlen(substr);
00298
00299 for (i=0,tmp=str; i<=n-substrlen; i++, tmp++) {
00300 if (*tmp == '\0')
00301 return NULL;
00302 if ( (ml = memcmp(tmp, substr, substrlen)) == 0)
00303 return tmp;
00304 }
00305 return NULL;
00306 }
|
|
||||||||||||||||
|
Definition at line 84 of file utils.cc.
00085 {
00086 int i, j;
00087
00088 for (i=0; i<retlen/5; i++) {
00089 for (j=0; j<5; j++) {
00090 fprintf(std, "%.02x ", *(buf + (unsigned) 5*i + j));
00091 }
00092 fprintf(std, " ");
00093 for (j=0; j<5; j++) {
00094 fprintf(std, "%c ", *(buf + (unsigned) 5*i + j));
00095 }
00096 fprintf(std, "\n");
00097 }
00098 if (retlen % 5 != 0) {
00099 for (j=0; j < retlen % 5; j++) {
00100 fprintf(std, "%.02x ", *(buf + (unsigned) 5*(retlen/5) + j));
00101 }
00102 fprintf(std, " ");
00103 for (j=0; j<5; j++) {
00104 fprintf(std, "%c ", *(buf + (unsigned) 5*i + j));
00105 }
00106 fprintf(std, "\n");
00107 }
00108 }
|
|
|
Definition at line 1054 of file utils.cc. Referenced by Tree_Delete(), and Tree_Destroy().
01055 {
01056 /* assume that data has been freed */
01057 if (freeMe == NULL)
01058 return;
01059
01060 free(freeMe);
01061 }
|
|
|
Definition at line 542 of file utils.cc. References heap_o_ll, and ll_st::next. Referenced by ll_del(), ll_delfirst(), and ll_destroy().
|
|
||||||||||||
|
Definition at line 360 of file utils.cc. References Allocate_ll(), ll_st::data, and ll_st::next. Referenced by ll_build(), and ll_sorted_insert().
00361 {
00362 ll temp;
00363
00364 temp = *addToMe;
00365 if (temp == NULL)
00366 {
00367 *addToMe = temp = Allocate_ll();
00368 temp->data = data;
00369 temp->prev = temp->next = NULL;
00370 return 1;
00371 }
00372
00373 while (temp->next != NULL)
00374 temp = temp->next;
00375
00376 temp->next = Allocate_ll();
00377 (temp->next)->prev = temp;
00378 (temp->next)->next = NULL;
00379 (temp->next)->data = data;
00380 return 1;
00381 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 383 of file utils.cc. References Allocate_ll(), ll_st::data, and ll_st::prev. Referenced by chained_hash_insert().
00384 {
00385 ll temp;
00386
00387 temp = *addToMe;
00388 if (temp == NULL)
00389 {
00390 *addToMe = temp = Allocate_ll();
00391 temp->data = data;
00392 temp->prev = temp->next = NULL;
00393 return 1;
00394 }
00395
00396 temp->prev = Allocate_ll();
00397 (temp->prev)->next = temp;
00398 (temp->prev)->prev = NULL;
00399 (temp->prev)->data = data;
00400 *addToMe = temp->prev;
00401
00402 return 1;
00403
00404 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 549 of file utils.cc. References ll_add_to_end().
00550 {
00551 /* Takes string of form [a, b, c, d, e] and builds linked list with
00552 elements from the string. Malloc's space for new linked list element
00553 strings. */
00554
00555 char *end, *start, *data, *temp;
00556
00557 data = (char *) malloc(sizeof(char) * (strlen(buildFromMe)+1));
00558 if (data == NULL)
00559 {
00560 fprintf(stderr, "Out of memory in ll_build!\n");
00561 return 0;
00562 }
00563 strcpy(data, buildFromMe);
00564 start = end = data + 1;
00565
00566 while ((*end != ']') && (*end != '\0'))
00567 {
00568 while (*start == ' ')
00569 {
00570 start++; end++;
00571 }
00572
00573 if (*end == ',')
00574 {
00575 *end = '\0';
00576 temp = (char *) (malloc(sizeof(char) * (strlen(start)+1)));
00577 if (temp == NULL)
00578 {
00579 fprintf(stderr, "Out of memory in ll_build!\n");
00580 return 0;
00581 }
00582 strcpy(temp, start);
00583 ll_add_to_end(buildMe, (void *) temp);
00584 start = end + 1;
00585 }
00586 end++;
00587 }
00588 *end = '\0';
00589 temp = (char *) (malloc(sizeof(char) * (strlen(start)+1)));
00590 if (temp == NULL)
00591 {
00592 fprintf(stderr, "Out of memory in ll_build!\n");
00593 return 0;
00594 }
00595 strcpy(temp, start);
00596 ll_add_to_end(buildMe, (void *) temp);
00597 free(data);
00598 return 1;
00599 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 446 of file utils.cc. References compare(), ll_st::data, Free_ll(), ll_st::next, and ll_st::prev. Referenced by chained_hash_delete().
00448 {
00449 ll temp = *delFromMe;
00450
00451 while (temp != NULL)
00452 {
00453 if (compare(data, temp->data) == 0) /* ie the same */
00454 {
00455 if (temp->prev != NULL)
00456 (temp->prev)->next = temp->next;
00457
00458 if (temp->next != NULL)
00459 (temp->next)->prev = temp->prev;
00460
00461 if (temp == *delFromMe)
00462 *delFromMe = temp->next;
00463
00464 if (nukeElement != NULL)
00465 nukeElement(temp->data);
00466 Free_ll(temp);
00467 return 1;
00468 }
00469 temp = temp->next;
00470 }
00471 return 0;
00472 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 474 of file utils.cc. References ll_st::data, Free_ll(), ll_st::next, and ll_st::prev.
00475 {
00476 ll temp = *delFromMe;
00477
00478 if (temp == NULL)
00479 return 0;
00480
00481 if (temp->prev != NULL)
00482 (temp->prev)->next = temp->next;
00483
00484 if (temp->next != NULL)
00485 (temp->next)->prev = temp->prev;
00486
00487 if (temp == *delFromMe)
00488 *delFromMe = temp->next;
00489
00490 if (nukeElement != NULL)
00491 nukeElement(temp->data);
00492 Free_ll(temp);
00493 return 1;
00494 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 496 of file utils.cc. References ll_st::data, Free_ll(), and ll_st::next. Referenced by chained_hash_destroy().
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 406 of file utils.cc. References compare(), ll_st::data, and ll_st::next. Referenced by chained_hash_search().
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 420 of file utils.cc. References Allocate_ll(), compare(), ll_st::data, ll_add_to_end(), ll_st::next, and ll_st::prev.
00422 {
00423 ll temp = *insertme, addEl;
00424
00425 while (temp != NULL) {
00426 if (compare(data, temp->data) <= 0) {/* ie. the same or smaller */
00427 /* insert before temp */
00428 addEl = Allocate_ll();
00429 addEl->data = data;
00430 addEl->prev = temp->prev;
00431 addEl->next = temp;
00432 temp->prev = addEl;
00433 if (addEl->prev == NULL)
00434 *insertme = addEl;
00435 else
00436 (addEl->prev)->next = addEl;
00437 return 1;
00438 }
00439 temp = temp->next;
00440 }
00441
00442 /* We hit the end, so add to the end */
00443 return ll_add_to_end(insertme, data);
00444 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 730 of file utils.cc. References Allocate_AVL_tree(), AVL_tree_st::bal, FALSE, AVL_tree_st::left, AVL_tree_st::parent, AVL_tree_st::right, and TRUE.
00731 {
00732 static int checkBalance = FALSE;
00733 static AVL_tree parent = NULL;
00734 AVL_tree *addTree = addToMe;
00735
00736 if (*addTree == NULL) /* Add in a new leaf... */
00737 {
00738 *addTree = Allocate_AVL_tree();
00739 (*addTree)->data = addMe;
00740 (*addTree)->bal = 0;
00741 (*addTree)->left = (*addTree)->right = NULL;
00742 (*addTree)->parent = parent;
00743 checkBalance = TRUE; /* whether balance should be checked */
00744 parent = NULL;
00745 return 0;
00746 }
00747 else
00748 if ( theComp( (*addTree)->data, addMe) > 0 ) // ie. (*addTree)->data > addMe
00749 {
00750 parent = *addTree;
00751 if ( Tree_Add(&((*addTree)->left), addMe, theComp) != 0 )
00752 { checkBalance = FALSE; return -1; }
00753 if (checkBalance == TRUE) /* CHECK FOR REBALANCING -
00754 LEFT INSERTION */
00755 {
00756 switch( (*addTree)->bal) {
00757 case 1 : (*addTree)->bal = 0;
00758 checkBalance = FALSE; return 0;
00759 case 0 : (*addTree)->bal = -1;
00760 checkBalance = TRUE; return 0;
00761 case -1:
00762 { AVL_tree p = (*addTree)->left;
00763 switch (p->bal) {
00764 case -1: { /* LL ROTATION */
00765 AVL_tree q = *addTree;
00766 AVL_tree r = p->right;
00767 p->parent = q->parent;
00768 p->right = q;
00769 q->parent = p; q->left = r;
00770 if (r != NULL)
00771 r->parent = q;
00772 *addTree = p; (*addTree)->bal = 0;
00773 q->bal = 0; checkBalance = FALSE;
00774 return 0; }
00775 case 1: { /* LR ROTATION */
00776 AVL_tree m = *addTree;
00777 AVL_tree q = p->right;
00778 AVL_tree s = q->left;
00779 AVL_tree u = q->right;
00780 q->parent = m->parent;
00781 m->parent = q;
00782 p->parent = q;
00783 if (s != NULL)
00784 s->parent = p;
00785 if (u != NULL)
00786 u->parent = m;
00787 p->right = s; q->left = p;
00788 q->right = m; m->left = u;
00789 *addTree = q;
00790 if (q->bal == 0)
00791 {
00792 q->bal = 0;
00793 p->bal = 0;
00794 m->bal = 0;
00795 }
00796 else if (q->bal == -1)
00797 {
00798 q->bal = 0;
00799 p->bal = 0;
00800 m->bal = 1;
00801
00802 }
00803 else if (q->bal == 1)
00804 {
00805 q->bal = 0;
00806 p->bal = -1;
00807 m->bal = 0;
00808 }
00809 checkBalance = FALSE; return 0; }
00810 default: exit(1);
00811 } } }
00812 }
00813 else
00814 { checkBalance = FALSE; return 0; }
00815 }
00816 else
00817 if ( theComp( (*addTree)->data, addMe) < 0 ) /* ie. (*addTree)->data < addMe */
00818 {
00819 parent = *addTree;
00820 if ( Tree_Add(&((*addTree)->right), addMe, theComp) != 0 )
00821 { checkBalance = FALSE; return -1; }
00822 if (checkBalance == TRUE)
00823 { /* Check for rebalancing - right insertion */
00824 switch ( (*addTree)->bal) {
00825 case -1: (*addTree)->bal = 0;
00826 checkBalance = FALSE; return 0;
00827 case 0 : (*addTree)->bal = 1;
00828 checkBalance = TRUE; return 0;
00829 case 1 :
00830 { AVL_tree p = (*addTree)->right;
00831 switch (p->bal) {
00832 case -1: { /*i RL ROTATION */
00833 AVL_tree m = *addTree;
00834 AVL_tree q = p->left;
00835 AVL_tree r = q->right;
00836 AVL_tree s = q->left;
00837 q->parent = m->parent;
00838 m->parent = q;
00839 p->parent = q;
00840 if (s != NULL)
00841 s->parent = m;
00842 if (r != NULL)
00843 r->parent = p;
00844 m->right = s; q->left = m;
00845 q->right = p; p->left = r;
00846 (*addTree) = q;
00847 if (q->bal == 0)
00848 {
00849 q->bal = 0;
00850 p->bal = 0;
00851 m->bal = 0;
00852 }
00853 else if (q->bal == -1)
00854 {
00855 q->bal = 0;
00856 p->bal = 1;
00857 m->bal = 0;
00858
00859 }
00860 else if (q->bal == 1)
00861 {
00862 q->bal = 0;
00863 p->bal = 0;
00864 m->bal = -1;
00865 }
00866 checkBalance = FALSE;
00867 return 0; }
00868 case 1: { /* RR ROTATION */
00869 AVL_tree q = (*addTree);
00870 AVL_tree r = p->left;
00871 p->parent = q->parent;
00872 q->parent = p;
00873 if (r != NULL)
00874 r->parent = q;
00875 p->left = q; q->right = r;
00876 (*addTree) = p; (*addTree)->bal = 0;
00877 q->bal = 0; checkBalance = FALSE;
00878 return 0; }
00879 }
00880 }
00881 }
00882 }
00883 else
00884 { checkBalance = FALSE; return 0; }
00885 }
00886 else /* key already exists - bomb out */
00887 { checkBalance = FALSE; return -1; }
00888
00889 return 0;
00890 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 892 of file utils.cc. References AVL_tree_st::data, Free_AVL_tree(), AVL_tree_st::left, AVL_tree_st::parent, AVL_tree_st::right, and Tree_Next().
00894 {
00895 /* A simplified version of an AVL_delete algorithm. This procedure will
00896 instead do a regular binary tree deletion */
00897
00898 AVL_tree tempTree, tempTreeX, Z;
00899 static AVL_tree *root = NULL;
00900
00901 Z = *deleteFromMe;
00902
00903 if (*deleteFromMe == NULL) /* hit a leaf. bomb out */
00904 { root = NULL;
00905 return -1;
00906 }
00907
00908 if (root == NULL)
00909 root = deleteFromMe;
00910
00911 if ( theComp((*deleteFromMe)->data, deleteMe) > 0 ) /* ie. (*deleteFromMe)->data > deleteMe */
00912 return Tree_Delete(&((*deleteFromMe)->left), deleteMe, theComp, theDel);
00913 else
00914 {
00915 if ( theComp((*deleteFromMe)->data, deleteMe) < 0) /* ie. (*deleteFromMe)->data < deleteMe */
00916 return Tree_Delete(&((*deleteFromMe)->right), deleteMe, theComp, theDel);
00917 else
00918 {
00919 theDel((*deleteFromMe)->data); /* Call the deletor function */
00920
00921 /* we've found the node to delete - three cases */
00922 if ( (((*deleteFromMe)->left) == NULL) ||
00923 (((*deleteFromMe)->right) == NULL) )
00924 tempTree = *deleteFromMe;
00925 else
00926 tempTree = Tree_Next(*deleteFromMe);
00927
00928 if ( tempTree->left != NULL)
00929 tempTreeX = tempTree->left;
00930 else
00931 tempTreeX = tempTree->right;
00932
00933 if (tempTreeX != NULL)
00934 tempTreeX->parent = tempTree->parent;
00935
00936 if (tempTree->parent == NULL) /* ie root, replace all */
00937 *root = tempTreeX;
00938 else
00939 {
00940 if ( tempTree == ((tempTree->parent)->left) )
00941 ((tempTree->parent)->left) = tempTreeX;
00942 else
00943 ((tempTree->parent)->right) = tempTreeX;
00944 }
00945
00946 if (tempTree != Z)
00947 {
00948 /* splice successor back in */
00949 (*deleteFromMe)->data = tempTree->data;
00950 }
00951
00952 Free_AVL_tree(tempTree);
00953 root = NULL;
00954 return 0;
00955
00956 }
00957 }
00958 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 960 of file utils.cc. References Free_AVL_tree().
00961 {
00962 if (*destroyMe == NULL)
00963 return 0;
00964
00965 Tree_Destroy( &((*destroyMe)->left), theDel);
00966 Tree_Destroy( &((*destroyMe)->right), theDel);
00967
00968 theDel( (*destroyMe)->data );
00969 Free_AVL_tree(*destroyMe);
00970 *destroyMe = NULL;
00971 return 0;
00972 }
|
Here is the call graph for this function:

|
|
Definition at line 989 of file utils.cc. References AVL_tree_st::left.
|
|
|
Definition at line 1002 of file utils.cc. References AVL_tree_st::right.
|
|
|
Definition at line 1015 of file utils.cc. References AVL_tree_st::left, AVL_tree_st::parent, and AVL_tree_st::right. Referenced by Tree_Delete().
01016 {
01017 AVL_tree tempTree;
01018
01019 if ((searchMe->right) != NULL) /* aha! swoop down to min of right subtree */
01020 {
01021 tempTree = searchMe->right;
01022 while ((tempTree->left) != NULL)
01023 tempTree = tempTree->left;
01024 return tempTree;
01025 }
01026
01027 /* right is null - find lowest ancestor whose left child is also ancestor of x */
01028 tempTree = searchMe->parent;
01029 while ( (tempTree != NULL) && (searchMe == tempTree->right) )
01030 {
01031 searchMe = tempTree;
01032 tempTree = tempTree->parent;
01033 }
01034 return tempTree;
01035 }
|
|
||||||||||||||||
|
Definition at line 974 of file utils.cc. References AVL_tree_st::data, AVL_tree_st::left, and AVL_tree_st::right.
00975 {
00976 if (searchMe == NULL) /* didn't find it! */
00977 return NULL;
00978
00979 if (theComp(searchMe->data, searchForMe) > 0 ) /* ie. searchMe->data > searchForMe */
00980 return Tree_Search(searchMe->left, searchForMe, theComp);
00981
00982 if (theComp(searchMe->data, searchForMe) < 0 ) /* ie. searchMe->data < searchForMe */
00983 return Tree_Search(searchMe->right, searchForMe, theComp);
00984
00985 /* aha! found correct key */
00986 return searchMe;
00987 }
|
|
||||||||||||
|
Definition at line 257 of file utils.cc. References ts_strtok_st::chars_remaining, and ts_strtok_st::nxt_ptr.
00258 {
00259 int len1, len2;
00260 char *tmpo;
00261
00262 if ((matching == NULL) || (state == NULL) || (state->chars_remaining <= 0))
00263 return NULL;
00264
00265 len1 = strspn(state->nxt_ptr, matching);
00266 if (len1 > state->chars_remaining) {
00267 return NULL;
00268 }
00269
00270 tmpo = state->nxt_ptr + (unsigned) len1;
00271 len2 = strcspn(tmpo, matching);
00272 if (len2+len1 > state->chars_remaining) {
00273 return NULL;
00274 }
00275 *(tmpo+len2) = '\0';
00276 state->nxt_ptr = tmpo + len2 + 1; /* +1 for the null */
00277 state->chars_remaining -= len1+len2+1; /* +1 for the null */
00278 return tmpo;
00279 }
|
|
|
Definition at line 281 of file utils.cc. References ts_strtok_st::string_dupe.
00282 {
00283 if (state) {
00284 if (state->string_dupe)
00285 free(state->string_dupe);
00286 free(state);
00287 }
00288 return 1;
00289 }
|
|
|
Definition at line 235 of file utils.cc. References ts_strtok_st::chars_remaining, ts_strtok_st::nxt_ptr, and ts_strtok_st::string_dupe.
00236 {
00237 ts_strtok_state *retval;
00238
00239 if (string == NULL)
00240 return NULL;
00241
00242 retval = (ts_strtok_state *) malloc(sizeof(ts_strtok_state));
00243 if (retval == NULL)
00244 return NULL;
00245
00246 retval->string_dupe = strdup(string);
00247 if (retval->string_dupe == NULL) {
00248 free(retval);
00249 return NULL;
00250 }
00251 retval->nxt_ptr = retval->string_dupe;
00252 retval->chars_remaining = strlen(retval->string_dupe);
00253
00254 return retval;
00255 }
|
|
||||||||||||
|
Definition at line 173 of file utils.cc.
|
|
||||||||||||
|
Definition at line 218 of file utils.cc. References t1.
|
|
||||||||||||
|
Definition at line 198 of file utils.cc.
00199 {
00200 ts_time ret;
00201 double rsec;
00202 double rnsec;
00203
00204 rsec = mult * ((double) t1.tv_sec);
00205 rnsec = mult * ((double) t1.tv_nsec);
00206
00207 ret.tv_sec = (long)rsec;
00208 ret.tv_nsec = (long)rnsec;
00209
00210 ret.tv_nsec += (long)((double) 1000000000.0 * (rsec - (double) ret.tv_sec));
00211 while (ret.tv_nsec > 1000000000) {
00212 ret.tv_nsec -= 1000000000;
00213 ret.tv_sec += 1;
00214 }
00215 return ret;
00216 }
|
|
||||||||||||
|
Definition at line 185 of file utils.cc.
|
|
||||||||||||
|
Definition at line 114 of file utils.cc.
|
|
||||||||||||
|
Definition at line 160 of file utils.cc. References t1.
|
|
||||||||||||
|
Definition at line 140 of file utils.cc.
00141 {
00142 tv_time ret;
00143 double rsec;
00144 double rusec;
00145
00146 rsec = mult * ((double) t1.tv_sec);
00147 rusec = mult * ((double) t1.tv_usec);
00148
00149 ret.tv_sec = (long)rsec;
00150 ret.tv_usec = (long)rusec;
00151
00152 ret.tv_usec += (long)((double) 1000000.0 * (rsec - (double) ret.tv_sec));
00153 while (ret.tv_usec > 1000000) {
00154 ret.tv_usec -= 1000000;
00155 ret.tv_sec += 1;
00156 }
00157 return ret;
00158 }
|
|
||||||||||||
|
Definition at line 127 of file utils.cc.
|
|
|
Definition at line 354 of file utils.cc. Referenced by Allocate_ll(), and Free_ll(). |
1.3.3