Exemplo n.º 1
0
static void some_really_long_function_name(
    struct device *dev, struct device_driver *drv)
{
    if ((some_variable_name &&
         somefunction(param1, param2, param3))) {
        asdfghjk = asdfasdfasd.aasdfasd +
                   (asdfasd.asdas * 1234.65);
    }

    for (struct something_really_really_excessive *
         a_long_ptr_name = get_first_item();
         a_long_ptr_name != NULL;
         a_long_ptr_name = get_next_item(a_long_ptr_name))
    {
    }

    for (a = get_first(); a != NULL; a = get_next(a))
    {
    }

    for (a_ptr = get_first();
         a_ptr != NULL;
         a_ptr = get_next(a))
    {
    }

    register_clcmd(
        "examine", "do_examine", -1,
        "-Allows a player to examine the health and armor of a teammate" );
    register_clcmd(
        "/examine", "do_examine", -1,
        "-Allows a player to examine the health and armor of a teammate" );
}
Exemplo n.º 2
0
	bool   check_add_item(uint32_t item_id, uint32_t item_count)
	{
		item_data* p_data = item_data_mgr::get_instance()->get_item_data_by_id(item_id);
		item* p_item = 	get_first_item(item_id);

		int32_t remain_count = item_count;
		uint32_t need_grid_count = 0;
		if(p_item == NULL)
		{
			need_grid_count = item_count / p_data->max_heap_num_  + (item_count % p_data->max_heap_num_ ? 1:0 );
		}
		else
		{
			while(p_item)
			{
				uint32_t count = p_item->get_cur_remain_heap_count();
				remain_count -= count; 
				p_item = get_next_item(p_item);	
				if(remain_count < 0)
				{
					remain_count = 0;
					break;
				}
			}
			need_grid_count = remain_count / p_data->max_heap_num_  + (remain_count % p_data->max_heap_num_ ? 1:0 );
		}
		return need_grid_count >= get_empty_grid_count();
	}
int main (int argc, char **argv)
{
    program_options::option_desc opt_descs[] = {
        {{"hash-function", required_argument}, true, "UINT", "", "Which hash function to use"},
        {{"map-capacity", required_argument}, true, "ULONG", "", "Map table capacity"},
        {{0, 0, 0, 0}}
    };
    size_t num_opts = sizeof(opt_descs) / sizeof(program_options::option_desc);
    program_options::option_bag opts;
    program_options::get_option_bag(argc, argv, opt_descs, num_opts,  &opts);
    unsigned int hash_function_id;
    size_t map_capacity;
    opts.get_opt_val("hash-function", &hash_function_id);
    opts.get_opt_val("map-capacity", &map_capacity);
    switch (hash_function_id) {
    case 0:
        //primary hash function implemented in parts 1-4
        hash_functor::hash_function = &my_hash;
        break;
    case 1:
        //Dave's cat hash
        hash_functor::hash_function = &dave_hash_1::hash;
        break;
    case 2:
        //Paul Hsieh's SuperFastHash
        hash_functor::hash_function = &dave_hash_2::hash;
        break;
    case 3:
        //variation on Program 14.2 from the textbook
        hash_functor::hash_function = &dave_hash_3::hash;
        break;
    }
    /*
    for each key in test case's file
      compute the key's hash
      for each table capacity to be considered
        compute index from key for tables 
        increment count of keys hashing to that index for that table's capacity
    for each table capacity to be considered
      output the table's capacity
      for X = 1 to table size
        if at least one index has exactly X collisions
          output: X and the number of indices that has exactly X collisions
    this can all be handled with the generic bucket map's cluster_distribution function
    */
    cop3530::HashMapBucketsGeneric<std::string, bool, hash_functor> map(map_capacity);
    std::string key;
    while (std::cin >> key) {
        map.insert(key, true);
    }
    
    auto cluster_pq = map.cluster_distribution();
    while ( ! cluster_pq.empty()) {
        auto cluster_type = cluster_pq.get_next_item();
        std::cout << cluster_type.cluster_size << " " << cluster_type.num_instances << std::endl;
    }
    return 0;
}
Exemplo n.º 4
0
void
testOpAssign(void)
{
  t.a = 0;
  t.n = 0;

  /* get_next_item() should be called only once */
  get_next_item()->a |= 42;

  ASSERT (t.a == 42);
  ASSERT (t.n == 1);
}
Exemplo n.º 5
0
	bool add_item(uint32_t item_id, uint32_t item_count)
	{
		if( !check_add_item(item_id, item_count))return false;

		uint32_t remain_count = item_count;	

		item* p_item =  get_first_item(item_id);

		if(p_item == NULL)
		{
			return add_item_to_empty_grid(item_id, item_count);
		}
		else
		{
			while(p_item)
			{
				uint32_t remain_heap_count = p_item->get_cur_remain_heap_count();
				if(remain_heap_count == 0)continue;
				
				if(remain_heap_count <= remain_count)
				{
					p_item->inc_cur_heap_count( remain_heap_count);	
					remain_count -= remain_heap_count;
				}
				else
				{
					p_item->inc_cur_heap_count(remain_count);	
					remain_count = 0;
					break;
				}	
				p_item = get_next_item(p_item);
			}
			if(remain_count > 0)
			{
				return add_item_to_empty_grid(item_id, remain_count);
			}	
		}
		return true;	
	}
Exemplo n.º 6
0
/* Dissector for xcsl */
static void dissect_xcsl_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {

   guint        offset = 0;
   gint         length_remaining;
   guint8       idx;
   gboolean     request;
   guint8       par;
   guint8       str[MAXLEN];
   guint8       result;
   const gchar *code;
   guint        len;
   gint         next_offset;
   proto_item  *xcsl_item = NULL;
   proto_tree  *xcsl_tree = NULL;

   /* color support */
   col_set_str(pinfo->cinfo, COL_PROTOCOL, "Xcsl");
   col_clear(pinfo->cinfo, COL_INFO);

   /* Create display tree for the xcsl protocol */
   if (tree) {
       xcsl_item = proto_tree_add_item(tree, proto_xcsl,tvb, offset, -1, FALSE);
       xcsl_tree = proto_item_add_subtree(xcsl_item, ett_xcsl);
   }

   /* reset idx */
   idx = 0;

   /* reset the parameter count */
   par = 0;

   /* switch whether it concerns a command or an answer */
   request = FALSE;

   while (tvb_reported_length_remaining(tvb, offset) != 0) {

      length_remaining = tvb_ensure_length_remaining(tvb, offset);
      if ( length_remaining == -1 ) {
         return;
      }

      /* get next item */
      if (!(get_next_item(tvb, offset, length_remaining, str, &next_offset, &len))) {
        /* do not continue when get_next_item returns false */
        return;
      }

      /* do not add to the tree when the string is of zero length */
      if ( strlen(str) == 0 ) {
         offset = next_offset + 1;
         continue;
      }

      /* Xcsl (Call Specification Language) protocol in brief :
       *
       * Request :
       *
       *    <xcsl-version>;<transaction-id>;<command>;[parameter1;parameter2;parameter3;....]
       *
       * Reply :
       *
       *    <xcsl-version>;transaction-id;<result>;[answer data;answer data];...
       *
       * If result is one or more digits, this is determined as a Reply.
       *
       * Example :
       *
       * -->      xcsl-1.0;1000;offhook;+31356871234
       * <--      xcsl-1.0;1000;0                              <- success
       *
       * -->      xcsl-1.0;1001;dial;+31356871234;+31356875678
       * <--      xcsl-1.0;1001;0                              <- success
       *
       *
       * index :  0        1    2    3            4
       *
       * Index 2 represents the return code (see the xcsl_action_vals[] definitions)
       *
       */

      /* One by one go through each item ';' separated */
      switch (idx) {

                    /* This is the protocol item */
          case 0:   proto_tree_add_item(tree, hf_xcsl_protocol_version, tvb, offset, len, FALSE);
                    break;

                    /* This should be the transaction ID, if non-digit, it is treated as info */
          case 1:   if ( isdigit(str[0]) ) {
                          proto_tree_add_item(tree, hf_xcsl_transaction_id, tvb, offset, len, FALSE);
                    } else {
                          proto_tree_add_item(tree, hf_xcsl_information, tvb, offset, len, FALSE);
                    }
                    if (check_col(pinfo->cinfo, COL_INFO))
                       col_append_fstr(pinfo->cinfo, COL_INFO, "%s ",str);
                    break;

                    /* Starting with non-digit -> Command, if it starts with a digit -> reply */
          case 2:   if ( isdigit(str[0]) ) {

                      request = FALSE;
                      result = atoi(str);
                      if ( result >= XCSL_NONE ) {
                         result = XCSL_UNDEFINED;
                      }
                      code = match_strval(result, xcsl_action_vals);

                      /* Print result code and description */
                      xcsl_item = proto_tree_add_item(tree, hf_xcsl_result, tvb, offset, len, FALSE);
                      proto_item_append_text(xcsl_item, " (%s)", code);

                      if (result != 0 && check_col(pinfo->cinfo, COL_INFO))
                         col_append_fstr(pinfo->cinfo, COL_INFO, "[%s] ", code);

                    } else {

                      request = TRUE;
                      proto_tree_add_item(tree, hf_xcsl_command, tvb, offset, len, FALSE);

                      if (check_col(pinfo->cinfo, COL_INFO))
                         col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", str);

                    }
                    break;

                    /* This is a command parameter */
          default:  proto_tree_add_item(tree, hf_xcsl_parameter, tvb, offset, len, FALSE);

                    if (check_col(pinfo->cinfo, COL_INFO)) {
                       if ( request == TRUE ) {
                          col_append_fstr(pinfo->cinfo, COL_INFO, ": %s ",str);
                       } else {
                          if (par == 0) {
                             col_append_fstr(pinfo->cinfo, COL_INFO, "reply: %s ",str);
                          } else {
                             col_append_fstr(pinfo->cinfo, COL_INFO, ": %s ",str);
                          }
                       }
                    }

                    /* increment the parameter count */
                    par++;

                    break;
      }

      offset = next_offset + 1;
      idx++;

   }


   return;
}