Esempio n. 1
0
File: RTST.c Progetto: atbrox/ctst
static VALUE rtst_memory_usage(VALUE self) {
  ctst_ctst *ctst;
  Data_Get_Struct(
    self,
    ctst_ctst,
    ctst
  );
  
  return INT2NUM(ctst_get_memory_usage(ctst));
}
Esempio n. 2
0
int main(int argc, char** argv) {
  ctst_ctst* ctst = ctst_alloc();
  ctst_data data;

  data = ctst_set(ctst,"The answer to your question is",0,30,42);
  printf("%*s %d (was %d)\n",30,"The answer to your question is",ctst_get(ctst,"The answer to your question is",0,30),data);
  
  data = ctst_set(ctst,"Hello, world!",0,13,57);
  printf("%*s %d (was %d)\n",13,"Hello, world!",ctst_get(ctst,"Hello, world!",0,13),data);

  data = ctst_set(ctst,"Hello, world!",0,13,62);
  printf("%*s %d (was %d)\n",13,"Hello, world!",ctst_get(ctst,"Hello, world!",0,13),data);

  data = ctst_set(ctst,"The answer to your question is",0,30,11);
  printf("%*s %d (was %d)\n",30,"The answer to your question is",ctst_get(ctst,"The answer to your question is",0,30),data);

  data = ctst_set(ctst,"There is something rotten in the kingdom of Denmark",0,51,1122);

  printf("DUMP OF THE TREE\n");
  ctst_visit_all(ctst, &printer_visitor, 0);
  printf("END DUMP OF THE TREE\n");

  printf("DUMP OF THE TREE, only H*\n");
  ctst_visit_all_from_key(ctst, &printer_visitor, 0, "**Hello", 2, 1);
  printf("END DUMP OF THE TREE\n");

  printf("DUMP OF THE TREE, only The*\n");
  ctst_visit_all_from_key(ctst, &printer_visitor, 0, "The", 0, 3);
  printf("END DUMP OF THE TREE\n");

  printf("DUMP OF THE TREE, only There*\n");
  ctst_visit_all_from_key(ctst, &printer_visitor, 0, "--There", 2, 5);
  printf("END DUMP OF THE TREE\n");

  printf("Number of entries: %d\nTotal length of keys: %d\nTotal node count: %d\nMemory usage: %d\nRatio: %f\n",
    ctst_get_size(ctst),
    ctst_get_total_key_length(ctst),
    ctst_get_node_count(ctst),
    ctst_get_memory_usage(ctst),
    ctst_get_ratio(ctst)
  );

  printf("Removing a key\n");
  data = ctst_remove(ctst,"Hello, world!",0,13);
  printf("%*s %d (was %d)\n",13,"Hello, world!",ctst_get(ctst,"Hello, world!",0,13),data);

  printf("Number of entries: %d\nTotal length of keys: %d\nTotal node count: %d\nMemory usage: %d\nRatio: %f\n",
    ctst_get_size(ctst),
    ctst_get_total_key_length(ctst),
    ctst_get_node_count(ctst),
    ctst_get_memory_usage(ctst),
    ctst_get_ratio(ctst)
  );

  printf("DUMP OF THE TREE\n");
  ctst_visit_all(ctst, &printer_visitor, 0);
  printf("END DUMP OF THE TREE\n");

  printf("LOAD TEST\n");
  
  load_test(ctst);

  printf("DUMP OF THE TREE\n");
  ctst_visit_all(ctst, &printer_visitor, 0);
  printf("END DUMP OF THE TREE\n");
  
  printf("Number of entries: %d\nTotal length of keys: %d\nTotal node count: %d\nMemory usage: %d\nRatio: %f\n",
    ctst_get_size(ctst),
    ctst_get_total_key_length(ctst),
    ctst_get_node_count(ctst),
    ctst_get_memory_usage(ctst),
    ctst_get_ratio(ctst)
  );

  ctst_free(ctst);  
  
  return 0;
}