FreeBSD/sys/kern/subr_pctrie.c
/*
 * Inserts the key-value pair into the trie.
 * Panics if the key already exists.
 */
Inserts the key-value pair into the trie.
Panics if the key already exists.
Inserts the key - value pair into the trie . Panics if the key already exists .
int
pctrie_insert(struct pctrie *ptree, uint64_t *val, pctrie_alloc_t allocfn)
{
	uint64_t index, newind;
	void **parentp;
	struct pctrie_node *node, *tmp;
	uint64_t *m;
	int slot;
	uint16_t clev;
	index = *val;
	node = pctrie_getroot(ptree);
	if (node == NULL) {
		ptree->pt_root = (uintptr_t)val | PCTRIE_ISLEAF;
		return (0);
	}
	parentp = (void **)&ptree->pt_root;
	for (;;) {
		if (pctrie_isleaf(node)) {
			m = pctrie_toval(node);
			if (*m == index)
				panic("%s: key %jx is already present",
				    __func__, (uintmax_t)index);
			clev = pctrie_keydiff(*m, index);
			tmp = pctrie_node_get(ptree, allocfn,
			    pctrie_trimkey(index, clev + 1), 2, clev);
			if (tmp == NULL)
				return (ENOMEM);
			*parentp = tmp;
			pctrie_addval(tmp, index, clev, val);
			pctrie_addval(tmp, *m, clev, m);
			return (0);
		} else if (pctrie_keybarr(node, index))
			break;
		slot = pctrie_slot(index, node->pn_clev);
		if (node->pn_child[slot] == NULL) {
			node->pn_count++;
			pctrie_addval(node, index, node->pn_clev, val);
			return (0);
		}
		parentp = &node->pn_child[slot];
		node = node->pn_child[slot];
	}
	newind = node->pn_owner;
	clev = pctrie_keydiff(newind, index);
	tmp = pctrie_node_get(ptree, allocfn,
	    pctrie_trimkey(index, clev + 1), 2, clev);
	if (tmp == NULL)
		return (ENOMEM);
	*parentp = tmp;
	pctrie_addval(tmp, index, clev, val);
	slot = pctrie_slot(newind, clev);
	tmp->pn_child[slot] = node;
	return (0);
}
int pctrie_insert ( struct pctrie * ptree , uint64_t * val , pctrie_alloc_t allocfn ) { uint64_t index , newind ; void * * parentp ; struct pctrie_node * node , * tmp ; uint64_t * m ; int slot ; uint16_t clev ; index = * val ; node = pctrie_getroot ( ptree ) ; if ( node == NULL ) { ptree -> pt_root = ( uintptr_t ) val | PCTRIE_ISLEAF ; return ( 0 ) ; } parentp = ( void * * ) & ptree -> pt_root ; for ( ; ; ) { if ( pctrie_isleaf ( node ) ) { m = pctrie_toval ( node ) ; if ( * m == index ) panic ( " " , __func__ , ( uintmax_t ) index ) ; clev = pctrie_keydiff ( * m , index ) ; tmp = pctrie_node_get ( ptree , allocfn , pctrie_trimkey ( index , clev + 1 ) , 2 , clev ) ; if ( tmp == NULL ) return ( ENOMEM ) ; * parentp = tmp ; pctrie_addval ( tmp , index , clev , val ) ; pctrie_addval ( tmp , * m , clev , m ) ; return ( 0 ) ; } else if ( pctrie_keybarr ( node , index ) ) break ; slot = pctrie_slot ( index , node -> pn_clev ) ; if ( node -> pn_child [ slot ] == NULL ) { node -> pn_count ++ ; pctrie_addval ( node , index , node -> pn_clev , val ) ; return ( 0 ) ; } parentp = & node -> pn_child [ slot ] ; node = node -> pn_child [ slot ] ; } newind = node -> pn_owner ; clev = pctrie_keydiff ( newind , index ) ; tmp = pctrie_node_get ( ptree , allocfn , pctrie_trimkey ( index , clev + 1 ) , 2 , clev ) ; if ( tmp == NULL ) return ( ENOMEM ) ; * parentp = tmp ; pctrie_addval ( tmp , index , clev , val ) ; slot = pctrie_slot ( newind , clev ) ; tmp -> pn_child [ slot ] = node ; return ( 0 ) ; }
Inserts the key-value pair into the trie.
Inserts the key - value pair into the trie .
/*
	 * The owner of record for root is not really important because it
	 * will never be used.
	 */ /*
	 * A new node is needed because the right insertion level is reached.
	 * Setup the new intermediate node and add the 2 children: the
	 * new object and the older edge.
	 */