示例#1
0
static Patricia::status
insert_between(
  Patricia::node* const parent,
  Patricia::node* const child,
  Patricia::node* const inserted,
  Trieable* const val
)
{
  assert((NULL != parent)); /* child can be NULL */
  if ((NULL == inserted) || (NULL == val))
  {
    delete inserted;
    delete val;
    Patricia::status const result = { ENOMEM };
    return result;
  }

  parent->child[val->bit(parent->branch)] = inserted;
  *inserted = fill_node(parent, val);
  if (NULL != child)
  {
    Patricia::node const* const data = first_data_node(child);
    assert(NULL != data); /* otherwise child would be NULL */
    assert(val->len() < data->val->len()); /* branch value order in trie */
    inserted->child[data->val->bit(val->len())] = child;
    child->parent = inserted;
  }
  Patricia::status const result = { 0 };
  return result;
}
示例#2
0
/*
 * callback provided to pmdaFetch
 */
static int
pmda_ctdb_fetch_cb(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom)
{
	int ret;
	__pmID_int *id = (__pmID_int *)&(mdesc->m_desc.pmid);

	if (inst != PM_IN_NULL) {
		return PM_ERR_INST;
	}

	if (stats == NULL) {
		fprintf(stderr, "stats not available\n");
		ret = PM_ERR_VALUE;
		goto err_out;
	}


	switch (id->cluster) {
	case 0:
		ret = fill_base(id->item, atom);
		if (ret) {
			goto err_out;
		}
		break;
	case 1:
		ret = fill_node(id->item, atom);
		if (ret) {
			goto err_out;
		}
		break;
	case 2:
		ret = fill_client(id->item, atom);
		if (ret) {
			goto err_out;
		}
		break;
	case 3:
		ret = fill_timeout(id->item, atom);
		if (ret) {
			goto err_out;
		}
		break;
	default:
		return PM_ERR_PMID;
	}

	ret = 0;
err_out:
	return ret;
}
void
push_back(struct node **root, struct node data)
{
    struct node *p = *root;

    if (p == NULL) {
        struct node* p = (struct node*)malloc(sizeof(struct node));
        init_empty_node(p);
        fill_node(p, data);
        *root = p;
        return;
    }

    for (;;) {
        if (p->next_node != NULL) {
            p = p->next_node;
        } else {
            p->next_node = malloc(sizeof(struct node));
            init_empty_node(p->next_node);
            fill_node(p->next_node, data);
            return;
        }
    }
}
示例#4
0
void fill_node(node *nd,int *Access, int ipos)
{
	int i,j,k;
	nd->n=Access[ipos];

	nd->t=Access[ipos+1];
	
	nd->child=new node [nd->n];
	for (i=0;i<nd->n;i++)
	{
		k=Access[ipos+2+i];
		if (k<0) nd->child[i].n=k;
		else
		{
			j=find_index(Access,k);
			fill_node(&nd->child[i],Access,j);
		}
	}
}
示例#5
0
static Patricia::status
branch_at(
  Patricia::node* const child,
  Patricia::node* const branched,
  Patricia::node* const inserted,
  Trieable* const val
)
{
  assert(NULL != child);
  if ((NULL == branched) || (NULL == inserted) || (NULL == val))
  {
    delete branched;
    delete inserted;
    delete val;
    Patricia::status result = { ENOMEM };
    return result;
  }
  /* find first differing bit for child[] of the new branch node */
  Patricia::node const * const data = first_data_node(child);
  assert(NULL != data); /* otherwise child would be NULL */
  std::size_t const branch = child->parent->branch;
  Trieable::difference const diff = data->val->diff(*val, branch);
  assert(true == diff.diff); /* replacing parent's old child with branch */
  assert((branch < diff.bit) && (diff.bit < child->branch));
  assert(val->bit(branch) == data->val->bit(branch)); /* same prefix */

  child->parent->child[val->bit(branch)] = branched;
  branched->parent = child->parent;
  branched->child[data->val->bit(diff.bit)] = child;
  branched->child[val->bit(diff.bit)] = inserted;
  branched->branch = diff.bit;
  branched->val = NULL;
  child->parent = branched;
  *inserted = fill_node(branched, val);

  Patricia::status const result = { 0 };
  return result;
}
示例#6
0
node::node(int *Access)
{
	fill_node(this,Access,0);
}
示例#7
0
/*****
*   User created Social Network
*
*   Allows user to simulate their own social network
*   Hashes user names and creates UID matrix
*   Assigns interests at random
*   Creates similarity matricies
*/
int build_graph(int*** uu, int*** ii, int*** interests, int** uid){
    int opt=0, m;
    node *head = NULL, *cur=NULL, *ref=NULL, *parent=NULL;
    char**  name;

    while(1){
        printf(GRAPH_MENU);
        scanf("%d", &opt);

        switch(opt){
            case 0: 
                m = list_length(head); // Network Size
                to_array(head, uid); // UIDs
                assign_interests(m, interests, END); // Interest Matrix
                similarity(m, *interests, uu, ii); // Similarities
                HEAD = head;

                return m;
            case 1: // Add Node
                ref = get_node();
                name = get_name();
                fill_node(ref,name);
                head = add_node(head, ref);
                cur = head;
                break;

            case 2: // Add Friend
                if(cur != NULL)
                    name = get_name();

                    if(search(head, name, &parent) == NULL){ //Friend Doesn't Exist Yet
                        ref = get_node();
                        fill_node(ref, name);
                        head = add_node(head, ref);
                    }
                    else 
                        ref = search(head, name, &parent);

                    add_friend(cur, name);
                    add_friend(ref, cur->name);
                break;

            case 3: // Switch Node
                cur = search(head, get_name(), &parent);
                break;

            case 4: // View Nodes
                print_list(head);
                break;

            case 5: // View Friends
                printf("%s %s's Friends: \n", cur->name[0], cur->name[1]);
                if(cur != NULL)
                    view_leaf(cur->root);

                printf("\n");
                break;

            default: printf("Invalid Option\n");
        }
    }
}