Example #1
0
/*	Set the slice of LDAPValueList between `ilow` and `ihigh` to the contents of `itemlist`.
	The `itemlist` must be containing unique elements. New items are append to the added list,
	and removed items are append to the deleted list. The `itemlist` may be NULL, indicating
	the assignment of an empty list (slice deletion).
*/
int
LDAPValueList_SetSlice(LDAPValueList *self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *itemlist) {
	PyObject *remove;

	/* Copying the removable items from LDAPValueList to deleted list.*/
	remove = PyList_GetSlice((PyObject *)self, ilow, ihigh);
	if (remove == NULL) return -1;
	if (balancing(remove, self->added) != 0) {
		Py_DECREF(remove);
		return -1;
	}
	if (UniqueList_Extend(self->deleted, remove) != 0) {
		Py_DECREF(remove);
		return -1;
	}
	Py_DECREF(remove);

	/* Copying new items to the added list.*/
	if (itemlist != NULL) {
		if (balancing(itemlist, self->deleted) != 0) return -1;
		if (UniqueList_Extend(self->added, itemlist) != 0) return -1;
	}

    return UniqueList_SetSlice((UniqueList *)self, ilow, ihigh, itemlist);
}
Example #2
0
int
LDAPValueList_Extend(LDAPValueList *self, PyObject *b) {
	if (balancing(b, self->deleted) != 0) return -1;
	if (UniqueList_Extend(self->added, b) != 0) return -1;
	if (UniqueList_Extend((UniqueList *)self, b) != 0) return -1;
	return 0;
}
Example #3
0
int* kPartitioning(double ** comm, int n, int k, int * constraints, int nb_constraints, int greedy_trials)
{
  /* ##### declarations & allocations ##### */

  PriorityQueue Qpart, *Q = NULL, *Qinst = NULL;
  double **D = NULL;
  int deficit, surplus, *part = NULL;
  int real_n = n-nb_constraints;

  part = build_p_vector(comm, n, k, greedy_trials, constraints, nb_constraints);

  memory_allocation(&Q, &Qinst, &D, real_n, k);

  /* ##### Initialization ##### */

  initialization(part, comm, &Qpart, Q, Qinst, D, real_n, k, &deficit, &surplus);

  /* ##### Main loop ##### */
  while((nextGain(&Qpart, Q, &deficit, &surplus))>0)
    {
      algo(part, comm, &Qpart, Q, Qinst, D, real_n, &deficit, &surplus);
    }

  /* ##### Balancing the partition  ##### */
  balancing(real_n, deficit, surplus, D, part); /*if partition isn't balanced we have to make one last move*/

  /* ##### Memory deallocation ##### */
  destruction(&Qpart, Q, Qinst, D, real_n, k);

  return part;
}
Example #4
0
avl_node* insert(avl_node *root,int data) {
    if (root == NULL) {
        root = (avl_node*) malloc(sizeof(avl_node));
        
        root->data = data;
        
        root->left = NULL;
        root->right = NULL;
        
        return root;
    } else if (data < root->data) {
        root->left = insert(root->left, data);
        root = balancing(root);
    } else if (data > root->data) {
        root->right = insert(root->right, data);
        root = balancing(root);
    }
    
    return root;
}
Example #5
0
NodeT *insertNode(NodeT *p,int x)
{
    if(p==NULL)
    {
        return createNode(x);
    }
    else
    {
        if(p->key>x)
        {
            p->left=insertNode(p->left,x);
        }
        else if(p->key<x)
        {
            p->right=insertNode(p->right,x);
        }
        else
        {
            printf("The node already exists!\n");
        }
        p=balancing(p);
        return p;
    }
}