コード例 #1
0
ファイル: cubesTable.c プロジェクト: lonbon7/cpe101
int main(void)
{
    int table_size;
    int first;
    int increment;

    /* loop until sentinel is reached */
    table_size = get_table_size();
    while (table_size != 0)
    {
        first = get_first();
        increment = get_increment();
        show_table(table_size, first, increment);
        table_size = get_table_size();
    }
    return 0;
}
コード例 #2
0
ファイル: FullZone.cpp プロジェクト: mpoquet/simgrid
FullZone::~FullZone()
{
  if (routing_table_) {
    unsigned int table_size = get_table_size();
    /* Delete routing table */
    for (unsigned int i = 0; i < table_size; i++)
      for (unsigned int j = 0; j < table_size; j++)
        delete TO_ROUTE_FULL(i, j);
    delete[] routing_table_;
  }
}
コード例 #3
0
ファイル: FullZone.cpp プロジェクト: mpoquet/simgrid
void FullZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* res, double* lat)
{
  XBT_DEBUG("full getLocalRoute from %s[%u] to %s[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id());

  unsigned int table_size        = get_table_size();
  RouteCreationArgs* e_route     = TO_ROUTE_FULL(src->id(), dst->id());

  if (e_route != nullptr) {
    res->gw_src = e_route->gw_src;
    res->gw_dst = e_route->gw_dst;
    for (auto const& link : e_route->link_list) {
      res->link_list.push_back(link);
      if (lat)
        *lat += link->get_latency();
    }
  }
}
コード例 #4
0
ファイル: public01.c プロジェクト: b3jh24/Coding-Samples
int main() {
   Table *table_ptr;
   int x, y, table_size = 5;
   void *value;

   /***** Starting memory checking *****/
   start_memory_check();
   /***** Starting memory checking *****/

   create_table(&table_ptr, table_size, NULL);
   x = 2;
   put(table_ptr, "Peggy", &x);
   y = 1;
   put(table_ptr, "John", &y);

   printf("Table size: %d\n", get_table_size(table_ptr));
   if (is_empty(table_ptr)) {
      printf("Empty table\n");
   } else {
      printf("Not empty\n");
   }
   get_value(table_ptr, "John", &value);
   printf("Value for John %d\n", *(int *) value);

   printf("Removing Peggy: %d\n", remove_entry(table_ptr, "Peggy"));
   printf("Displaying Table\n");
   display_table(table_ptr);

   clear_table(table_ptr);
   printf("After clearing\n");
   if (is_empty(table_ptr)) {
      printf("Empty table\n");
   } else {
      printf("Not empty\n");
   }
   printf("Displaying Table\n");
   display_table(table_ptr);

   destroy_table(table_ptr);

   /****** Gathering memory checking info *****/
   stop_memory_check();
   /****** Gathering memory checking info *****/

   return 0;
}
コード例 #5
0
ファイル: assembly.c プロジェクト: hoangduit/reactos
static HRESULT parse_clr_tables(ASSEMBLY *assembly, ULONG offset)
{
    DWORD i, count;
    ULONG currofs;
    ULONGLONG mask;

    currofs = offset;
    assembly->tableshdr = assembly_data_offset(assembly, currofs);
    if (!assembly->tableshdr)
        return E_FAIL;

    assembly->stringsz = (assembly->tableshdr->HeapOffsetSizes & MD_STRINGS_BIT) ?
                         sizeof(DWORD) : sizeof(WORD);
    assembly->guidsz = (assembly->tableshdr->HeapOffsetSizes & MD_GUIDS_BIT) ?
                       sizeof(DWORD) : sizeof(WORD);
    assembly->blobsz = (assembly->tableshdr->HeapOffsetSizes & MD_BLOBS_BIT) ?
                       sizeof(DWORD) : sizeof(WORD);

    currofs += sizeof(METADATATABLESHDR);
    assembly->numrows = assembly_data_offset(assembly, currofs);
    if (!assembly->numrows)
        return E_FAIL;

    memset(assembly->tables, -1, MAX_CLR_TABLES * sizeof(CLRTABLE));

    for (i = count = 0, mask = 1; i < MAX_CLR_TABLES; i++, mask <<= 1)
    {
        if (assembly->tableshdr->MaskValid.QuadPart & mask)
            assembly->tables[i].rows = assembly->numrows[count++];
    }
    assembly->numtables = count;
    currofs += assembly->numtables * sizeof(DWORD);

    for (i = 0, mask = 1; i < MAX_CLR_TABLES; i++, mask <<= 1)
    {
        if (assembly->tableshdr->MaskValid.QuadPart & mask)
        {
            assembly->tables[i].offset = currofs;
            currofs += get_table_size(assembly, i) * assembly->tables[i].rows;
        }
    }

    return S_OK;
}
コード例 #6
0
ファイル: FullZone.cpp プロジェクト: mpoquet/simgrid
void FullZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
                         std::vector<resource::LinkImpl*>& link_list, bool symmetrical)
{
  addRouteCheckParams(src, dst, gw_src, gw_dst, link_list, symmetrical);

  unsigned int table_size = get_table_size();

  if (not routing_table_)
    routing_table_ = new RouteCreationArgs*[table_size * table_size]();

  /* Check that the route does not already exist */
  if (gw_dst) // inter-zone route (to adapt the error message, if any)
    xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
               "The route between %s@%s and %s@%s already exists (Rq: routes are symmetrical by default).",
               src->get_cname(), gw_src->get_cname(), dst->get_cname(), gw_dst->get_cname());
  else
    xbt_assert(nullptr == TO_ROUTE_FULL(src->id(), dst->id()),
               "The route between %s and %s already exists (Rq: routes are symmetrical by default).", src->get_cname(),
               dst->get_cname());

  /* Add the route to the base */
  TO_ROUTE_FULL(src->id(), dst->id()) =
      newExtendedRoute(hierarchy_, src, dst, gw_src, gw_dst, link_list, symmetrical, true);

  if (symmetrical == true && src != dst) {
    if (gw_dst && gw_src) {
      NetPoint* gw_tmp = gw_src;
      gw_src           = gw_dst;
      gw_dst           = gw_tmp;
    }
    if (gw_dst && gw_src) // inter-zone route (to adapt the error message, if any)
      xbt_assert(
          nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
          "The route between %s@%s and %s@%s already exists. You should not declare the reverse path as symmetrical.",
          dst->get_cname(), gw_dst->get_cname(), src->get_cname(), gw_src->get_cname());
    else
      xbt_assert(nullptr == TO_ROUTE_FULL(dst->id(), src->id()),
                 "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.",
                 dst->get_cname(), src->get_cname());

    TO_ROUTE_FULL(dst->id(), src->id()) =
        newExtendedRoute(hierarchy_, src, dst, gw_src, gw_dst, link_list, symmetrical, false);
  }
}
コード例 #7
0
ファイル: FullZone.cpp プロジェクト: mpoquet/simgrid
void FullZone::seal()
{
  unsigned int table_size = get_table_size();

  /* Create table if needed */
  if (not routing_table_)
    routing_table_ = new RouteCreationArgs*[table_size * table_size]();

  /* Add the loopback if needed */
  if (surf_network_model->loopback_ && hierarchy_ == RoutingMode::base) {
    for (unsigned int i = 0; i < table_size; i++) {
      RouteCreationArgs* e_route = TO_ROUTE_FULL(i, i);
      if (not e_route) {
        e_route = new RouteCreationArgs();
        e_route->link_list.push_back(surf_network_model->loopback_);
        TO_ROUTE_FULL(i, i) = e_route;
      }
    }
  }
}
コード例 #8
0
/*Tests creating a table, placing key/value pairs in it, getting values from the table,
 clearing the entire table, then reinserting some key/value pairs and getting 
 their values. Also tests get_table_size */
static int test2() {
   int table_size = 4, x = 1, y = 3, z = 4, w = 5,
   a = 10, b = 2, c = 7, d = 8, e = 9, f = 12, g = 13;
   Table *t;
   void *value1, *value2, *value3, *value4, *value5, *value6,
    *value7, *value8, *value9, *value10, *value11;

   create_table(&t, table_size, NULL);
   /*Insert 4 keys into the table.*/
   put(t, "Spongebob", &x);
   put(t, "Patrick", &y);
   put(t, "Squidward", &z);
   put(t, "Sandy", &w);
   /*Check that each key has the correct value, and that get_value is
   operating correctly.*/
   get_value(t, "Spongebob", &value1);
   get_value(t, "Patrick", &value2);
   get_value(t, "Squidward", &value3);
   get_value(t, "Sandy", &value4);
   printf("Value for Spongebob: %d\n", *(int *) value1);
   printf("Value for Patrick: %d\n", *(int *) value2);
   printf("Value for Squidward: %d\n", *(int *) value3);
   printf("Value for Sandy: %d\n", *(int *) value4);
   printf("\n");
   /*Check the State of the entire table.*/
   display_table(t);
   /*Clear the entire table.*/
   clear_table(t);
   /*Check that get_table_size and get_key_count are workign correctly.*/
   if(get_table_size(t) != 4 || get_key_count(t) != 0){
      return FAILURE;
   }
   /*Make sure the table is empty.*/
   display_table(t);
   /*Reinsert 7 keys.*/
   put(t, "Krabs", &a);
   put(t, "Larry", &b);
   put(t, "Herminator", &c);
   put(t, "Brian", &d);
   put(t, "Steve", &e);
   put(t, "Nelson", &f);
   put(t, "Corwin", &g);
   /*Check that these keys have the correct values associated witht hem.*/
   get_value(t, "Krabs", &value5);
   get_value(t, "Larry", &value6);
   get_value(t, "Herminator", &value7);
   get_value(t, "Brian", &value8);
   get_value(t, "Steve", &value9);
   get_value(t, "Nelson", &value10);
   get_value(t, "Corwin", &value11);
   printf("Value for Krabs: %d\n", *(int *) value5);
   printf("Value for Larry: %d\n", *(int *) value6);
   printf("Value for Herminator: %d\n", *(int *) value7);
   printf("Value for Brian: %d\n", *(int *) value8);
   printf("Value for Steve: %d\n", *(int *) value9);
   printf("Value for Nelson: %d\n", *(int *) value10);
   printf("Value for Corwin: %d\n", *(int *) value11);
   /*Check the state of the entire table, especially to see if any keys from 
   before clear_table was called are left over. */
   display_table(t);
   printf("\n\n");

   destroy_table(t);
   return SUCCESS;
}
コード例 #9
0
/*Tests null and failure cases for create_table, destroy_table, put, get_value,
get_key_count*/
static int test3(){
   int table_size =5, x =5;
   Table *t, *p;
   void *value1, *value2, *value3 = NULL;
   /*Tests NULL cases for create_table.*/
   if(create_table(NULL, table_size, NULL ) != -1){
      return FAILURE;
   }else if(create_table(&t, 0, NULL) != -1){
      return FAILURE;
   }/*Tests NULL case for destroy_table.*/
    if (destroy_table(NULL) != -1){
      return FAILURE;
   }/*Tests NULL cases for put.*/
   if (put(NULL, "Krabs", &x) != -1){
      return FAILURE;
   }else if (put(t, NULL, &x) != -1){
      return FAILURE;
   }
   /*Creates one empty table, and one table with two keys.*/
   create_table(&t, table_size, NULL);
   create_table(&p, table_size, NULL);
   put(t, "Art thou feeling it now,", NULL);
   put(t, "Mr. Krabs?", &x);
   /*Tests NULL and FAILURE cases for get_value.*/
   if(get_value(NULL, "Mr. Krabs?", &value1) != -1){
      return FAILURE;
   } else if(get_value(t, NULL, &value1) != -1){
      return FAILURE;
   } else if(get_value(t, "Spongebob", &value1) != -1){
      return FAILURE;
   }
   /*Tests get_value for cases where the value stored is NULL and where the input
   parameter value is NULL. */
   get_value(t, "Mr. Krabs?", &value1);
   get_value(t, "Art thou feeling it now,", &value2);
   get_value(t, "Mr. Krabs?", &value3);
   if(value2 != NULL){
      return FAILURE;
   }
   printf("How much is Mr. Krabs feeling it: %d/10\n", *(int *) value1);
   printf("Key Count: %d\n", get_key_count(t));
   /*Tests NULL case for get_key_count.*/
   if(get_key_count(NULL) != -1){
      return FAILURE;
   } /*Tests NULL and FAILURE cases for remove_entry.*/
   if(remove_entry(NULL, "Mr. Krabs?") != -1){
      return FAILURE;
   } else if (remove_entry(t, NULL) != -1){
      return FAILURE;
   } else if (remove_entry(t, "Brian") != -1){
      return FAILURE;
   } /*Tests NULL case for clear_table. */
   if (clear_table(NULL) != -1){
      return FAILURE;
   } /*Tests is_empty with NULL, empty, and non-empty table.*/
   if (is_empty(t) != 0 || is_empty(NULL) != 1 || is_empty(p) != 1){
      return FAILURE;
   } /*Tests NULL case of get_table_size.*/
   if(get_table_size(NULL) != -1){
      return FAILURE;
   }

   destroy_table(t);
   destroy_table(p);
   return SUCCESS;
}