Optimize cache in tbtree. Fix small bug in psort and move on tmalloc psortex
[tedtools.git] / psortex.c
index fedd701..93c9449 100644 (file)
--- a/psortex.c
+++ b/psortex.c
@@ -30,6 +30,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "tlog.h"
+#include "tmalloc.h"
 #include "psort.h"
 
 #define LENARR (1<<10)
@@ -70,6 +72,8 @@ main(int argn, char *argv[]) {
        int inserted=0;
        EXMPL   **aptr;
 
+       opentlog( TL_OPEN_STDERR,  TL_DEBUG, NULL);
+
        if ( PS_init( &sobj, LIMIT, exstr_cmp, exstr_free ) ) {
                fprintf(stderr,"No memory\n");
                return 1;
@@ -78,16 +82,8 @@ main(int argn, char *argv[]) {
        printf("Test insert:\n");
        for(i=0;i<LENARR;i++) {
                if ( ! ptr ) {
-                       ptr = (EXMPL*)malloc( sizeof(EXMPL) );
-                       if ( ! ptr ) {
-                               fprintf(stderr,"No memory\n");
-                               return 1;       
-                       }
-                       ptr->value=(char*)malloc( 64 );
-                       if ( ! ptr->value ) {
-                               fprintf(stderr,"No memory\n");
-                               return 1;       
-                       }
+                       ptr = (EXMPL*)tmalloc( sizeof(EXMPL) );
+                       ptr->value=(char*)tmalloc( 64 );
                }
                ptr->id = random() % LENARR;
                sprintf( ptr->value, "Value: %d, startnum: %d", ptr->id, i ); 
@@ -111,22 +107,10 @@ main(int argn, char *argv[]) {
 
        srandom(1);
        printf("Test bulk insert:\n");
-       aptr = (EXMPL**)malloc( sizeof(EXMPL*) * LENARR );
-       if ( ! aptr ) {
-               fprintf(stderr,"No memory\n");
-               return 1;       
-       }
+       aptr = (EXMPL**)tmalloc( sizeof(EXMPL*) * LENARR );
        for(i=0;i<LENARR;i++) {
-               aptr[i] = (EXMPL*)malloc( sizeof(EXMPL) );
-               if ( ! aptr[i] ) {
-                       fprintf(stderr,"No memory\n");
-                       return 1;       
-               }
-               aptr[i]->value = (char*)malloc( 64 );
-               if ( ! aptr[i]->value ) {
-                       fprintf(stderr,"No memory\n");
-                       return 1;       
-               }
+               aptr[i] = (EXMPL*)tmalloc( sizeof(EXMPL) );
+               aptr[i]->value = (char*)tmalloc( 64 );
                aptr[i]->id = random() % LENARR;
                sprintf( aptr[i]->value, "Value: %d, startnum: %d", aptr[i]->id, i ); 
        }
@@ -153,18 +137,10 @@ main(int argn, char *argv[]) {
                fprintf(stderr,"No memory\n");
                return 1;
        }
-       ptr = (EXMPL*)malloc( sizeof(EXMPL) * LENARR );
-       if ( ! ptr ) {
-               fprintf(stderr,"No memory\n");
-               return 1;
-       }
+       ptr = (EXMPL*)tmalloc( sizeof(EXMPL) * LENARR );
 
        for(i=0;i<LENARR;i++) {
-               ptr[i].value = (char*)malloc( 64 );
-               if ( ! ptr[i].value ) {
-                       fprintf(stderr,"No memory\n");
-                       return 1;       
-               }
+               ptr[i].value = (char*)tmalloc( 64 );
                ptr[i].id = random() % LENARR;
                sprintf( ptr[i].value, "Value: %d, startnum: %d", ptr[i].id, i ); 
        }