예제 #1
0
int main() {
	struct bucket_array* b = ba_init();
	struct generic_data d;
	d.key = "music";
	d.key_l = 5;
	d.value = 2;
	printf("This new bucket has %d elements.\n", ba_size(b));

	ba_insert(b, d, 4);
	printf("Now, this bucket has %d elements.\n", ba_size(b));
	struct generic_data *p_d = ba_get(b, 4, "music", 5);
	printf("Let's see what's there: %s\n", p_d->key);
	printf("Let's remove this entry. ");
	ba_remove(b, 4, "music", 5);
	printf("The new size of the bucket array is %d.\n", ba_size(b));
	d.key = "hiking";
	d.key_l = 6;
	d.value = 5;
	ba_insert(b, d, 4);
	printf("Let's add a new element, and the new size is %d.\n", ba_size(b));
	p_d = ba_get(b, 4, "hiking", 5);
	printf("The new element is: %s, %d\n", p_d->key, p_d->value);
	d.value = 10;
	ba_set(b, 4, "hiking", 5, d.value);
	p_d = ba_get(b, 4, "hiking", 5);
	printf("Set %s to %d\n", p_d->key, p_d->value); 
	ba_insert(b, d, 20);
	ba_increase(b);
	
}
예제 #2
0
파일: port.c 프로젝트: idmf/vde2
/* initialize a new endpoint */
struct endpoint *setup_ep(int portno, int fd_ctl, int fd_data, uid_t user,
		struct mod_support *modfun)
{
	struct port *port;
	struct endpoint *ep;

	if ((portno = alloc_port(portno)) >= 0) {
		port=portv[portno];	
		if (port->ep == NULL && checkport_ac(port,user)==0)
			port->curuser=user;
		if (port->curuser == user &&
				(ep=malloc(sizeof(struct endpoint))) != NULL) {
			DBGOUT(DBGEPNEW,"Port %02d FD %2d", portno,fd_ctl);
			EVENTOUT(DBGEPNEW,portno,fd_ctl);
			port->ms=modfun;
			port->sender=modfun->sender;
			ep->port=portno;
			ep->fd_ctl=fd_ctl;
			ep->fd_data=fd_data;
			ep->descr=NULL;
#ifdef VDE_PQ2
			ep->vdepq=NULL;
			ep->vdepq_count=0;
			ep->vdepq_max=stdqlen;
#endif
			if(port->ep == NULL) {/* WAS INACTIVE */
				register int i;
				/* copy all the vlan defs to the active vlan defs */
				ep->next=port->ep;
				port->ep=ep;
				bac_FORALL(validvlan,NUMOFVLAN,
						({if (ba_check(vlant[i].table,portno)) {
						 ba_set(vlant[i].bctag,portno);
#ifdef FSTP
						 fstaddport(i,portno,(i!=port->vlanuntag));
#endif
						 }
						 }),i);
				if (port->vlanuntag != NOVLAN) {
					ba_set(vlant[port->vlanuntag].bcuntag,portno);
					ba_clr(vlant[port->vlanuntag].bctag,portno);
				}
				ba_clr(vlant[port->vlanuntag].notlearning,portno);
			} else {
예제 #3
0
void ht_put(hash_tbl_t *h, key_t nKey, int nValue) {
	uint32_t b_number = h->func->compress(h->func->hash(nkey));
	struct generic_data d;
	if(ba_get(h->buckets, b_number, nKey) == NULL) {
		d.key = key;
		d.value = value;
		ba_insert(h->buckets, d, b_number); 
	} else
		ba_set(h->buckets, b_number, key, value);
}
예제 #4
0
/* Behaviour of BitArray.set(index) */
static PyObject *
BitArray_set(BitArray *self, PyObject *args) {
    const unsigned int index;
    if(!PyArg_ParseTuple(args, "I", &index))
        return NULL;
    
    if(index > self->num_elements) {
        PyErr_SetString(PyExc_IndexError, "Index out of array bounds");
        return NULL;
    }

    ba_set(self->bitarray_pointer, index);
    return Py_BuildValue("");
}
예제 #5
0
파일: port.c 프로젝트: idmf/vde2
static int alloc_port(unsigned int portno)
{
	int i=portno;
	if (i==0) {
		/* take one */
		for (i=1;i<numports && portv[i] != NULL && 
				(portv[i]->ep != NULL || portv[i]->flag & NOTINPOOL) ;i++)
			;
	} else if (i<0) /* special case MGMT client port */
		i=0;
	if (i >= numports)
		return -1;
	else {
		if (portv[i] == NULL) {
			struct port *port;
			if ((port = malloc(sizeof(struct port))) == NULL){
				printlog(LOG_WARNING,"malloc port %s",strerror(errno));
				return -1;
			} else
			{
				DBGOUT(DBGPORTNEW,"%02d", i);
				EVENTOUT(DBGPORTNEW,i);

				portv[i]=port;
				port->ep=NULL;
				port->user=port->group=port->curuser=-1;
#ifdef FSTP
				port->cost=DEFAULT_COST;
#endif
#ifdef PORTCOUNTERS
				port->pktsin=0;
				port->pktsout=0;
				port->bytesin=0;
				port->bytesout=0;
#endif
				port->flag=0;
				port->sender=NULL;
				port->vlanuntag=0;
				ba_set(vlant[0].table,i);
			}
		}
		return i;
	}
}