int insert_in_list(List **list, char *content, int index) {
  List *ptr_to_node_prior;
  List *next_to_assign;

  /* handle index parameter less than 0 */
  if (index < 0) {
    return 0;
  }
  
  /* else, if index parameter 0 or list is empty */
  if (index == 0 || *list == NULL) {
    /* simply run add_node to make new node head */
    return add_node(list, content);
  }

  /* ELSE */
  /* find the node prior to node we want to insert */
  ptr_to_node_prior = find_node_prior(*list, index);

  /* if index req'd greater than size of list */
  if (ptr_to_node_prior == NULL) {
    /* make next val for new node NULL (make new node equivalent to tail of list) */
    next_to_assign = NULL;
    ptr_to_node_prior = find_end_of_list(list);
  } else {
    /* store next value of node prior */
    next_to_assign = ptr_to_node_prior->next;
  }

  /* create node we want to insert, with input string & the next val of the node prior, & insert in list */
  return insert_new_node(ptr_to_node_prior, content, next_to_assign);
}
Beispiel #2
0
node_t* insert_function_node(node_t* parent, node_function f, uint64_t m, uint64_t n, char** input_names, char** output_names, char* node_name) {
  node_t* result = insert_new_node(parent,m,n);
  if(result) {
    result->function = f;
    result->input_names = input_names;
    result->output_names = output_names;
    result->node_name = node_name;
    result->subnodes = NULL;
    result->k = 0;
    result->ncxn = 0;
    result->cxn = NULL;
  }
  return result;
}
Beispiel #3
0
node_t* insert_constant_node(node_t* parent, void* output_constant, char* node_name) {
  node_t* result = insert_new_node(parent,0,1);
  if(result) {
    result->output_constant = output_constant;
    result->output_names = constant_output_names;
    result->node_name = node_name;
    result->input_names  = NULL;
    result->function = NULL;
    result->subnodes = NULL;
    result->k = 0;
    result->ncxn = 0;
    result->cxn = NULL;
  }
  return result;
}
Beispiel #4
0
void insert_node(struct Node **root, int value) {
    struct Node *new_node, *conductor;
    new_node = malloc(sizeof(struct Node));
    new_node->right = NULL;
    new_node->left= NULL;
    conductor = *root;

    if(conductor == NULL) {
        new_node->value = value;
        *root = new_node;
        printf("Root node created! Value is %d.\n", new_node->value);
    } else {
        void insert_new_node() {
            if(value < conductor->value) {
                if(conductor->left != NULL) {
                    conductor = conductor->left; 
                    insert_new_node();
                } else {
                    conductor->left = new_node;
                    new_node->value = value;
                    printf("Left node created! Value is %d.\n", new_node->value);
                }
            } else if (value > conductor->value) {
                if(conductor->right != NULL) {
                    conductor = conductor->right; 
                    insert_new_node();
                } else {
                    conductor->right = new_node;
                    new_node->value = value;
                    printf("Right node created! Value is %d.\n", new_node->value);
                }
            }
        }
        insert_new_node();
    }
}
Beispiel #5
0
void sd_inode_set_vid(write_node_fn writer, read_node_fn reader,
		      struct sd_inode *inode, uint32_t idx, uint32_t vdi_id)
{
	struct sd_extent_header *header;
	struct find_path path;
	int ret;

	path.p_ext_header = NULL;

	if (inode->store_policy == 0)
		inode->data_vdi_id[idx] = vdi_id;
	else {
		if (inode->data_vdi_id[0] == 0)
			sd_inode_init(inode->data_vdi_id, 1);
		header = EXT_HEADER(inode->data_vdi_id);
		if (header->magic != INODE_BTREE_MAGIC)
			panic("%s() B-tree in inode is corrupt!", __func__);
		while (1) {
			memset(&path, 0, sizeof(path));
			ret = search_whole_btree(reader, inode, idx, &path);
			if (ret == SD_RES_BTREE_FOUND) {
				path.p_ext->vdi_id = vdi_id;
				goto out;
			} else {
				ret = insert_new_node(writer, reader, inode,
						&path, idx, vdi_id);
				if (SD_RES_BTREE_REPEAT == ret) {
					if (path.p_ext_header)
						free(path.p_ext_header);
					continue;
				} else
					goto out;
			}
		}
	}
out:
	if (path.p_ext_header)
		free(path.p_ext_header);
	dump_btree(reader, inode);
}