Ejemplo n.º 1
0
int find_bucket(long long hash_index, long long *bid, int*mo, INDEX_FILE *index_file){
	void *bucket;
	int tmp_bid;
	bucket = calloc(BSIZE,sizeof(char));
	if (bucket==NULL){
		printf("Malloc failed");
		exit(1);
	}
	read_bucket(bucket, hash_index, index_file->main_path);
	if (((long long*)(bucket+4))[0]==-1){
		if (((int*)bucket)[0] < BSIZE-sizeof(long long)-atoi((index_file->type)+1)) {
			*bid = hash_index;
			*mo = 0;
			free(bucket);
			return 0;
		} else {

			*bid = create_overflow_bucket(index_file);
			mylink(hash_index, 0, *bid, index_file);
			*mo = 1;

			free(bucket);
			return 1;
		}
	} else {
		long long next_bid =  ((long long*)(bucket+4))[0];
        	do
		{
			read_bucket(bucket, next_bid, index_file->overflow_path);
			tmp_bid = next_bid;
			next_bid = ((long long*)(bucket+4))[0];	
		}
		while(next_bid != -1);
		if (((int*)bucket)[0] < BSIZE-sizeof(long long)-atoi((index_file->type)+1)) {
			*bid = tmp_bid;			
			*mo = 1;
			free(bucket);
			return 0;
		} else {
			*bid = create_overflow_bucket(index_file);
			mylink(tmp_bid, 1, *bid, index_file);
			*mo = 1;
			free(bucket);
			return 1;
		}
	}
}
Ejemplo n.º 2
0
int
OpenDDS::DCPS::DataLinkSet::insert_link(DataLink* link)
{
  DBG_ENTRY_LVL("DataLinkSet","insert_link",6);
  DataLink_rch mylink(link, false);
  GuardType guard(this->lock_);
  return OpenDDS::DCPS::bind(map_, mylink->id(), mylink);
}
Ejemplo n.º 3
0
static void run_test2(long i, long c) 
{
    double cpe;
    long len = ASIZE;
    mylink(len);
    printf("Description: %s, %s, ",
	   test2_descr[i], case2_descr[c]);
    myindex = i;
    cpe = find_cpe(case_fun[c], ASIZE);
    /* print results */
    printf("CPE = %.2f\n", cpe);
}
Ejemplo n.º 4
0
/* Perform test of one of the list functions */
static void run_test(long i)
{
    double cpe;
    long len = ASIZE;
    mylink(len);
    printf("Description: %s, f(%ld) = %ld, ",
	   test_descr[i], len, test_fun[i](main_list));
    myindex = i;
    cpe = find_cpe(test, ASIZE);
    /* print results */
    printf("CPE = %.2f\n", cpe);
}
Ejemplo n.º 5
0
QoccHarnessWindow::QoccHarnessWindow(QStringList ags)
: args(ags), myLastFolder(tr(""))
{
	myVC  = new QoccViewerContext();
	myOCC = new QoccViewWidget(myVC->getContext(), this); //Note this has changed!
	this->setCentralWidget(myOCC);

    	createActions();
    	createMenus();

    	//statusBar()->showMessage(tr("A context menu is available by right-clicking"));

    	setWindowTitle(tr("Cam-occ v2"));
        setMinimumSize(300, 300);
        showNormal();
    	resize(789,527);  //so that it will fit nicely on 1/4 of my screen

        //showMaximized();

	lnk mylink(this);

}
Ejemplo n.º 6
0
void rehash_keys(HFILE *hf, int i, INDEX_FILE *index_file){
	void *original_bucket;
	void *old_bucket;
	void *new_bucket;
	void *buf;
	int original_offset=12;
	int original_usage;
	int old_bucket_write_position = -1;
	int new_bucket_write_position = -1;
	int free_start_point;
	
	original_bucket = calloc(BSIZE,sizeof(char));
	if (original_bucket==NULL){
		printf("Malloc failed");
		exit(1);
	}
	old_bucket = calloc(BSIZE,sizeof(char));
	if (old_bucket==NULL){
		printf("Malloc failed");
		exit(1);
	}
	new_bucket = calloc(BSIZE,sizeof(char));
	if (new_bucket==NULL){
		printf("Malloc failed");
		exit(1);
	}
	buf = calloc(105,sizeof(char));
	if (buf==NULL){
		printf("Malloc failed");
		exit(1);
	}
	read_bucket(original_bucket, index_file->next, index_file->main_path);
	original_usage = ((int*)original_bucket)[0];
	read_bucket(old_bucket, index_file->next, index_file->main_path);
	((int*)old_bucket)[0]=12;

	read_bucket(new_bucket, index_file->n, index_file->main_path);
	for (original_offset = 12; original_offset < original_usage; original_offset += atoi((hf->schema[i])+1)+sizeof(long long)){
		RID rid = (*read_keypair[hf->schema_array[i]])(original_bucket, buf, original_offset, atoi((hf->schema[i])+1));
		long long new_index = (*calculate_index[hf->schema_array[i]])(buf,index_file->s,index_file->n+1, 0);
		if (new_index==index_file->next){//old
			if (((int*)old_bucket)[0] >= BSIZE-sizeof(long long)-atoi((index_file->type)+1)){//full, allocate new		
				if (old_bucket_write_position == -1){
					write_bucket(old_bucket, index_file->next, index_file->main_path);
				} else {
					write_bucket(old_bucket, old_bucket_write_position, index_file->overflow_path);
				}
				old_bucket_write_position = ((long long*)(old_bucket+4))[0];
				read_bucket(old_bucket, old_bucket_write_position, index_file->overflow_path);
				((int*)old_bucket)[0]=12;	
			}

			(*update_bucket[hf->schema_array[i]])(old_bucket,buf,rid,atoi((hf->schema[i])+1)+sizeof(long long),0);

		} else { //new
			if (((int*)new_bucket)[0] >= BSIZE-sizeof(long long)-atoi((index_file->type)+1)){//full, allocate new		
				if (new_bucket_write_position == -1){
					write_bucket(new_bucket, index_file->n, index_file->main_path);
					new_bucket_write_position = create_overflow_bucket(index_file);
					mylink(index_file->n, 0, new_bucket_write_position, index_file);
				} else {
					RID tmp = new_bucket_write_position;
					write_bucket(new_bucket, new_bucket_write_position, index_file->overflow_path);
					new_bucket_write_position = create_overflow_bucket(index_file);
					mylink(tmp, 1, new_bucket_write_position, index_file);
				}
				read_bucket(new_bucket, new_bucket_write_position, index_file->overflow_path);	
			}
			(*update_bucket[hf->schema_array[i]])(new_bucket,buf,rid,atoi((hf->schema[i])+1)+sizeof(long long),0);
		}
	}
	while (((long long*)(original_bucket+4))[0]!=-1){
		read_bucket(original_bucket, ((long long*)(original_bucket+4))[0], index_file->overflow_path);
		original_usage = ((int*)original_bucket)[0];
		for (original_offset = 12; original_offset < original_usage; original_offset += atoi((hf->schema[i])+1)+sizeof(long long)){
			RID rid = (*read_keypair[hf->schema_array[i]])(original_bucket, buf, original_offset, atoi((hf->schema[i])+1));
			long long new_index = (*calculate_index[hf->schema_array[i]])(buf,index_file->s,index_file->n+1, 0);
			if (new_index==index_file->next){//old
				if (((int*)old_bucket)[0] >= BSIZE-sizeof(long long)-atoi((index_file->type)+1)){//full, allocate new		
					if (old_bucket_write_position == -1){
						write_bucket(old_bucket, index_file->next, index_file->main_path);
					} else {
						write_bucket(old_bucket, old_bucket_write_position, index_file->overflow_path);
					}
					old_bucket_write_position = ((long long*)(old_bucket+4))[0];

					read_bucket(old_bucket, old_bucket_write_position, index_file->overflow_path);
					((int*)old_bucket)[0]=12;	
				}
				(*update_bucket[hf->schema_array[i]])(old_bucket,buf,rid,atoi((hf->schema[i])+1)+sizeof(long long),0);
			} else { //new
				if (((int*)new_bucket)[0] >= BSIZE-sizeof(long long)-atoi((index_file->type)+1)){//full, allocate new		
					if (new_bucket_write_position == -1){
						write_bucket(new_bucket, index_file->n, index_file->main_path);
						new_bucket_write_position = create_overflow_bucket(index_file);
						mylink(index_file->n, 0, new_bucket_write_position, index_file);
					} else {
						RID tmp = new_bucket_write_position;
						write_bucket(new_bucket, new_bucket_write_position, index_file->overflow_path);
						new_bucket_write_position = create_overflow_bucket(index_file);
						mylink(tmp, 1, new_bucket_write_position, index_file);
					}
					read_bucket(new_bucket, new_bucket_write_position, index_file->overflow_path);	
				}
				(*update_bucket[hf->schema_array[i]])(new_bucket,buf,rid,atoi((hf->schema[i])+1)+sizeof(long long),0);
			}
		}
	}
	free_start_point = ((long long*)(old_bucket+4))[0];
	if (free_start_point != -1){

		int original_free_tail = find_free_list_tail(index_file);
		if (original_free_tail != -1) {
			mylink(original_free_tail, 1, free_start_point, index_file);
		} else {
			add_to_free_list(free_start_point, index_file);
		}
	}
	((long long*)(old_bucket+4))[0] = -1;
	if (old_bucket_write_position == -1){
		write_bucket(old_bucket, index_file->next, index_file->main_path);
	} else {
		write_bucket(old_bucket, old_bucket_write_position, index_file->overflow_path);
	}
	if (new_bucket_write_position == -1){
		write_bucket(new_bucket, index_file->n, index_file->main_path);
	} else {
		write_bucket(new_bucket, new_bucket_write_position, index_file->overflow_path);
	}
	
	free(original_bucket);
	free(old_bucket);
	free(new_bucket);
	free(buf);
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
	double C[SIZE];
	char D[SIZE];
	bool bResult = false;

	/* if no command line arguments passed, we'll default to 
		these two port number */

	int port = 5010;
	int dataport = -1;
	
	if (argc > 1)
	{
		port = atoi(argv[1]);

		if (argc > 2)
			dataport = atoi(argv[2]);
	}

	printf("Server, listening on port %d, datagram port %d\n", port, dataport);
	fflush(NULL);

	Server mylink(port, dataport, &bResult);
	if (!bResult)
	{
		printf("Failed to create Server object!\n");
		return 0;
	}

	/* put some dummy data in our arrays */

	for (int i = 0; i < SIZE; i++)
	{
		C[i] = (double) i*i+0.5;
		D[i] = i;
	}
	printf("Server, waiting for connection...\n");
	fflush(NULL);
	mylink.Connect();

	printf("Server, got a connection...\n");
	fflush(NULL);

	for (int i = 0; i < NUM_PACKS; i++)
	{
		printf("Server, sending bytes, iteration %d...\n", i);
	   	fflush(NULL);
		mylink.SendBytes(D, SIZE);

		printf("Server, receiving doubles, iteration %d...\n", i);
		fflush(NULL);
		mylink.RecvDoubles(C, SIZE);
	}

	printf("Server, closing connection...\n");
	fflush(NULL);
	mylink.Close();

	printf("Server, done...\n");
	fflush(NULL);
	return 0;
}