Exemplo n.º 1
0
/*!
 * @brief An entry point of this program
 * @return exit-status
 */
int main(void) {
  uint row, col;
  uint i;
  int **array, **t_array;
  printf("Number of ROW    = ?\b"); scanf("%u", &row);
  printf("Number of COLUMN = ?\b"); scanf("%u", &col);

  array   = alloc_2d_array(row, col);
  t_array = alloc_2d_array(col, row);
  if (array == NULL || t_array == NULL) {
    fputs("Memory allocation error!\n", stderr);
    return EXIT_FAILURE;
  }

  for (i = 0; i < row; i++) {
    uint j;
    for (j = 0; j < col; j++) {
      int tmp;
      scanf("%d", &tmp);
      array[i][j] = tmp;
    }
  }
  puts("");
  puts("Matrix = ");
  show_2d_array((const int *const *)array, row, col);
  puts("============================================================");

  transpose(t_array, (const int *const *)array, row, col);
  puts("Transposed Matrix = ");
  show_2d_array((const int *const *)t_array, col, row);

  free_2d_array(array, row);
  free_2d_array(t_array, row);
  return EXIT_SUCCESS;
}
Exemplo n.º 2
0
static int chunk_file_process(char *chunk_file, hashtable *htab, int which, int sim_algo, lcs_entry *le)
{
	int fd, i, ret = 0;
	ssize_t rwsize;
	chunk_file_header chunk_file_hdr;
	chunk_block_entry chunk_bentry;
	hash_entry *he = NULL;

	/* parse chunk file */
	fd = open(chunk_file, O_RDONLY);
	if (-1 == fd) {
		return -1;
	}

	rwsize = read(fd, &chunk_file_hdr, CHUNK_FILE_HEADER_SZ);
	if (rwsize != CHUNK_FILE_HEADER_SZ) {
		ret = -1;
		goto _CHUNK_FILE_PROCESS_EXIT;
	}

	if (sim_algo == LCS_YES) {
		le->str = alloc_2d_array(chunk_file_hdr.block_nr, MD5_LEN);
		if (le->str == NULL) {
			ret = -1;
			goto _CHUNK_FILE_PROCESS_EXIT;
		}
		le->len = chunk_file_hdr.block_nr;
	}

	for(i = 0; i < chunk_file_hdr.block_nr; i++) {
		rwsize = read(fd, &chunk_bentry, CHUNK_BLOCK_ENTRY_SZ);
		if (rwsize != CHUNK_BLOCK_ENTRY_SZ) {
			ret = -1;
			goto _CHUNK_FILE_PROCESS_EXIT;
		}

		he = (hash_entry *)hash_value((void *)chunk_bentry.md5, htab);
		if (he == NULL) {
			he = (hash_entry *)malloc(sizeof(hash_entry));
			he->nr1 = he->nr2 = 0;
			he->len = chunk_bentry.len;
		}
		(which == FILE1) ? he->nr1++ : he->nr2++;
		/* insert or update hash entry */
		hash_insert((void *)strdup(chunk_bentry.md5), (void *)he, htab);
		if (sim_algo == LCS_YES) {
			memcpy(le->str[i], chunk_bentry.md5, MD5_LEN);
		}
	}

_CHUNK_FILE_PROCESS_EXIT:
	close(fd);
	return ret;
}