Example #1
0
void test_aa_tree_create_1(void) {

    char mem[aa_tree_size];

    struct aa_tree *t = aa_tree_create( sizeof(mem)
                                      , mem
                                      , sizeof(uint32_t)
                                      , __u32_cmp
                                      , __u32_cpy
                                      , 0
                                      , __alloc
                                      , __dealloc
                                      );

    uint32_t v[] = { 10, 5, 12, 1, 7, 11, 15 };
    size_t i = 0;

    for(; i < sizeof(v)/sizeof(v[0]); i++ ) {
        aa_tree_insert(t, &v[i]);
    }

    __print_u32_digraph(t, "G");

    aa_tree_destroy(t,0,0);
}
Example #2
0
void test_aa_tree_remove_1_0(void) {

    char mem[aa_tree_size];

    struct aa_tree *t = aa_tree_create( sizeof(mem)
                                      , mem
                                      , sizeof(uint32_t)
                                      , __u32_cmp
                                      , __u32_cpy
                                      , 0
                                      , __alloc
                                      , __dealloc
                                      );

    uint32_t v[] = { 50 };
    size_t i = 0;

    for(; i < sizeof(v)/sizeof(v[0]); i++ ) {
        aa_tree_insert(t, &v[i]);
    }

    __print_u32_digraph(t, "G1");
    fprintf(stdout, "\n");

    uint32_t tmp = 0;

    tmp = 50;
    aa_tree_remove(t, &tmp);
    __print_u32_digraph(t, "G2");
    fprintf(stdout, "\n");

    aa_tree_destroy(t,0,0);
}
Example #3
0
static void
test_long_aa(void)
{
  aa_tree_t *aa;
    //                    5  c   19  14  1e  f   18  d   12  10
  long          a[] = { 5, 12, 25, 20, 30, 15, 24, 13, 18, 16 };
  int           i;
  int           n;

  aa = aa_tree_init(&g_long_op);
  if (aa == NULL)
    kerror("init aa tree error");

  for (i = 0; i < sizeof(a)/sizeof(long); ++i) {
    n = aa_tree_insert(aa, (void *) a[i]);
    if (n == KEEXIST)
      printf("[NOTICE] insert duplicate key\n");
    else if (n != KSUCCESS)
      kerror("aa tree insert error");
  }

  if (aa_tree_delete(aa, (void *) 30) != KSUCCESS)
    printf("aa tree delete error in 30\n");

  aa_tree_print(aa);
  aa_tree_destroy(aa);
}
Example #4
0
static void
test_string_aa()
{
  aa_tree_t  *aa;
  kstring_t  *s;
  int         i;
  int         n;
  char       *sa[] = {
    "hello",
    "world",
    "hj",
    "krt",
    "test",
    "10",
    "85",
    "15",
    "70",
    NULL
  };

  aa = aa_tree_init(&g_string_op);
  if (aa == NULL)
    kerror("init aa tree error");

  for (i = 0; sa[i] != NULL; ++i) {
    s = kstring_new((unsigned char *) sa[i], strlen(sa[i]));
    if (s == NULL)
      kerror("malloc string_t error");

    n = aa_tree_insert(aa, (void *) s);
    if (n == KEEXIST)
      printf("[NOTICE] insert duplicate key\n");
    else if (n != KSUCCESS)
      kerror("aa tree insert [%s] error", sa[i]);
  }

  if (aa_tree_delete(aa, s) != KSUCCESS)
    kerror("aa tree delete error");
  aa_tree_print(aa);
  aa_tree_destroy(aa);
}
Example #5
0
void test_aa_tree_remove_3(void) {

    char mem[aa_tree_size];

    struct aa_tree *t = aa_tree_create( sizeof(mem)
                                      , mem
                                      , sizeof(uint32_t)
                                      , __u32_cmp
                                      , __u32_cpy
                                      , 0
                                      , __alloc
                                      , __dealloc
                                      );

    uint32_t v[] = { 4,10,2,6,12,3,1,8,13,11,5,9,7 };
    size_t i = 0;

    for(; i < sizeof(v)/sizeof(v[0]); i++ ) {
        aa_tree_insert(t, &v[i]);
    }

    __print_u32_digraph(t, "G");
    fprintf(stdout, "\n");

    uint32_t rm[] = { 1, 5 };

    for(i = 0; i < sizeof(rm)/sizeof(rm[0]); i++ ) {
        char tmp[16];
        snprintf(tmp, sizeof(tmp), "G%d", (int)i);
        fprintf(stdout, "// remove %u\n", rm[i]);
        aa_tree_remove(t, &rm[i]);
        __print_u32_digraph(t, tmp);
        fprintf(stdout, "\n");
    }

    aa_tree_destroy(t,0,0);
}
Example #6
0
void test_aa_tree_remove_2(void) {

    char mem[aa_tree_size];

    struct aa_tree *t = aa_tree_create( sizeof(mem)
                                      , mem
                                      , sizeof(uint32_t)
                                      , __u32_cmp
                                      , __u32_cpy
                                      , 0
                                      , __alloc
                                      , __dealloc
                                      );

    uint32_t v[] = { 50, 40, 100, 45, 20, 47, 15, 30, 25, 37, 27, 90 };
    size_t i = 0;

    for(; i < sizeof(v)/sizeof(v[0]); i++ ) {
        aa_tree_insert(t, &v[i]);
    }

    __print_u32_digraph(t, "G");
    fprintf(stdout, "\n");

    uint32_t rm[] = { 90, 20, 45, 30, 40  };

    for(i = 0; i < sizeof(rm)/sizeof(rm[0]); i++ ) {
        char tmp[16];
        snprintf(tmp, sizeof(tmp), "G%d", (int)i);
        fprintf(stdout, "// remove %u\n", rm[i]);
        aa_tree_remove(t, &rm[i]);
        __print_u32_digraph(t, tmp);
        fprintf(stdout, "\n");
    }

    aa_tree_destroy(t,0,0);
}
Example #7
0
void test_aa_tree_clinical_1(void) {

    ranctx rctx;
    raninit(&rctx, 0xDEADBEEF);

    char mem[aa_tree_size];

    fprintf(stdout, "clinical case\n");

    struct aa_tree *t = aa_tree_create( sizeof(mem)
                                      , mem
                                      , sizeof(uint32_t)
                                      , __u32_cmp_stat
                                      , __u32_cpy
                                      , 0
                                      , __alloc
                                      , __dealloc
                                      );

    const size_t N = 10000;
    size_t i = 0;

    size_t cn = 0;

    for(; i < N; i++ ) {
        uint32_t tmp = i;

        __cmp_num = 0;

        aa_tree_insert(t, &tmp);

        cn = __cmp_num > cn ? __cmp_num : cn;
    }

    fprintf( stdout
           , "inserted %zu, max. cmp: %zu ops\n"
           , i
           , cn );


    cn = 0;

    size_t found = 0;
    for(i = 0; i < N; i++ ) {
        uint32_t tmp = ranval(&rctx) % N;

        __cmp_num = 0;

        if( aa_tree_find(t, &tmp) ) {
            found++;
        }

        cn = __cmp_num > cn ? __cmp_num : cn;

    }

    fprintf( stdout
           , "found %zu of %zu, max. cmp: %zu ops\n"
           , found
           , i
           , cn );

    aa_tree_destroy(t,0,0);
}