RC GHJ::SentOutput(RECORD * tuple) { if(m_OutPage.freeSpace > 508) // page not full { AddTupleToPage(tuple, &m_OutPage, &m_OutPageBuffer); } else // page is full { if(m_OutBuffer.currentSize <= m_OutBuffer.size) // output buffer full { AddPageToBuffer(&m_OutPage, &m_OutBuffer); ResetPage(&m_OutPage, &m_OutPageBuffer); AddTupleToPage(tuple, &m_OutPage, &m_OutPageBuffer); } else//该桶已经没有剩余的页 { DWORD dwBytesToWrite = m_OutBuffer.currentSize; DWORD dwBytesWritten = 0; WriteFile(m_hOutFile, m_OutBuffer.data, dwBytesToWrite, &dwBytesWritten, NULL); ResetBuffer(&m_OutBuffer); AddPageToBuffer(&m_OutPage, &m_OutBuffer); ResetPage(&m_OutPage, &m_OutPageBuffer); AddTupleToPage(tuple, &m_OutPage, &m_OutPageBuffer); m_OutBuffer.tupleCount++; } m_OutBuffer.pageCount++; } return SUCCESS; }
/* Draw a line */ static int mac_draw_line (register gx_device *dev, int x0, int y0, int x1, int y1, gx_color_index color) { gx_device_macos * mdev = (gx_device_macos *)dev; CheckMem(1024, 100*1024); ResetPage(); GSSetFgCol(dev, mdev->currPicPos, color); PICT_Line(mdev->currPicPos, x0, y0, x1, y1); PICT_OpEndPicGoOn(mdev->currPicPos); return 0; }
/* Copy a monochrome bitmap. */ static int mac_copy_mono (register gx_device *dev, const unsigned char *base, int data_x, int raster, gx_bitmap_id id, int x, int y, int w, int h, gx_color_index color_0, gx_color_index color_1) { gx_device_macos * mdev = (gx_device_macos *)dev; int byteCount = raster * h; short copyMode; // this case doesn't change the picture -> return without wasting time if (color_0 == gx_no_color_index && color_1 == gx_no_color_index) return 0; fit_copy(dev, base, data_x, raster, id, x, y, w, h); CheckMem(10*1024 + byteCount*10, 100*1024 + byteCount*10); ResetPage(); if (color_0 == gx_no_color_index) copyMode = srcOr; else if (color_1 == gx_no_color_index) copyMode = notSrcBic; // this mode is untested ! (no file found which is using it) else copyMode = srcCopy; copyMode += ditherCopy; GSSetBkCol(dev, mdev->currPicPos, color_0); GSSetFgCol(dev, mdev->currPicPos, color_1); PICTWriteOpcode(mdev->currPicPos, 0x0098); PICTWriteInt(mdev->currPicPos, raster); PICTWriteRect(mdev->currPicPos, 0, 0, raster*8, h); PICTWriteRect(mdev->currPicPos, data_x, 0, w, h); PICTWriteRect(mdev->currPicPos, x, y, w, h); PICTWriteInt(mdev->currPicPos, copyMode); PICTWriteDataPackBits(mdev->currPicPos, base, raster, h); PICT_OpEndPicGoOn(mdev->currPicPos); return 0; }
static int mac_render_char(gx_xfont *xf, gx_xglyph xg, gx_device *dev, int xo, int yo, gx_color_index color, int required) { #pragma unused(dev,required) mac_xfont * macxf = (mac_xfont*) xf; gx_device_macos * mdev = (gx_device_macos*) macxf->dev; Str255 character; int i, found; CheckMem(10*1024, 100*1024); ResetPage(); character[0] = 1; character[1] = xg; GSSetFgCol(macxf->dev, mdev->currPicPos, color); found = 0; for (i=0; i<mdev->numUsedFonts; i++) if (mdev->usedFontIDs[i] == macxf->fontID) found = 1; if (!found) { mdev->usedFontIDs[mdev->numUsedFonts++] = macxf->fontID; PICT_fontName(mdev->currPicPos, macxf->fontID, macxf->fontName); } if (mdev->lastFontID != macxf->fontID) { PICT_TxFont(mdev->currPicPos, macxf->fontID); mdev->lastFontID = macxf->fontID; } if (mdev->lastFontSize != macxf->fontSize) { PICT_TxSize(mdev->currPicPos, macxf->fontSize); mdev->lastFontSize = macxf->fontSize; } if (mdev->lastFontFace != macxf->fontFace) { PICT_TxFace(mdev->currPicPos, macxf->fontFace); mdev->lastFontFace = macxf->fontFace; } PICT_LongText(mdev->currPicPos, xo, yo, character); PICT_OpEndPicGoOn(mdev->currPicPos); return 0; }
/* Fill a rectangle with a color. */ static int mac_fill_rectangle(register gx_device *dev, int x, int y, int w, int h, gx_color_index color) { gx_device_macos * mdev = (gx_device_macos *)dev; /* ignore a fullpage rect directly after an output_page, this would clear the pict */ if (mdev->outputPage && (x == 0) && (y == 0) && (w == mdev->width) && (h == mdev->height)) { return 0; } CheckMem(1024, 100*1024); ResetPage(); GSSetFgCol(dev, mdev->currPicPos, color); PICT_fillRect(mdev->currPicPos, x, y, w, h); PICT_OpEndPicGoOn(mdev->currPicPos); return 0; }
/* Copy a color bitmap. */ static int mac_copy_color (register gx_device *dev, const unsigned char *base, int data_x, int raster, gx_bitmap_id id, int x, int y, int w, int h) { gx_device_macos * mdev = (gx_device_macos *)dev; int byteCount = raster * h, color; gx_color_value rgb[3]; fit_copy(dev, base, data_x, raster, id, x, y, w, h); CheckMem(10*1024 + byteCount*4, 100*1024 + byteCount*4); ResetPage(); GSSetStdCol(mdev->currPicPos); // Sets FgCol to Black and BkCol to White if (mdev->color_info.depth == 24) { PICTWriteOpcode(mdev->currPicPos, 0x009A); PICTWriteLong(mdev->currPicPos, 0x000000FF); PICTWritePixMap(mdev->currPicPos, 0, 0, raster/4, h, raster, 2, 0, X2Fix(mdev->x_pixels_per_inch), X2Fix(mdev->y_pixels_per_inch), 32); PICTWriteRect(mdev->currPicPos, data_x, 0, w, h); PICTWriteRect(mdev->currPicPos, x, y, w, h); PICTWriteInt(mdev->currPicPos, srcCopy); /* memcpy(mdev->currPicPos, base, byteCount); (char*)(mdev->currPicPos) += byteCount;*/ { short i; byteCount = 0; for (i=0; i<raster/4*h; i++) { // PICTWriteByte(mdev->currPicPos, 0x00); PICTWriteByte(mdev->currPicPos, 0x00); PICTWriteByte(mdev->currPicPos, 0x00); PICTWriteByte(mdev->currPicPos, 0x00); byteCount += 3; } } if (byteCount % 2) PICTWriteFillByte(mdev->currPicPos); } else if (mdev->color_info.depth <= 8) { ColorSpec *colorTable; colorTable = (ColorSpec*) malloc(sizeof(ColorSpec) * (1 << mdev->color_info.depth)); for (color=0; color < (1 << mdev->color_info.depth); color++) { (*dev_proc(dev, map_color_rgb))(dev, color, rgb); colorTable[color].value = color; colorTable[color].rgb.red = rgb[0]; colorTable[color].rgb.green = rgb[1]; colorTable[color].rgb.blue = rgb[2]; } PICTWriteOpcode(mdev->currPicPos, 0x0098); PICTWritePixMap(mdev->currPicPos, 0, 0, raster*8/mdev->color_info.depth, h, raster, 1, 0, X2Fix(mdev->x_pixels_per_inch), X2Fix(mdev->y_pixels_per_inch), mdev->color_info.depth); PICTWriteColorTable(mdev->currPicPos, 0, (1 << mdev->color_info.depth), colorTable); PICTWriteRect(mdev->currPicPos, data_x, 0, w, h); PICTWriteRect(mdev->currPicPos, x, y, w, h); PICTWriteInt(mdev->currPicPos, srcCopy); PICTWriteDataPackBits(mdev->currPicPos, base, raster, h); free(colorTable); } else { gx_default_copy_color( dev, base, data_x, raster, id, x, y, w, h ); } PICT_OpEndPicGoOn(mdev->currPicPos); return 0; }
/* that's why this will only work on a fully white background!!!! */ static int mac_copy_alpha(gx_device *dev, const unsigned char *base, int data_x, int raster, gx_bitmap_id id, int x, int y, int w, int h, gx_color_index color, int depth) { gx_device_macos * mdev = (gx_device_macos *)dev; ColorSpec *colorTable; short copyMode, shade, maxShade = (1 << depth) - 1, byteCount = raster * h; gx_color_value rgb[3]; colorHSV colHSV; colorRGB colRGB; float saturation, value; fit_copy(dev, base, data_x, raster, id, x, y, w, h); CheckMem( byteCount*4 + 200*1024, byteCount*4 + 500*1024 ); ResetPage(); colorTable = (ColorSpec*) malloc(sizeof(ColorSpec) * (maxShade+1)); if (colorTable == NULL) return gs_error_VMerror; (*dev_proc(dev, map_color_rgb))(dev, color, rgb); colRGB.red = rgb[0]; colRGB.green = rgb[1]; colRGB.blue = rgb[2]; mac_convert_rgb_hsv(&colRGB, &colHSV); saturation = colHSV.s; value = colHSV.v; for (shade=0; shade <= maxShade; shade++) { colorTable[shade].value = maxShade - shade; colHSV.s = saturation * (1.0 - (float)shade/(float)maxShade); colHSV.v = value + ((1.0 - value) * (float)shade/(float)maxShade); mac_convert_hsv_rgb(&colHSV, &colRGB); colorTable[shade].rgb.red = colRGB.red; colorTable[shade].rgb.green = colRGB.green; colorTable[shade].rgb.blue = colRGB.blue; } copyMode = srcCopy + ditherCopy; GSSetStdCol(mdev->currPicPos); if (raster < 8) { PICTWriteOpcode(mdev->currPicPos, 0x0090); } else { PICTWriteOpcode(mdev->currPicPos, 0x0098); } PICTWritePixMap(mdev->currPicPos, 0, 0, raster*8/depth, h, raster, 0, 0, X2Fix(mdev->x_pixels_per_inch), X2Fix(mdev->y_pixels_per_inch), depth); PICTWriteColorTable(mdev->currPicPos, 0, maxShade+1, colorTable); PICTWriteRect(mdev->currPicPos, data_x, 0, w, h); PICTWriteRect(mdev->currPicPos, x, y, w, h); PICTWriteInt(mdev->currPicPos, copyMode); PICTWriteDataPackBits(mdev->currPicPos, base, raster, h); PICT_OpEndPicGoOn(mdev->currPicPos); free(colorTable); return 0; }
RC GHJ::Execute() { RC rc = Initialize(); if(rc!=SUCCESS) { return rc; } DOUBLE cpuTimeBefore = 0; DOUBLE cpuTimeAfter = 0; DOUBLE cpuTime = 0; StopWatch stwTotalTime; StopWatch stwJoinTime; StopWatch stwPartitionTime; UINT64 totalTime = 0; UINT64 partitionTime = 0; UINT64 joinTime = 0; stwTotalTime.Start(); stwPartitionTime.Start(); cpuTimeBefore = GetCpuTime(); PartitionTable(m_Params.RELATION_R_PATH, m_Params.R_KEY_POS, &m_InBuffer, m_BucketBuffer, m_FileHandle); /*************************************************************************/ //再次对桶装配过程中需要的全局变量初始化 for(UINT partitionIndex=0; partitionIndex < m_PartitionNum; partitionIndex++) { ResetPage(&m_BucketPage[partitionIndex], &m_BucketBuffer[partitionIndex]); } PartitionTable(m_Params.RELATION_S_PATH, m_Params.S_KEY_POS, &m_InBuffer, m_BucketBuffer, m_FileHandle); partitionTime = stwPartitionTime.NowInMilliseconds(); stwJoinTime.Start(); HashJoin(&m_Pool); cpuTimeAfter = GetCpuTime(); totalTime = stwTotalTime.NowInMilliseconds(); joinTime = stwJoinTime.NowInMilliseconds(); cpuTime = cpuTimeAfter - cpuTimeBefore; FILE *fp; CHAR *reportFilePath = new CHAR[MAX_PATH]; LPWSTR tempReportPath = new TCHAR[MAX_PATH]; swprintf(tempReportPath, MAX_PATH, L"%s%s", m_Params.WORK_SPACE_PATH, L"GHJ_Report.csv" ); // convert file path to char size_t count = wcstombs(reportFilePath, tempReportPath, MAX_PATH); CHAR *reportTitle = "Relation Size,Memory Size,Bucket Size,Partition,Read Buffer Size,Write Buffer Size,Total Execute Time(ms),Partition Time(ms),Join Time(ms),CPU Time\n"; CHAR *reportContent = new CHAR[1024]; sprintf(reportContent, "%d,%d,%.f,%d,%d,%d,%lld,%lld,%lld,%.f", m_R_FileSize, m_Params.BUFFER_POOL_SIZE/SSD_PAGE_SIZE, m_BucketSize, m_PartitionNum, m_Params.READ_BUFFER_SIZE/SSD_PAGE_SIZE, m_Params.WRITE_BUFFER_SIZE/SSD_PAGE_SIZE, totalTime, partitionTime, joinTime, cpuTime); fp=fopen(reportFilePath, "w+b"); fprintf(fp, reportTitle); fprintf(fp, reportContent); fclose(fp); delete reportFilePath; delete tempReportPath; delete reportContent; //连接结束后 删除所有的临时文件 LPWSTR tempBucketName = new TCHAR[MAX_PATH]; for(UINT partitionIndex=0;partitionIndex < m_PartitionNum;partitionIndex++) { swprintf_s(tempBucketName, MAX_PATH, L"%s%d%s.tmp", m_Params.WORK_SPACE_PATH, partitionIndex, m_Params.RELATION_R_NO_EXT); DeleteFile(tempBucketName); swprintf_s(tempBucketName, MAX_PATH, L"%s%d%s.tmp", m_Params.WORK_SPACE_PATH, partitionIndex, m_Params.RELATION_S_NO_EXT); DeleteFile(tempBucketName); } delete tempBucketName; delete m_Pool.data; CloseHandle(m_hOutFile); ShowMB(L"GHJ done"); return SUCCESS; }