Example #1
0
int main(int argc,char *argv[]) {
    int i;
    example_user_t *user, *users=NULL, *altusers=NULL;

    /* create elements */
    for(i=0;i<1000;i++) {
        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
        user->id = i;
        user->cookie = i*i;
        if (i<10) HASH_ADD_INT(users,id,user);
        HASH_ADD(alth,altusers,id,sizeof(int),user);
    }

    printf("sorting users ascending\n");
    HASH_SRT(hh,users,ascending_sort);
    for(user=users; user; user=(example_user_t*)user->hh.next)
      printf("user %d\n", user->id);

    printf("sorting altusers descending\n");
    HASH_SRT(alth,altusers,descending_sort);
    for(user=altusers; user; user=(example_user_t*)user->alth.next)
      printf("altuser %d\n", user->id);

    /* HASH_FSCK(hh,users); */
    /* HASH_FSCK(alth,altusers); */
   return 0;
}
Example #2
0
int main(int argc,char *argv[]) {
    int i;
    example_user_t *user, *users=NULL, *ausers=NULL;

    /* create elements */
    for(i=0;i<10;i++) {
        user = (example_user_t*)malloc(sizeof(example_user_t));
        user->id = i;
        HASH_ADD_INT(users,id,user);
    }

    for(user=users; user!=NULL; user=(example_user_t*)(user->hh.next)) {
        printf("user %d\n", user->id);
    }
    printf("users count: %u\n", HASH_CNT(hh,users));

    /* now select some users into ausers */
    HASH_SELECT(ah,ausers,hh,users,EVENS);
    HASH_SRT(ah,ausers,idcmp);

    for(user=ausers; user!=NULL; user=(example_user_t*)(user->ah.next)) {
        printf("auser %d\n", user->id);
    }
    printf("ausers count: %u\n", HASH_CNT(ah,ausers));
    HASH_CLEAR(ah,ausers);
    printf("cleared ausers.\n");
    printf("ausers count: %u\n", HASH_CNT(ah,ausers));
    for(user=ausers; user!=NULL; user=(example_user_t*)(user->ah.next)) {
        printf("auser %d\n", user->id);
    }
    printf("users count: %u\n", HASH_CNT(hh,users));
   return 0;
}
Example #3
0
int main(int argc,char *argv[]) {
    int i;
    example_user_t *user, *users=NULL, *ausers=NULL;

    /* create elements */
    for(i=0;i<10;i++) {
        user = (example_user_t*)malloc(sizeof(example_user_t));
        if (user == NULL) exit(-1);
        user->id = i;
        HASH_ADD_INT(users,id,user);
    }

    for(user=users; user!=NULL; user=(example_user_t*)(user->hh.next)) {
        printf("user %d\n", user->id);
    }

    /* now select some users into ausers */
    HASH_SELECT(ah,ausers,hh,users,evens);
    HASH_SRT(ah,ausers,idcmp);

    for(user=ausers; user!=NULL; user=(example_user_t*)(user->ah.next)) {
        printf("auser %d\n", user->id);
    }
   return 0;
}
Example #4
0
int main() {
    int i;
    example_user_t *user, *users=NULL, *ausers=NULL, *tmp;

    /* create elements */
    for(i=0;i<10;i++) {
        user = (example_user_t*)m_malloc(sizeof(example_user_t));
        user->id = i;
        HASH_ADD_INT(users,id,user);
    }

    for(user=users; user; user=(example_user_t*)(user->hh.next)) {
        printf("user %d\n", user->id);
    }

    /* now select some users into ausers */
    HASH_SELECT(ah,ausers,hh,users,evens);
    HASH_SRT(ah,ausers,idcmp);

    for(user=ausers; user; user=(example_user_t*)(user->ah.next)) {
        printf("auser %d\n", user->id);
    }
   
	/* free memory */
	HASH_ITER(ah, ausers, user, tmp) {
		HASH_DELETE(ah, ausers, user);     /* delete; users advances to next */
	}
/**
* Function to save a player's changes to an craft recipe (or a new one).
*
* @param descriptor_data *desc The descriptor who is saving.
*/
void save_olc_craft(descriptor_data *desc) {
	extern int sort_crafts_by_data(craft_data *a, craft_data *b);
	
	craft_data *proto, *craft = GET_OLC_CRAFT(desc);
	craft_vnum vnum = GET_OLC_VNUM(desc);
	UT_hash_handle hh, sorted_hh;
	
	// have a place to save it?
	if (!(proto = craft_proto(vnum))) {
		proto = create_craft_table_entry(vnum);
	}
	
	// free prototype strings and pointers
	if (GET_CRAFT_NAME(proto)) {
		free(GET_CRAFT_NAME(proto));
	}
	if (GET_CRAFT_RESOURCES(proto)) {
		free(GET_CRAFT_RESOURCES(proto));
	}
	
	// sanity
	if (!GET_CRAFT_NAME(craft) || !*GET_CRAFT_NAME(craft)) {
		if (GET_CRAFT_NAME(craft)) {
			free(GET_CRAFT_NAME(craft));
		}
		GET_CRAFT_NAME(craft) = str_dup("unnamed recipe");
	}
	
	// save data back over the proto-type
	hh = proto->hh;	// save old hash handles
	sorted_hh = proto->sorted_hh;
	*proto = *craft;	// copy all data
	proto->vnum = vnum;	// ensure correct vnum
	proto->hh = hh;	// restore hash handles
	proto->sorted_hh = sorted_hh;
	
	// and save to file
	save_library_file_for_vnum(DB_BOOT_CRAFT, vnum);
	
	// ... and re-sort
	HASH_SRT(sorted_hh, sorted_crafts, sort_crafts_by_data);
}