示例#1
0
文件: zad1.cpp 项目: mariuswol/polsl
int main(int argc, char *argv[]) {
	std::ifstream in_english("english.dic", std::ifstream::in);
	std::ifstream in_polish("polish.dic", std::ifstream::in);
	std::istream_iterator<std::string> in_iter_english(in_english), in_iter_polish(in_polish), eos;
	std::vector<std::string> lines_english(in_iter_english, eos);
	std::vector<std::string> lines_polish(in_iter_polish, eos);

	srand(unsigned(time(0)));
	std::random_shuffle(lines_english.begin(), lines_english.end());
	std::random_shuffle(lines_polish.begin(), lines_polish.end());

	std::set<std::string> set_polish, set_english;
	std::unordered_set<std::string> uset_polish, uset_english;
	
	std::cout << "English to std::set " << insert_time(set_english, lines_english.begin(), lines_english.end()) << "s\n";
	std::cout << "Polish to std::set " << insert_time(set_polish, lines_polish.begin(), lines_polish.end()) << "s\n";
	std::cout << "English to std::unordered_set " << insert_time(uset_english, lines_english.begin(), lines_english.end()) << "s\n";
	std::cout << "Polish to std::unordered_set " << insert_time(uset_polish, lines_polish.begin(), lines_polish.end()) << "s\n";

	std::cout << "English searching in std::set " << search_time(set_english, lines_english) << "s\n";
	std::cout << "Polish searching in std::set " << search_time(set_polish, lines_polish) << "s\n";
	std::cout << "English searching in std::unordered_set " << search_time(uset_english, lines_english) << "s\n";
	std::cout << "Polish searching in std::unordered_set " << search_time(uset_polish, lines_polish) << "s\n";

	float slices[] = {0.05, 0.1, 0.2, 0.4, 0.7, 1};
	std::vector<std::string> test_lines;

	for(float ratio : slices)
	{
		test_lines.insert(test_lines.end(), lines_polish.begin(), lines_polish.begin()+(int)round(lines_polish.size()*ratio));
		std::cout << "Polish searching in std::set for ratio " << ratio << " " << search_time(set_polish, test_lines) << "s\n";
		std::cout << "Polish searching in std::unordered_set for ratio " << ratio << " " << search_time(uset_polish, test_lines) << "s\n";
		test_lines.clear();
	}

	return 0; //Huge success!
}
示例#2
0
/**
 * log_msg - Write log message into lp_diag log file
 *
 * @fmt	format string to printf()
 * @...	additional argument
 */
void
log_msg(const char *fmt, ...)
{
	int	rc;
	int     len = 0;
	char    buf[LP_ERROR_LOG_MAX];
	va_list ap;

#ifndef LPD_DEBUG
	/* In order to make testing easier we will not print time in
	 * debug version of lp_diag.
	 */
	if (lp_error_log_fd != STDOUT_FILENO) {
		len = insert_time(buf, LP_ERROR_LOG_MAX);
		len += snprintf(buf + len, LP_ERROR_LOG_MAX - len, ": ");
	}
#endif

	/* Add the actual message */
	va_start(ap, fmt);
	len += vsnprintf(buf + len, LP_ERROR_LOG_MAX - len, fmt, ap);
	if (len < 0 || len >= LP_ERROR_LOG_MAX) {
		dbg("Insufficient buffer size");
		va_end(ap);
		return;
	}
	va_end(ap);

	/* Add ending punctuation */
	len += snprintf(buf + len, LP_ERROR_LOG_MAX - len, ".");

	if (lp_error_log_fd == -1) {
		dbg("Log file \"%s\" is not available", lp_error_log_file);
		_dbg(buf);
		return;
	}

	_dbg(buf);

	/* reformat the new message */
	len = reformat_msg(buf, LP_ERROR_LOG_MAX);
	rc = write(lp_error_log_fd, buf, len);
	if (rc == -1)
		dbg("Write to log file \"%s\" failed", lp_error_log_file);
}
示例#3
0
/**
 * indicator_log_write - write indicate events to log file
 *
 * @fmt	format string to printf()
 * @...	additional argument to printf()
 *
 * Returns :
 *	return code from write() call
 */
int
indicator_log_write(const char *fmt, ...)
{
	int	len;
	int	rc = 0;
	char    buf[LP_ERROR_LOG_MAX];
	va_list ap;

	if (lp_event_log_fd == -1) {
		log_msg("Indicator event log file \"%s\" is not available",
			lp_event_log_file);
		return -1;
	}

	/* Add time */
	len = insert_time(buf, LP_ERROR_LOG_MAX);

	len += snprintf(buf + len, LP_ERROR_LOG_MAX - len, ": %s : ",
			program_name);

	va_start(ap, fmt);
	len += vsnprintf(buf + len, LP_ERROR_LOG_MAX - len, fmt, ap);
	if (len < 0 || len >= LP_ERROR_LOG_MAX) {
		log_msg("Insufficient buffer size");
		va_end(ap);
		return -1;
	}
	va_end(ap);

	/* Add ending punctuation */
	len += snprintf(buf + len, LP_ERROR_LOG_MAX - len, "\n");

	rc = write(lp_event_log_fd, buf, len);
	if (rc == -1)
		log_msg("Write to indicator event log file \"%s\" failed",
			lp_event_log_file);

	return rc;
}
示例#4
0
文件: interface.c 项目: dimkr/beaver
void menu_items_treatment (GtkWidget *Widget, guint Op)
{
  gint CurrentPage, i;

  CurrentPage = gtk_notebook_get_current_page (GTK_NOTEBOOK(MainNotebook));
  switch(Op)
    {
    case NEW                  : new_file ();                   break;
    case OPEN                 : open_file ();                  break;
    case SAVE                 : save_file ();                  break;
    case SAVE_ALL             : save_all ();                   break;
    case SAVE_AS              : save_file_as ();               break;
    case PRINT                : print_buffer ();               break;
    case CLOSE                : close_file ();                 break;
    case CLOSE_ALL            : close_all ();                  break;
    case QUIT                 : quit ();                       break;
    case UNDO                 :
      if (OpenedFilesCnt)
	{
	  proceed_undo ();
	  break;
	 } 
    case REDO                 :
      if (OpenedFilesCnt)
	{
	  proceed_redo ();
	  break;
	}
    case CUT                  :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  gtk_editable_cut_clipboard (GTK_EDITABLE(FPROPS(CurrentPage, Text)));
	  print_msg ("Selection cut to Clipboard...");
	}
      break;
    case COPY                 :
      if (OpenedFilesCnt)
	{
	  gtk_editable_copy_clipboard
	    (GTK_EDITABLE(FPROPS(CurrentPage, Text)));
	  print_msg ("Selection copied to Clipboard...");
	}
	break;
    case PASTE                :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  gtk_editable_paste_clipboard
	    (GTK_EDITABLE(FPROPS(CurrentPage, Text)));
	  print_msg ("Text pasted from Clipboard...");
	}
      break;
    case CLEAR                :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  gtk_editable_delete_text
	    (GTK_EDITABLE(FPROPS(CurrentPage, Text)), 0, -1);
	  print_msg ("Buffer cleared...");
	}
      break;
    case SELECT_ALL           :
      if (OpenedFilesCnt)
	{
	  gtk_editable_select_region
	    (GTK_EDITABLE(FPROPS(CurrentPage, Text)), 0, -1);
	  print_msg ("All Text selected...");
	}
      break;
    case COMPLETE             :
      if (OpenedFilesCnt)
	auto_completion (GTK_TEXT(FPROPS(CurrentPage, Text)));
      break;
    case FIND                 :
      if (OpenedFilesCnt)
	search (FALSE);
      break;
    case REPLACE              :
      if (OpenedFilesCnt)
	search (TRUE);
      break;
    case LINE                 :
      if (OpenedFilesCnt)
	goto_line ();
      break;
    case READONLY             : toggle_readonly ();            break;
    case CONVERTER            : converter ();                  break;
    case COLOR                : color_picker ();               break;
    case INSERT_TIME          : insert_time (CurrentPage);     break;
    case TO_UPPER             :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  change_case (1);
	  print_msg ("Selection converted to upper Case...");
	}
      break;
    case TO_LOWER             :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  change_case (2);
	  print_msg ("Selection converted to Lower Case...");
	}
      break;
    case CAPITALIZE           :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  change_case (3);
	  print_msg ("Selection Capitalized...");
	}
      break; 
    case INVERT_CASE          :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  change_case (4);
	  print_msg ("Case inverted...");
	}
      break;
    case UNIX_DOS             :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  conv_unix_to_dos ();
	}
      break;
    case UNIX_MAC             :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  conv_unix_to_mac ();
	}
      break;
    case DOS_UNIX             :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  conv_dos_to_unix ();
	}
      break;
    case DOS_MAC              :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  conv_dos_to_mac ();
	}
      break;
    case MAC_DOS              :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  conv_mac_to_dos ();
	}
      break;
    case MAC_UNIX             :
      if ((OpenedFilesCnt) && !FPROPS(CurrentPage, ReadOnly))
	{
	  conv_mac_to_unix ();
	}
      break;
    case UNIX_DOS_ALL             :
      convert_all(conv_unix_to_dos);
      break;
    case UNIX_MAC_ALL             :
      convert_all(conv_unix_to_mac);
      break;
    case DOS_UNIX_ALL             :
      convert_all(conv_dos_to_unix);
      break;
    case DOS_MAC_ALL              :
      convert_all(conv_dos_to_mac);
      break;
    case MAC_DOS_ALL              :
      convert_all(conv_mac_to_dos);
      break;
    case MAC_UNIX_ALL             :
      convert_all(conv_mac_to_unix);
      break;
    case FILE_INFO            : file_info (CurrentPage);       break;
    case TOOLBAR              :
      if ((!ToolBarToggleDisplay) && (TOOLBAR_DISPLAY))
	ToolBarToggleDisplay = TRUE;
      else
	{
	  if (TOOLBAR_DISPLAY)
	    {
	      TOOLBAR_DISPLAY = FALSE;
	      hide_toolbar ();
	      print_msg ("Hide Tool Bar...");
	    }
	  else
	    {
	      TOOLBAR_DISPLAY = TRUE;
	      show_toolbar ();
	      if (!ToolBarToggleDisplay) ToolBarToggleDisplay = TRUE;
	      print_msg ("Display Tool Bar...");
	    }
	}
      break;
    case MSGBAR               :
      if ((!MsgBarToggleDisplay) && (MSGBAR_DISPLAY))
	MsgBarToggleDisplay = TRUE;
      else
	{
	  if (MSGBAR_DISPLAY)
	    {
	      MSGBAR_DISPLAY = FALSE;
	      hide_msgbar ();
	    }
	  else
	    {
	      MSGBAR_DISPLAY = TRUE;
	      show_msgbar ();
	      if (!MsgBarToggleDisplay) MsgBarToggleDisplay = TRUE;
	      print_msg ("Display Msg Bar...");
	    }
	}
      break;
    case WORDWRAP        :
     if ((!ToggleWordwrap) && (TOGGLE_WORDWRAP))
	ToggleWordwrap = TRUE;
      else
	{
	  if (TOGGLE_WORDWRAP)
	    {
	      TOGGLE_WORDWRAP = FALSE;
	      for (i = 0; i < OpenedFilesCnt; i++)
		gtk_text_set_word_wrap (GTK_TEXT(FPROPS(CurrentPage, Text)),
					FALSE);
	      print_msg ("Wordwrap disabled...");
	    }
	  else
	    {
	      TOGGLE_WORDWRAP = TRUE;
	      for (i = 0; i < OpenedFilesCnt; i++)
		gtk_text_set_word_wrap (GTK_TEXT(FPROPS(CurrentPage, Text)),
					TRUE);
	      if (!ToggleWordwrap) ToggleWordwrap = TRUE;
	      print_msg ("Wordwrap enabled...");
	    }
	}
      break;
    case TAB_POS_TOP          :
      TAB_POSITION = 1;
      gtk_notebook_set_tab_pos (GTK_NOTEBOOK(MainNotebook), GTK_POS_TOP);
      break;
    case TAB_POS_BOTTOM       :
      TAB_POSITION = 2;
      gtk_notebook_set_tab_pos (GTK_NOTEBOOK(MainNotebook), GTK_POS_BOTTOM);
      break;
    case TAB_POS_LEFT         :
      TAB_POSITION = 3;
      gtk_notebook_set_tab_pos (GTK_NOTEBOOK(MainNotebook), GTK_POS_LEFT);
      break;
    case TAB_POS_RIGHT        :
      TAB_POSITION = 4;
      gtk_notebook_set_tab_pos (GTK_NOTEBOOK(MainNotebook), GTK_POS_RIGHT);  
      break;
    case SCROLLBAR_POS_LEFT   :
      SCROLLBAR_POSITION = 1;
      for (i = 0; i < OpenedFilesCnt; i++)
	gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW
					   (gtk_notebook_get_nth_page
					    (GTK_NOTEBOOK(MainNotebook), i)),
					   GTK_CORNER_TOP_RIGHT);
      break;
    case SCROLLBAR_POS_RIGHT  :
      SCROLLBAR_POSITION = 2;
      for (i = 0; i < OpenedFilesCnt; i++)
	gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW
					   (gtk_notebook_get_nth_page
					    (GTK_NOTEBOOK(MainNotebook), i)),
					   GTK_CORNER_TOP_LEFT);
      break;
    case PREFS                : display_prefs (&Settings);     break;
    case HELP                 :
      print_msg ("No help available yet...");
      break;
    case ABOUT                : about ();                      break;
    }
  (void)Widget; /* avoid the "unused parameter" warning */
}