buzzswarm_members_t buzzswarm_members_new() { return buzzdict_new(10, sizeof(uint16_t), sizeof(buzzswarm_elem_t), buzzdict_uint16keyhash, buzzdict_uint16keycmp, buzzswarm_elem_destroy); }
buzzvstig_t buzzvstig_new() { buzzvstig_t x = (buzzvstig_t)malloc(sizeof(struct buzzvstig_s)); x->data = buzzdict_new( 10, sizeof(buzzobj_t), sizeof(buzzvstig_elem_t), buzzvstig_key_hash, buzzvstig_key_cmp, buzzvstig_elem_destroy); x->onconflict = NULL; x->onconflictlost = NULL; return x; }
int main() { buzzdict_t di = buzzdict_new(4, sizeof(int16_t), sizeof(float), di_hash, di_cmp, NULL); int16_t k; float d; di_print(di); int i; for(i = 0; i < 10; ++i) { k = i; d = (100.0f + k); fprintf(stdout, "adding (%d, %f)\n", k, d); buzzdict_set(di, &k, &d); di_print(di); } k = 5; d = (200.0f + k); fprintf(stdout, "assigning (%d, %f)\n", k, d); buzzdict_set(di, &k, &d); di_print(di); k = 10; d = (200.0f + k); fprintf(stdout, "assigning (%d, %f)\n", k, d); buzzdict_set(di, &k, &d); di_print(di); k = 4; fprintf(stdout, "removing (%d)\n", k); buzzdict_remove(di, &k); di_print(di); k = 10; fprintf(stdout, "removing (%d)\n", k); buzzdict_remove(di, &k); di_print(di); buzzdict_destroy(&di); return 0; }
buzzvm_t buzzvm_new(uint16_t robot) { /* Create VM state. calloc() takes care of zeroing everything */ buzzvm_t vm = (buzzvm_t)calloc(1, sizeof(struct buzzvm_s)); /* Create stacks */ vm->stacks = buzzdarray_new(BUZZVM_STACKS_INIT_CAPACITY, sizeof(buzzdarray_t), buzzvm_darray_destroy); vm->stack = buzzdarray_new(BUZZVM_STACK_INIT_CAPACITY, sizeof(buzzobj_t), NULL); buzzdarray_push(vm->stacks, &(vm->stack)); /* Create local variable tables */ vm->lsymts = buzzdarray_new(BUZZVM_LSYMTS_INIT_CAPACITY, sizeof(buzzvm_lsyms_t), buzzvm_lsyms_destroy); vm->lsyms = NULL; /* Create global variable tables */ vm->gsyms = buzzdict_new(BUZZVM_SYMS_INIT_CAPACITY, sizeof(int32_t), sizeof(buzzobj_t), buzzdict_int32keyhash, buzzdict_int32keycmp, NULL); /* Create string list */ vm->strings = buzzstrman_new(); /* Create heap */ vm->heap = buzzheap_new(); /* Create function list */ vm->flist = buzzdarray_new(20, sizeof(buzzvm_funp), NULL); /* Create swarm list */ vm->swarms = buzzdict_new(10, sizeof(uint16_t), sizeof(uint8_t), buzzdict_uint16keyhash, buzzdict_uint16keycmp, NULL); /* Create swarm stack */ vm->swarmstack = buzzdarray_new(10, sizeof(uint16_t), NULL); /* Create swarm member structure */ vm->swarmmembers = buzzswarm_members_new(); vm->swarmbroadcast = SWARM_BROADCAST_PERIOD; /* Create message queues */ vm->inmsgs = buzzinmsg_queue_new(); vm->outmsgs = buzzoutmsg_queue_new(robot); /* Create virtual stigmergy */ vm->vstigs = buzzdict_new(10, sizeof(uint16_t), sizeof(buzzvstig_t), buzzdict_uint16keyhash, buzzdict_uint16keycmp, buzzvm_vstig_destroy); /* Create virtual stigmergy */ vm->listeners = buzzdict_new(10, sizeof(uint16_t), sizeof(buzzobj_t), buzzdict_uint16keyhash, buzzdict_uint16keycmp, NULL); /* Take care of the robot id */ vm->robot = robot; /* Initialize empty random number generator (buzzvm_math takes care of creating it) */ vm->rngstate = NULL; vm->rngidx = 0; /* Return new vm */ return vm; }