int main(int argc, char** argv)
{
    if (argc != 2)
    {
        show_usage();
        return -1;
    }
    const size_t buckets = boost::lexical_cast<size_t>(argv[1]);

    const size_t total_txs = read_total("values.seqdb");
    // Copied from prepare.cpp
    const size_t max_tx_size = 400;

    BITCOIN_ASSERT(buckets > 0);
    std::cout << "Buckets: " << buckets << std::endl;

    touch_file("htdb_slabs");
    mmfile file("htdb_slabs");
    BITCOIN_ASSERT(file.data());
    file.resize(4 + 8 * buckets + 8 + total_txs * max_tx_size * 2);

    htdb_slab_header header(file, 0);
    header.initialize_new(buckets);
    header.start();

    slab_allocator alloc(file, 4 + 8 * buckets);
    alloc.initialize_new();
    alloc.start();

    htdb_slab<hash_digest> ht(header, alloc);

    size_t number_wrote = 0;
    auto read = [&ht, &number_wrote](const data_chunk& value)
    {
        const hash_digest key = bitcoin_hash(value);
        auto write = [&value](uint8_t* data)
        {
            std::copy(value.begin(), value.end(), data);
        };
        ht.store(key, value.size(), write);
        ++number_wrote;
    };
    iterate_values("values.seqdb", read);

    alloc.sync();
    std::cout << "Wrote " << number_wrote << " values. Done." << std::endl;
    return 0;
}
Ejemplo n.º 2
0
int load_file(const char *directory, const char *ip) {
    char block_type;
    int sock, file;
    int trans_cond = EXIT_SUCCESS;
    /** Opening socket descriptor */
    if ((sock = open_socket(ip)) == EXIT_FAILURE) {
        return EXIT_FAILURE;
    }
    /** Reading block until all files will not be received **/
    while (read_total(sock, &block_type, 1) == 1
           && block_type == BLOCK_FILE_START) {
        /** Reading file name **/
        const char *file_name = (const char *) read_data(sock, '\n', 0);
        /** Concatinating into file path **/
        char *file_path = fpath(file_name, directory);
        /** Reading file size **/
        off_t file_size = *((unsigned long *) read_data(sock, 0, 8));
        /** Opening file descriptor */
        if ((file = open_file(file_path, O_CREAT | O_WRONLY)) == EXIT_FAILURE) {
            return EXIT_FAILURE;
        }
        setup_bar(file_name, file_size);
        trans_cond = transfer_data(sock, file, 0, file_size);
        /** Closing streams **/
        close(file);
        /** Checking for transfer condition **/
        if (trans_cond == EXIT_FAILURE) {
            /** Nothing to do now **/
            break;
        }
        printf("\n");
    }
    /** Checking for transaction success **/
    if (trans_cond == EXIT_SUCCESS) {
        block_type = BLOCK_FILE_END;
        write_total(sock, &block_type, 1);
    }
    shutdown(sock, SHUT_RDWR);
    return trans_cond;
}
void strafeToIR()
{
	// This function triangulates the position of the IR beacon, then strafes left or right until the robot is directly facing it
	bool done = 0;
	while(done == 0)
	{
		switch(read_total())			// This switch statement considers every possible value that could be returned from the two IR sensors, and
		{													//designates which direction to move based on it
		case 1:										// If a value of 1 is returned, strafe left at 100% speed
			motor[motorFL] = -100;
			motor[motorFR] = 100;
			motor[motorBR] = -100;
			motor[motorBL] = 100;
			break;
		case 2:										// If a value of 2 is returned, strafe left at 100% speed
			motor[motorFL] = -100;
			motor[motorFR] = 100;
			motor[motorBR] = -100;
			motor[motorBL] = 100;
			break;
		case 3:										// If a value of 3 is returned, strafe left at 88% speed
			motor[motorFL] = -88;
			motor[motorFR] = 88;
			motor[motorBR] = -88;
			motor[motorBL] = 88;
			break;
		case 4:										// If a value of 4 is returned, strafe left at 75% speed
			motor[motorFL] = -75;
			motor[motorFR] = 75;
			motor[motorBR] = -75;
			motor[motorBL] = 75;
			break;
		case 5:										// If a value of 5 is returned, strafe left at 63% speed
			motor[motorFL] = -63;
			motor[motorFR] = 63;
			motor[motorBR] = -63;
			motor[motorBL] = 63;
			break;
		case 6:										// If a value of 6 is returned, strafe left at 50% speed
			motor[motorFL] = -50;
			motor[motorFR] = 50;
			motor[motorBR] = -50;
			motor[motorBL] = 50;
			break;
		case 7:										// If a value of 7 is returned, strafe left at 38% speed
			motor[motorFL] = -38;
			motor[motorFR] = 38;
			motor[motorBR] = -38;
			motor[motorBL] = 38;
			break;
		case 8:										// If a value of 8 is returned, strafe left at 25% speed
			motor[motorFL] = -25;
			motor[motorFR] = 25;
			motor[motorBR] = -25;
			motor[motorBL] = 25;
			break;
		case 9:										// If a value of 9 is returned, strafe left at 25% speed
			motor[motorFL] = -25;
			motor[motorFR] = 25;
			motor[motorBR] = -25;
			motor[motorBL] = 25;
			break;
		case 10:									// If a value of 10 is returned, stop the robot, end the function, and stop timing the program
			motor[motorFL] = 0;
			motor[motorFR] = 0;
			motor[motorBR] = 0;
			motor[motorBL] = 0;
			done = true;
			StopTask(counter);
			break;
		case 11:									// If a value of 11 is returned, strafe right at 25% speed
			motor[motorFL] = 25;
			motor[motorFR] = -25;
			motor[motorBR] = 25;
			motor[motorBL] = -25;
			break;
		case 12:									// If a value of 12 is returned, strafe right at 25% speed
			motor[motorFL] = 25;
			motor[motorFR] = -25;
			motor[motorBR] = 25;
			motor[motorBL] = -25;
			break;
		case 13:									// If a value of 13 is returned, strafe right at 38% speed
			motor[motorFL] = 38;
			motor[motorFR] = -38;
			motor[motorBR] = 38;
			motor[motorBL] = -38;
			break;
		case 14:									// If a value of 14 is returned, strafe right at 50% speed
			motor[motorFL] = 50;
			motor[motorFR] = -50;
			motor[motorBR] = 50;
			motor[motorBL] = -50;
			break;
		case 15:									// If a value of 15 is returned, strafe right at 63% speed
			motor[motorFL] = 63;
			motor[motorFR] = -63;
			motor[motorBR] = 63;
			motor[motorBL] = -63;
			break;
		case 16:									// If a value of 16 is returned, strafe right at 75% speed
			motor[motorFL] = 75;
			motor[motorFR] = -75;
			motor[motorBR] = 75;
			motor[motorBL] = -75;
			break;
		case 17:									// If a value of 17 is returned, strafe right at 88% speed
			motor[motorFL] = 88;
			motor[motorFR] = -88;
			motor[motorBR] = 88;
			motor[motorBL] = -88;
			break;
		case 18:									// If a value of 18 is returned, strafe right at 100% speed
			motor[motorFL] = 100;
			motor[motorFR] = -100;
			motor[motorBR] = 100;
			motor[motorBL] = -100;
			break;
		default:									// Otherwise, don't move
			motor[motorFL] = 0;
			motor[motorFR] = 0;
			motor[motorBR] = 0;
			motor[motorBL] = 0;
			break;
		}
	}
}