⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genwituples.cpp

📁 linux 下用c++ 开发的一个小型数据库系统
💻 CPP
字号:
//=============================================================================// Generate simple WI Tuple unique1 tuples//=============================================================================#include <string.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <stdio.h>#include <stdlib.h>#include <time.h>#define NUMRANDOMIZEPASSES 10int main(int argc, char *argv[]){    // get command line args    if (argc != 3)    {        fprintf(stderr,                 "Usage: %s <total num tuples> <output filename>\n",                argv[0]);        return 1;    }    int tupleCount = atoi(argv[1]);    char *outputFilename = argv[2];    // gen the tuples    int nums[tupleCount];    // fill in in order    for (int i = 0; i < tupleCount; i++)    {        nums[i] = i;    }    // randomize    srand(time(NULL));    for (int pass = 0; pass < NUMRANDOMIZEPASSES; pass++)    {        for (int i = 0; i < tupleCount; i++)        {            // swap curr entry to new pos            int newPos = rand() % tupleCount;            int tmpVal = nums[newPos];            nums[newPos] = nums[i];            nums[i] = tmpVal;         }    }    // write the tuples to the output file    int outfd = open(outputFilename, O_WRONLY | O_CREAT | O_TRUNC);    if (-1 == outfd)    {        perror("Error opening file for writing\n");        exit(1);    }    // write the tuples    for (int i = 0; i < tupleCount; i++)    {        if (write(outfd, &nums[i], sizeof(int)) == -1)        {            perror("Error writing tuple\n");            return 1;        }    }            close(outfd);    printf("Done.\n");    return 0;} // end main    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -