Ejemplo n.º 1
0
    int minArea(vector<vector<char>>& image, int x, int y) {
        if(image.empty() || image[0].empty()) return 0;
        int n = image.size();
        int m = image[0].size();
        int up;
        int down;
        int left;
        int right;

        int b1 = 0;
        int b2 = x;
        while(b1 < b2) {
            int mid = b1 + (b2 - b1) / 2;
            if(emptyRow(image, mid)) {
                b1 = mid + 1;
            } else {
                b2 = mid;
            }
        }
        up = b1;

        b1 = x;
        b2 = n - 1;
        while(b1 < b2) {
            int mid = b1 + (b2 - b1 + 1) / 2;
            if(emptyRow(image, mid)) {
                b2 = mid - 1;
            } else {
                b1 = mid;
            }
        }
        down = b1;

        b1 = 0;
        b2 = y;
        while(b1 < b2) {
            int mid = b1 + (b2 - b1) / 2;
            if(emptyCol(image, mid)) {
                b1 = mid + 1;
            } else {
                b2 = mid;
            }
        }
        left = b1;

        b1 = y;
        b2 = m - 1;
        while(b1 < b2) {
            int mid = b1 + (b2 - b1 + 1) / 2;
            if(emptyCol(image, mid)) {
                b2 = mid - 1;
            } else {
                b1 = mid;
            }
        }
        right = b1;

        return (down - up + 1) * (right - left + 1);
    }
Ejemplo n.º 2
0
 // This function sticks the entire table into a character buffer.
 // Note that the buffer is likely to be reused if you call the
 // function again, and it will also be invalidated if you free the
 // table. If size is not NULL, it will be filled with the size of
 // the ASCII table in bytes (not including the terminating NUL) 
 // All blank rows are removed from the returned string
char *NcrackOutputTable::printableTable(int *size) {
  unsigned int col, row;
  int p = 0; /* The offset into tableout */
  int clen = 0;
  int i;
  struct NcrackOutputTableCell *cell;
  int validthisrow;

  if (tableoutsz == 0) {
    tableoutsz = 512; /* Start us off with half a k */
    tableout = (char *) safe_malloc(tableoutsz);
  }

  for(row = 0; row < numRows; row++) {
    validthisrow = 0;

    if(emptyRow(row)) 
	continue;

    cell = getCellAddy(row, 0);
    if(cell->fullrow && cell->strlength > 0) {
      /* Full rows are easy, just make sure we have the space + \n\0 */
      if (cell->strlength + p + 2 > tableoutsz) {
	tableoutsz = (cell->strlength + p + 2) * 2;
	tableout = (char *) safe_realloc(tableout, tableoutsz);
      }
      memcpy(tableout + p, cell->str,  cell->strlength);
      p += cell->strlength;
    } else {
      for(col = 0; col < numColumns; col++) {
        cell = getCellAddy(row, col);
        clen = maxColLen[col];
	/* Cells get padded with an extra space + \n\0 */
	if (clen + p + 3 > tableoutsz) {
	  tableoutsz = (cell->strlength + p + 2) * 2;
	  tableout = (char *) safe_realloc(tableout, tableoutsz);
	}
        if (cell->strlength > 0) {
          memcpy(tableout + p, cell->str,  cell->strlength);
          p += cell->strlength;
          validthisrow++;
        }
        // No point leaving trailing spaces ...
        if (validthisrow < itemsInRow[row]) {
          for(i=cell->strlength; i <= clen; i++) // one extra because of space between columns
            *(tableout + p++) = ' ';
        }
      }
    }
    *(tableout + p++) = '\n';
  }
  *(tableout + p) = '\0';

  if (size) *size = p;
  return tableout;
}
Ejemplo n.º 3
0
void Calls::CreateCallingToCalledTBV() {
	int totalNoOfProcs = ProcTable::GetNoOfProcs();
	vector<bool> emptyRow(totalNoOfProcs + 1, false);
	callingToCalledTBV = vector<vector<bool>>(totalNoOfProcs + 1, emptyRow);

	vector<int> calledT;
	for (int i = 0; i < totalNoOfProcs; i++) {
		calledT = GetProcsCalledTBy(i);

		for(vector<int>::iterator it = calledT.begin(); it != calledT.end(); it++) {
			callingToCalledTBV.at(i).at(*it) = true;
		}
	
	}

}
Ejemplo n.º 4
0
/**
 * Set value in row and column.
*/
int Table::setValue(int value, int row, int col) {
  int pos;
  int ret = -1;

  if (validated && row >= 0 && row < height) {
    // was the value added
    if (!lines[row]->setValue(value, col)) {
      // check if not violates table
      if ((value ? fullRow(row) : emptyRow(row)) || 
          (value ? fullColumn(col) : emptyColumn(col)) ||
          duplicatedRow(row, &pos))
        lines[row]->setValue((value ? 0 : 1), col);
      else
        ret = 0; // no error
    }
  }

  return ret;
}