struct bufferedString * nameByID (long taxID)
{
  static struct			storedNameTag queryTag;
  struct storedNameTag *	res;
  struct bufferedString * resStr = NULL;
		
  queryTag.taxID = taxID;
  res = (struct storedNameTag *)avl_find(nameTagAVL, &queryTag);
  if (res)
  {
    resStr = allocateNewString();
    appendRangeToString(resStr,globalNameBuffer,res->startIndex,res->startIndex+res->length-1);
  }
  return resStr;
}
Exemple #2
0
END_TEST

START_TEST(test_tree)
{
  avl_tree_t *tree = avl_new();
  
  avl_insert(tree, (void*)1, (void*)1234);
  avl_insert(tree, (void*)2, (void*)12345);
  avl_insert(tree, (void*)3, (void*)123456);
  avl_insert(tree, (void*)4, (void*)1234567);
  avl_insert(tree, (void*)5, (void*)12345678);
 
  fail_unless(avl_find(tree, (void*)1) == (void*)1234,
              "could not find obj 1");
  fail_unless(avl_find(tree, (void*)2) == (void*)12345,
              "could not find obj 2");
  fail_unless(avl_find(tree, (void*)3) == (void*)123456,
              "could not find obj 3");
  fail_unless(avl_find(tree, (void*)4) == (void*)1234567,
              "could not find obj 4");
  fail_unless(avl_find(tree, (void*)5) == (void*)12345678,
              "could not find obj 5");
  avl_delete(tree);
}
Exemple #3
0
static int
zil_dva_tree_add(avl_tree_t *t, dva_t *dva)
{
	zil_dva_node_t *zn;
	avl_index_t where;

	if (avl_find(t, dva, &where) != NULL)
		return (EEXIST);

	zn = kmem_alloc(sizeof (zil_dva_node_t), KM_SLEEP);
	zn->zn_dva = *dva;
	avl_insert(t, zn, where);

	return (0);
}
Exemple #4
0
void
unique_remove(uint64_t value)
{
	unique_t un_tofind;
	unique_t *un;

	un_tofind.un_value = value;
	mutex_enter(&unique_mtx);
	un = avl_find(&unique_avl, &un_tofind, NULL);
	if (un != NULL) {
		avl_remove(&unique_avl, un);
		kmem_free(un, sizeof (unique_t));
	}
	mutex_exit(&unique_mtx);
}
Exemple #5
0
int
lookup_charmap(const char *sym, wchar_t *wc)
{
	charmap_t	srch;
	charmap_t	*n;

	srch.name = sym;
	n = avl_find(&cmap_sym, &srch, NULL);
	if (n && n->wc != (wchar_t)-1) {
		if (wc)
			*wc = n->wc;
		return (0);
	}
	return (-1);
}
Exemple #6
0
/*
 * Find a zfs_snapentry_t in zfs_snapshots_by_objsetid given the objset id
 * rather than the snapname.  In all other respects it behaves the same
 * as zfsctl_snapshot_find_by_name().
 */
static zfs_snapentry_t *
zfsctl_snapshot_find_by_objsetid(spa_t *spa, uint64_t objsetid)
{
	zfs_snapentry_t *se, search;

	ASSERT(RW_LOCK_HELD(&zfs_snapshot_lock));

	search.se_spa = spa;
	search.se_objsetid = objsetid;
	se = avl_find(&zfs_snapshots_by_objsetid, &search, NULL);
	if (se)
		refcount_add(&se->se_refcount, NULL);

	return (se);
}
Exemple #7
0
static zcrypt_keychain_node_t *
zcrypt_keychain_find(avl_tree_t keychain, uint64_t txg)
{
	zcrypt_keychain_node_t search_dkn;
	zcrypt_keychain_node_t *found_dkn;
	avl_index_t where;

	search_dkn.dkn_txg = txg;
	found_dkn = avl_find(&keychain, &search_dkn, &where);
	if (found_dkn == NULL) {
		found_dkn = avl_nearest(&keychain, where, AVL_BEFORE);
	}

	return (found_dkn);
}
Exemple #8
0
static void
sa_attr_iter(objset_t *os, sa_hdr_phys_t *hdr, dmu_object_type_t type,
    sa_iterfunc_t func, sa_lot_t *tab, void *userp)
{
	void *data_start;
	sa_lot_t *tb = tab;
	sa_lot_t search;
	avl_index_t loc;
	sa_os_t *sa = os->os_sa;
	int i;
	uint16_t *length_start = NULL;
	uint8_t length_idx = 0;

	if (tab == NULL) {
		search.lot_num = SA_LAYOUT_NUM(hdr, type);
		tb = avl_find(&sa->sa_layout_num_tree, &search, &loc);
		ASSERT(tb);
	}

	if (IS_SA_BONUSTYPE(type)) {
		data_start = (void *)P2ROUNDUP(((uintptr_t)hdr +
		    offsetof(sa_hdr_phys_t, sa_lengths) +
		    (sizeof (uint16_t) * tb->lot_var_sizes)), 8);
		length_start = hdr->sa_lengths;
	} else {
		data_start = hdr;
	}

	for (i = 0; i != tb->lot_attr_count; i++) {
		int attr_length, reg_length;
		uint8_t idx_len;

		reg_length = sa->sa_attr_table[tb->lot_attrs[i]].sa_length;
		if (reg_length) {
			attr_length = reg_length;
			idx_len = 0;
		} else {
			attr_length = length_start[length_idx];
			idx_len = length_idx++;
		}

		func(hdr, data_start, tb->lot_attrs[i], attr_length,
		    idx_len, reg_length == 0 ? B_TRUE : B_FALSE, userp);

		data_start = (void *)P2ROUNDUP(((uintptr_t)data_start +
		    attr_length), 8);
	}
}
Exemple #9
0
static void
trim_map_segment_add(trim_map_t *tm, uint64_t start, uint64_t end, uint64_t txg)
{
	avl_index_t where;
	trim_seg_t tsearch, *ts_before, *ts_after, *ts;
	boolean_t merge_before, merge_after;

	ASSERT(MUTEX_HELD(&tm->tm_lock));
	VERIFY(start < end);

	tsearch.ts_start = start;
	tsearch.ts_end = end;

	ts = avl_find(&tm->tm_queued_frees, &tsearch, &where);
	if (ts != NULL) {
		if (start < ts->ts_start)
			trim_map_segment_add(tm, start, ts->ts_start, txg);
		if (end > ts->ts_end)
			trim_map_segment_add(tm, ts->ts_end, end, txg);
		return;
	}

	ts_before = avl_nearest(&tm->tm_queued_frees, where, AVL_BEFORE);
	ts_after = avl_nearest(&tm->tm_queued_frees, where, AVL_AFTER);

	merge_before = (ts_before != NULL && ts_before->ts_end == start &&
	    ts_before->ts_txg == txg);
	merge_after = (ts_after != NULL && ts_after->ts_start == end &&
	    ts_after->ts_txg == txg);

	if (merge_before && merge_after) {
		avl_remove(&tm->tm_queued_frees, ts_before);
		list_remove(&tm->tm_head, ts_before);
		ts_after->ts_start = ts_before->ts_start;
		kmem_free(ts_before, sizeof (*ts_before));
	} else if (merge_before) {
		ts_before->ts_end = end;
	} else if (merge_after) {
		ts_after->ts_start = start;
	} else {
		ts = kmem_alloc(sizeof (*ts), KM_SLEEP);
		ts->ts_start = start;
		ts->ts_end = end;
		ts->ts_txg = txg;
		avl_insert(&tm->tm_queued_frees, ts, where);
		list_insert_tail(&tm->tm_head, ts);
	}
}
Exemple #10
0
void
add_charmap_undefined(char *sym)
{
	charmap_t srch;
	charmap_t *cm = NULL;

	srch.name = sym;
	cm = avl_find(&cmap_sym, &srch, NULL);

	if ((undefok == 0) && ((cm == NULL) || (cm->wc == (wchar_t)-1))) {
		warn(_("undefined symbol <%s>"), sym);
		add_charmap_impl(sym, -1, 0);
	} else {
		free(sym);
	}
}
Exemple #11
0
static void
zfsctl_rename_snap(zfs_sb_t *zsb, zfs_snapentry_t *sep, const char *name)
{
	avl_index_t where;

	ASSERT(MUTEX_HELD(&zsb->z_ctldir_lock));
	ASSERT(sep != NULL);

	/*
	 * Change the name in the AVL tree.
	 */
	avl_remove(&zsb->z_ctldir_snaps, sep);
	(void) strcpy(sep->se_name, name);
	VERIFY(avl_find(&zsb->z_ctldir_snaps, sep, &where) == NULL);
	avl_insert(&zsb->z_ctldir_snaps, sep, where);
}
Exemple #12
0
static authzid_conn_t *
authzid_conn_find( Connection *c )
{
	authzid_conn_t *ac = NULL, tmp = { 0 };

	tmp.conn = c;
	ac = (authzid_conn_t *)avl_find( authzid_tree, (caddr_t)&tmp, authzid_conn_cmp );
	if ( ac == NULL || ( ac != NULL && ac->refcnt != 0 ) ) {
		ac = NULL;
	}
	if ( ac ) {
		ac->refcnt++;
	}

	return ac;
}
Exemple #13
0
static void
check_one_slice(avl_tree_t *r, char *diskname, uint_t partno,
    diskaddr_t size, uint_t blksz)
{
	rdsk_node_t tmpnode;
	rdsk_node_t *node;
	char sname[MAXNAMELEN];

	tmpnode.rn_name = &sname[0];
	(void) snprintf(tmpnode.rn_name, MAXNAMELEN, "%s%u",
	    diskname, partno);
	/* too small to contain a zpool? */
	if ((size < (SPA_MINDEVSIZE / blksz)) &&
	    (node = avl_find(r, &tmpnode, NULL)))
		node->rn_nozpool = B_TRUE;
}
bool existeClienteCatalogo(CATALOGO_CLIENTES catalogo, CodigoCliente_st codigo) {
	bool resultado = false;
	char letra = codigo[0];
	int i;

	if (codigo != NULL) {
		i = calculaIndiceCliente(letra);

		if (avl_find(catalogo->indice[i], codigo) != NULL) 
			resultado = true;
		else
			resultado = false;
	}

	return resultado;
}
bool existeProdutoCatalogo(CATALOGO_PRODUTOS catalogo, CodigoProduto_st codigo) {
	bool resultado = false;
	char letra = codigo[0];
	int i;

	if (codigo != NULL) {
		i = calculaIndiceProduto(letra);

		if (avl_find(catalogo->indice[i], codigo) != NULL) 
			resultado = true;
		else
			resultado = false;
	}

	return resultado;
}
Exemple #16
0
EntryInfo *
bdb_cache_find_info(
	struct bdb_info *bdb,
	ID id )
{
	EntryInfo	ei = { 0 },
			*ei2;

	ei.bei_id = id;

	ldap_pvt_thread_rdwr_rlock( &bdb->bi_cache.c_rwlock );
	ei2 = (EntryInfo *) avl_find( bdb->bi_cache.c_idtree,
					(caddr_t) &ei, bdb_id_cmp );
	ldap_pvt_thread_rdwr_runlock( &bdb->bi_cache.c_rwlock );
	return ei2;
}
Exemple #17
0
/*
 * Retrieves a map
 */
struct rewrite_builtin_map *
rewrite_builtin_map_find(
		struct rewrite_info *info,
		const char *name
)
{
	struct rewrite_builtin_map tmp;

	assert( info != NULL );
	assert( name != NULL );

	tmp.lb_name = ( char * )name;

	return ( struct rewrite_builtin_map * )avl_find( info->li_maps,
			( caddr_t )&tmp, rewrite_builtin_map_cmp );
}
Exemple #18
0
/**
 * Delete a prefix from the prefix tree hanging off a lsdb (tc) entry.
 */
void
olsr_delete_routing_table(union olsr_ip_addr *dst, int plen,
                          union olsr_ip_addr *originator)
{
#ifdef DEBUG
  struct ipaddr_str dstbuf, origbuf;
#endif

  struct tc_entry *tc;
  struct rt_path *rtp;
  struct avl_node *node;
  struct olsr_ip_prefix prefix;

  /*
   * No bogus prefix lengths.
   */
  if (plen > olsr_cnf->maxplen) {
    return;
  }

  tc = olsr_lookup_tc_entry(originator);
  if (!tc) {
    return;
  }

  /*
   * Grab the rt_path for the prefix.
   */
  prefix.prefix = *dst;
  prefix.prefix_len = plen;

  node = avl_find(&tc->prefix_tree, &prefix);

  if (node) {
    rtp = rtp_prefix_tree2rtp(node);
    olsr_delete_rt_path(rtp);

#ifdef DEBUG
    OLSR_PRINTF(1, "RIB: del prefix %s/%u from %s\n",
                olsr_ip_to_string(&dstbuf, dst), plen,
                olsr_ip_to_string(&origbuf, originator));
#endif

    /* overload the hna change bit for flagging a prefix change */
    changes_hna = OLSR_TRUE;
  }
}
container_handle_t *ofs_get_container_handle(const char *ct_name)
{
    container_handle_t *ct = NULL;
    avl_index_t where = 0;
 
    if (ct_name == NULL)
    {   /* Not allocated yet */
        LOG_ERROR("Invalid parameter. ct_name(%p)\n", ct_name);
        return NULL;
    }

    OS_RWLOCK_WRLOCK(&g_container_list_rwlock);
    ct = avl_find(g_container_list, (avl_find_fn_t)compare_container2, ct_name, &where);
    OS_RWLOCK_WRUNLOCK(&g_container_list_rwlock);
    
    return ct;
}     
Exemple #20
0
static struct avl_table *mark_chars(fo_entry * fo, struct avl_table *tx_tree,
                             internalfontnumber f)
{
    int i, *j;
    void **aa;
    if (tx_tree == NULL) {
        tx_tree = avl_create(comp_int_entry, NULL, &avl_xallocator);
        assert(tx_tree != NULL);
    }
    for (i = fo->first_char; i <= fo->last_char; i++) {
        if (pdfcharmarked(f, i) && (int *) avl_find(tx_tree, &i) == NULL) {
            j = xtalloc(1, int);
            *j = i;
            aa = avl_probe(tx_tree, j);
            assert(aa != NULL);
        }
    }
Exemple #21
0
/*
 * Locates, creates, and deletes a record of a duplicate reference.
 *
 * For DB_INCR, returns true if the dup was added to the tree.
 * For DB_DECR, returns true if the dup was in the tree.
 */
int
find_dup_ref(daddr32_t fragno, fsck_ino_t ino, daddr32_t lfn, int flags)
{
	fragment_t key;
	fragment_t *dup;
	avl_index_t where;
	int added = 0;
	int removed = 0;

	if (avl_first(&dup_frags) == NULL) {
		if (flags & DB_CREATE)
			avl_create(&dup_frags, fragment_cmp,
			    sizeof (fragment_t),
			    OFFSETOF(fragment_t, fr_avl));
		else
			return (0);
	}

	key.fr_pfn = fragno;
	dup = avl_find(&dup_frags, (void *)&key, &where);
	if ((dup == NULL) & (flags & DB_CREATE)) {
		dup = alloc_dup(fragno);
		avl_insert(&dup_frags, (void *)dup, where);
	}

	if (dup != NULL) {
		if (flags & DB_INCR) {
			if (debug)
				(void) printf(
				    "adding claim by ino %d as lfn %d\n",
				    ino, lfn);
			added = increment_claimant(dup, ino, lfn);
		} else if (flags & DB_DECR) {
			/*
			 * Note that dup may be invalidated by this call.
			 */
			removed = decrement_claimant(dup, ino, lfn);
			if (debug)
				(void) printf(
		    "check for claimant ino %d lfn %d returned %d\n",
				    ino, lfn, removed);
		}
	}

	return (added || removed || (dup != NULL));
}
Exemple #22
0
vnode_t *
vncache_lookup(struct stat *st)
{
	vnode_t tmp_vn;
	vnode_t *vp;

	tmp_vn.v_st_dev = st->st_dev;
	tmp_vn.v_st_ino = st->st_ino;

	mutex_enter(&vncache_lock);
	vp = avl_find(&vncache_avl, &tmp_vn, NULL);
	if (vp != NULL)
		vn_hold(vp);
	mutex_exit(&vncache_lock);

	return (vp);
}
Exemple #23
0
static char *
file_find(pkgfilter_t *cmd, int *len)
{
	pkgentry_t p;
	pkgentry_t *look;

	p.line = cmd->buf;
	p.pathlen = cmd->len;

	look = avl_find(list, &p, NULL);

	if (look == NULL)
		return (NULL);

	*len = look->len;
	return (look->line);
}
Exemple #24
0
/*
 * Determine whether a (COMDAT) group has already been encountered.  If so,
 * indicate that the group descriptor has an overriding group (gd_oisc).  This
 * indication triggers the ld_place_section() to discard this group, while the
 * gd_oisc information provides for complete diagnostics of the override.
 * Otherwise, this is the first occurrence of this group, therefore the group
 * descriptor is saved for future comparisons.
 */
static uintptr_t
gpavl_loaded(Ofl_desc *ofl, Group_desc *gdp)
{
	Isd_node	isd, *isdp;
	avl_tree_t	*avlt;
	avl_index_t	where;

	/*
	 * Create a groups avl tree if required.
	 */
	if ((avlt = ofl->ofl_groups) == NULL) {
		if ((avlt = libld_calloc(sizeof (avl_tree_t), 1)) == NULL)
			return (S_ERROR);
		avl_create(avlt, isdavl_compare, sizeof (Isd_node),
		    SGSOFFSETOF(Isd_node, isd_avl));
		ofl->ofl_groups = avlt;
	}

	/*
	 * An SHT_GROUP section is identified by the name of its signature
	 * symbol rather than section name. Although the section names are
	 * often unique, this is not required, and some compilers set it to
	 * a generic name like ".group".
	 */
	isd.isd_name = gdp->gd_name;
	isd.isd_hash = sgs_str_hash(isd.isd_name);

	if ((isdp = avl_find(avlt, &isd, &where)) != NULL) {
		gdp->gd_oisc = isdp->isd_isp;
		return (1);
	}

	/*
	 * This is a new group - so keep it.
	 */
	if ((isdp = libld_calloc(sizeof (Isd_node), 1)) == NULL)
		return (S_ERROR);

	isdp->isd_name = isd.isd_name;
	isdp->isd_hash = isd.isd_hash;
	isdp->isd_isp = gdp->gd_isc;

	avl_insert(avlt, isdp, where);
	return (0);
}
Exemple #25
0
extern "C" int
ndb_aset_get( struct ndb_info *ni, struct berval *sname, struct berval *attrs, NdbOcInfo **ret )
{
	NdbOcInfo *oci, octmp;
	int i, rc;

	octmp.no_name = *sname;
	oci = (NdbOcInfo *)avl_find( ni->ni_oc_tree, &octmp, ndb_name_cmp );
	if ( oci )
		return LDAP_ALREADY_EXISTS;

	for ( i=0; !BER_BVISNULL( &attrs[i] ); i++ ) {
		if ( !at_bvfind( &attrs[i] ))
			return LDAP_NO_SUCH_ATTRIBUTE;
	}
	i++;

	oci = (NdbOcInfo *)ch_calloc( 1, sizeof( NdbOcInfo ) + sizeof( ObjectClass ) +
		i*sizeof(AttributeType *) + sname->bv_len+1 );
	oci->no_oc = (ObjectClass *)(oci+1);
	oci->no_oc->soc_required = (AttributeType **)(oci->no_oc+1);
	oci->no_table.bv_val = (char *)(oci->no_oc->soc_required+i);

	for ( i=0; !BER_BVISNULL( &attrs[i] ); i++ )
		oci->no_oc->soc_required[i] = at_bvfind( &attrs[i] );

	strcpy( oci->no_table.bv_val, sname->bv_val );
	oci->no_table.bv_len = sname->bv_len;
	oci->no_name = oci->no_table;
	oci->no_oc->soc_cname = oci->no_name;
	oci->no_flag = NDB_INFO_ATSET;

	if ( !ber_bvcmp( sname, &slap_schema.si_oc_extensibleObject->soc_cname ))
		oci->no_oc->soc_kind = slap_schema.si_oc_extensibleObject->soc_kind;

	rc = ndb_oc_create( ni, oci, 0 );
	if ( !rc )
		rc = avl_insert( &ni->ni_oc_tree, oci, ndb_name_cmp, avl_dup_error );
	if ( rc ) {
		ch_free( oci );
	} else {
		*ret = oci;
	}
	return rc;
}
Exemple #26
0
/**
 * 从一个表索引中删除该索引
 * @param idx {ACL_MDT_IDX*} 表索引
 * @param rec {ACL_MDT_REC*} 索引表中对应某个键的结果集对象
 * @param key_value {const char*} 数据结点的引用结点的引用键值
 */
static void mdt_idx_del(ACL_MDT_IDX *idx, const char *key)
{
	const char *myname = "mdt_idx_del";
	ACL_MDT_IDX_AVL *idx_avl = (ACL_MDT_IDX_AVL*) idx;
	TREE_NODE node, *pnode;

	node.key.c_key = key;
	pnode = (TREE_NODE*) avl_find(&idx_avl->avl, &node, NULL);
	if (pnode == NULL)
		acl_msg_fatal("%s: key(%s) not exist", myname, key);
	avl_remove(&idx_avl->avl, pnode);
	if (!(idx->flag & ACL_MDT_FLAG_KMR))
		acl_myfree(pnode->key.key);
	if (idx_avl->slice)
		acl_slice_free2(idx_avl->slice, pnode);
	else
		acl_myfree(pnode);
}
Exemple #27
0
void epdf_mark_glyphs(fd_entry * fd, char *charset)
{
    char *p, *q, *s;
    char *glyph;
    void **aa;
    if (charset == NULL)
        return;
    assert(fd != NULL);
    for (s = charset + 1, q = charset + strlen(charset); s < q; s = p + 1) {
        for (p = s; *p != '\0' && *p != '/'; p++);
        *p = '\0';
        if ((char *) avl_find(fd->gl_tree, s) == NULL) {
            glyph = xstrdup(s);
            aa = avl_probe(fd->gl_tree, glyph);
            assert(aa != NULL);
        }
    }
}
intptr_t delete_table( Table* table, intptr_t cle ) {
    intptr_t valeur = (intptr_t) NULL;
    Table_association* asso_tree = NULL;
    Table_association* asso = creer_table_association(
                                  table, cle, (intptr_t) NULL
                              );
    void* val = avl_find( table->root, (void*) asso );
    if( val ) {
        asso_tree = ( Table_association* ) val;
        valeur = asso_tree->valeur;
    }
    avl_delete( table->root, (void*) asso );
    if(asso_tree) {
        supprimer_table_association( asso_tree );
    }
    supprimer_table_association( asso );
    return valeur;
}
Exemple #29
0
Fichier : fs.c Projet : asac/procd
int add_mount(const char *path, int readonly, int error)
{
	assert(path != NULL);

	if (avl_find(&mounts, path))
		return 1;

	struct mount *m;
	m = calloc(1, sizeof(struct mount));
	assert(m != NULL);
	m->avl.key = m->path = strdup(path);
	m->readonly = readonly;
	m->error = error;

	avl_insert(&mounts, &m->avl);
	DEBUG("adding mount %s ro(%d) err(%d)\n", m->path, m->readonly, m->error != 0);
	return 0;
}
Exemple #30
0
/*
 * Add a new node to an AVL tree.
 */
void
avl_add(avl_tree_t *tree, void *new_node)
{
	avl_index_t where;

	/*
	 * This is unfortunate.  We want to call panic() here, even for
	 * non-DEBUG kernels.  In userland, however, we can't depend on anything
	 * in libc or else the rtld build process gets confused.  So, all we can
	 * do in userland is resort to a normal ASSERT().
	 */
	if (avl_find(tree, new_node, &where) != NULL)
#ifdef _KERNEL
		panic("avl_find() succeeded inside avl_add()");
#else
		//ASSERT(0);
#endif
	avl_insert(tree, new_node, where);
}