bool Skiplist::insert( double val )
{
	int new_level = calc_random_level();

	std::vector<Node*> next_vec = get_next_vector(new_level, val);

	if(next_vec.empty())
	{
		return false;
	}

	Node* new_node = new Node(val, new_level);

	for(int i = 0; i < next_vec.size(); ++i)
	{
		Node* tmp = next_vec[i]->get_next(i) != NULL ? next_vec[i]->get_next(i) : NULL;
		
		next_vec[i]->set_next(i, new_node);
		new_node->set_next(i, tmp);
	}

	return true;
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------------------------
 * (function: simulateNextWave)
 *-------------------------------------------------------------------------------------------*/
int OdinInterface::simulateNextWave()
{
    if(!num_vectors){
        fprintf(stderr, "No vectors to simulate.\n");
    } else {

        double total_time = 0;
        double simulation_time = 0;

        num_cycles = num_vectors*2;
        num_waves = 1;
        tvector = 0;


        double wave_start_time = wall_time();
        //create a new wave
        wave++;
        int cycle_offset = SIM_WAVE_LENGTH * wave;
        int wave_length  = SIM_WAVE_LENGTH;

        // Assign vectors to lines, either by reading or generating them.
        // Every second cycle gets a new vector.

        for (cycle = cycle_offset; cycle < cycle_offset + wave_length; cycle++)
        {
            if (is_even_cycle(cycle))
            {
                    if (input_vector_file)
                    {
                            char buffer[BUFFER_MAX_SIZE];

                            if (!get_next_vector(in, buffer))
                                    error_message(SIMULATION_ERROR, 0, -1, (char*)"Could not read next vector.");

                            tvector = parse_test_vector(buffer);
                    }
                    else
                    {
                            tvector = generate_random_test_vector(input_lines, cycle, hold_high_index, hold_low_index);
                    }
            }

            add_test_vector_to_lines(tvector, input_lines, cycle);

            if (!is_even_cycle(cycle))
                    free_test_vector(tvector);
        }

        // Record the input vectors we are using.
        write_wave_to_file(input_lines, in_out, cycle_offset, wave_length, 1);
        // Write ModelSim script.
        write_wave_to_modelsim_file(netlist, input_lines, modelsim_out, cycle_offset, wave_length);

        double simulation_start_time = wall_time();

        // Perform simulation
        for (cycle = cycle_offset; cycle < cycle_offset + wave_length; cycle++)
        {
            if (cycle)
            {
                    simulate_cycle(cycle, stgs);
            }
            else
            {
                    // The first cycle produces the stages, and adds additional
                    // lines as specified by the -p option.
                    pin_names *p = parse_pin_name_list(global_args.sim_additional_pins);
                    stgs = simulate_first_cycle(netlist, cycle, p, output_lines);
                    free_pin_name_list(p);
                    // Make sure the output lines are still OK after adding custom lines.
                    if (!verify_lines(output_lines))
                            error_message(SIMULATION_ERROR, 0, -1,
                                            (char*)"Problem detected with the output lines after the first cycle.");
            }
        }

        simulation_time += wall_time() - simulation_start_time;

        // Write the result of this wave to the output vector file.
        write_wave_to_file(output_lines, out, cycle_offset, wave_length, output_edge);

        total_time += wall_time() - wave_start_time;

        // Print netlist-specific statistics.
        if (!cycle_offset)
        {
                print_netlist_stats(stgs, num_vectors);
                fflush(stdout);
        }

        // Print statistics.
        print_simulation_stats(stgs, num_vectors, total_time, simulation_time);
        myCycle = cycle;
    }


    return myCycle;
}