当前位置: 首页>>代码示例>>C++>>正文


C++ RB_FIND函数代码示例

本文整理汇总了C++中RB_FIND函数的典型用法代码示例。如果您正苦于以下问题:C++ RB_FIND函数的具体用法?C++ RB_FIND怎么用?C++ RB_FIND使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了RB_FIND函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sizeof

static const lang_code_t *_lang_code_get ( const char *code, size_t len )
{
  int i;
  char tmp[4];
  
  if (lang_codes_code2b == NULL) {
    const lang_code_t *c = lang_codes;

    lang_codes_code2b = (lang_code_lookup_t *)calloc(1, sizeof(lang_code_lookup_t));
    lang_codes_code1 = (lang_code_lookup_t *)calloc(1, sizeof(lang_code_lookup_t));
    lang_codes_code2t = (lang_code_lookup_t *)calloc(1, sizeof(lang_code_lookup_t));

    while (c->code2b) {
      _lang_code_lookup_add(lang_codes_code2b, c, _lang_code2b_cmp);
      if (c->code1) _lang_code_lookup_add(lang_codes_code1, c, _lang_code1_cmp);
      if (c->code2t) _lang_code_lookup_add(lang_codes_code2t, c, _lang_code2t_cmp);
      c++;
    }
  }

  if (code && *code && len) {

    /* Extract the code (lowercase) */
    i = 0;
    while (i < 3 && *code && len) {
      if (*code == ';' || *code == ',' || *code == '-') break;
      if (*code != ' ')
        tmp[i++] = *code | 0x20; // |0x20 = lower case
      code++;
      len--;
    }
    tmp[i] = '\0';

    /* Convert special case (qaa..qtz) */
    if (*tmp == 'q') {
      if (tmp[1] >= 'a' && tmp[1] <= 'z' && tmp[2] >= 'a' && tmp[2] <= 'z') {
        tmp[1] = 'a';
        tmp[2] = 'a';
      }
    }

    /* Search */
    if (i) {
      lang_code_lookup_element_t sample, *element;
      lang_code_t lang_code;
      lang_code.code1 = tmp;
      lang_code.code2b = tmp;
      lang_code.code2t = tmp;
      sample.lang_code = &lang_code;
      element = RB_FIND(lang_codes_code2b, &sample, link, _lang_code2b_cmp);
      if (element != NULL) return element->lang_code;
      element = RB_FIND(lang_codes_code1, &sample, link, _lang_code1_cmp);
      if (element != NULL) return element->lang_code;
      element = RB_FIND(lang_codes_code2t, &sample, link, _lang_code2t_cmp);
      if (element != NULL) return element->lang_code;
    }
  }
  return &lang_codes[0];
}
开发者ID:Leyorus,项目名称:tvheadend,代码行数:59,代码来源:lang_codes.c

示例2: options_find

struct options_entry *
options_find(struct options *oo, const char *name)
{
	struct options_entry	*o, p;

	p.name = (char *)name;
	o = RB_FIND(options_tree, &oo->tree, &p);
	while (o == NULL) {
		oo = oo->parent;
		if (oo == NULL)
			break;
		o = RB_FIND(options_tree, &oo->tree, &p);
	}
	return (o);
}
开发者ID:20400992,项目名称:tmux,代码行数:15,代码来源:options.c

示例3: cmd_bind_key_mode_table

static enum cmd_retval
cmd_bind_key_mode_table(struct cmd *self, struct cmdq_item *item, key_code key)
{
	struct args			*args = self->args;
	const char			*tablename;
	const struct mode_key_table	*mtab;
	struct mode_key_binding		*mbind, mtmp;
	enum mode_key_cmd		 cmd;

	tablename = args_get(args, 't');
	if ((mtab = mode_key_findtable(tablename)) == NULL) {
		cmdq_error(item, "unknown key table: %s", tablename);
		return (CMD_RETURN_ERROR);
	}

	cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]);
	if (cmd == MODEKEY_NONE) {
		cmdq_error(item, "unknown command: %s", args->argv[1]);
		return (CMD_RETURN_ERROR);
	}

	if (args->argc != 2) {
		cmdq_error(item, "no argument allowed");
		return (CMD_RETURN_ERROR);
	}

	mtmp.key = key;
	if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) == NULL) {
		mbind = xmalloc(sizeof *mbind);
		mbind->key = mtmp.key;
		RB_INSERT(mode_key_tree, mtab->tree, mbind);
	}
	mbind->cmd = cmd;
	return (CMD_RETURN_NORMAL);
}
开发者ID:CraZySacX,项目名称:tmux,代码行数:35,代码来源:cmd-bind-key.c

示例4: api_exec

int
api_exec ( const char *subsystem, htsmsg_t *args, htsmsg_t **resp )
{
  api_hook_t h;
  api_link_t *ah, skel;
  const char *op;

  /* Args and response must be set */
  if (!args || !resp || !subsystem)
    return EINVAL;

  // Note: there is no locking while checking the hook tree, its assumed
  //       this is all setup during init (if this changes the code will
  //       need updating)
  h.ah_subsystem = subsystem;
  skel.hook      = &h;
  ah = RB_FIND(&api_hook_tree, &skel, link, ah_cmp);

  if (!ah) {
    tvhwarn("api", "failed to find subsystem [%s]", subsystem);
    return ENOSYS; // TODO: is this really the right error code?
  }

  /* Extract method */
  op = htsmsg_get_str(args, "method");
  if (!op)
    op = htsmsg_get_str(args, "op");
  // Note: this is not required (so no final validation)

  /* Execute */
  return ah->hook->ah_callback(ah->hook->ah_opaque, op, args, resp);
}
开发者ID:BATYD-Turksat,项目名称:tvheadend,代码行数:32,代码来源:api.c

示例5: RB_FIND

struct tupid_tree *tupid_tree_search(struct tupid_entries *root, tupid_t tupid)
{
	struct tupid_tree tt = {
		.tupid = tupid,
	};
	return RB_FIND(tupid_entries, root, &tt);
}
开发者ID:erikbrinkman,项目名称:tup,代码行数:7,代码来源:tupid_tree.c

示例6: intlconv_utf8

ssize_t
intlconv_utf8( char *dst, size_t dst_size,
               const char *dst_charset_id,
               const char *src_utf8 )
{
  intlconv_cache_t templ, *ic;
  char **inbuf, **outbuf;
  size_t inbuf_left, outbuf_left;
  ssize_t res;

  if (dst_charset_id == NULL) {
    strncpy(dst, src_utf8, dst_size);
    dst[dst_size - 1] = '\0';
    return strlen(dst);
  }
  templ.ic_charset_id = (char *)dst_charset_id;
  pthread_mutex_lock(&intlconv_lock);
  if (intlconv_last_ic &&
      strcmp(intlconv_last_ic->ic_charset_id, dst_charset_id) == 0) {
    ic = intlconv_last_ic;
    goto found;
  }
  ic = RB_FIND(&intlconv_all, &templ, ic_link, intlconv_cmp);
  if (!ic) {
    iconv_t c = iconv_open(dst_charset_id, "UTF-8");
    if ((iconv_t)-1 == c) {
      pthread_mutex_unlock(&intlconv_lock);
      return -EIO;
    }
    ic = malloc(sizeof(*ic));
    if (ic == NULL) {
      pthread_mutex_unlock(&intlconv_lock);
      return -ENOMEM;
    }
    ic->ic_charset_id = strdup(dst_charset_id);
    if (ic->ic_charset_id == NULL) {
      pthread_mutex_unlock(&intlconv_lock);
      free(ic);
      iconv_close(c);
      return -ENOMEM;
    }
    ic->ic_handle = c;
    RB_INSERT_SORTED(&intlconv_all, ic, ic_link, intlconv_cmp);
  }
found:
  inbuf       = (char **)&src_utf8;
  inbuf_left  = strlen(src_utf8);
  outbuf      = &dst;
  outbuf_left = dst_size;
  res = iconv(ic->ic_handle, inbuf, &inbuf_left, outbuf, &outbuf_left);
  if (res == -1) {
    res = -errno;
  } else {
    intlconv_last_ic = ic;
  }
  pthread_mutex_unlock(&intlconv_lock);
  if (res >= 0)
    res = dst_size - outbuf_left;
  return res;
}
开发者ID:BATYD-Turksat,项目名称:tvheadend,代码行数:60,代码来源:intlconv.c

示例7: RB_FIND

struct evcpe_dns_entry *evcpe_dns_cache_find(struct evcpe_dns_cache *cache,
		const char *name)
{
	struct evcpe_dns_entry find;
	find.name = (char *)name;
	return RB_FIND(evcpe_dns_cache, cache, &find);
}
开发者ID:b1l1s,项目名称:open-tr069,代码行数:7,代码来源:dns_cache.c

示例8: ct_getloginbyuid

char *
ct_getloginbyuid(uid_t uid)
{
	struct passwd *passwd;
	struct ct_login_cache *entry, search;

	search.lc_uid = uid;

	entry = RB_FIND(ct_login_cache_tree, &ct_login_cache, &search);

	if (entry != NULL) {
		return entry->lc_name;
	}

	/* if the cache gets too big, dump all entries and refill. */
	if (ct_login_cache_size > MAX_LC_CACHE_SIZE) {
		ct_cleanup_login_cache();
	}

	/* yes, this even caches negative entries */
	ct_login_cache_size++;

	entry = e_calloc(1, sizeof(*entry));
	entry->lc_uid = uid;

	passwd = getpwuid(uid);
	if (passwd)
		entry->lc_name = e_strdup(passwd->pw_name);
	else
		entry->lc_name = NULL; /* entry not found cache NULL */

	RB_INSERT(ct_login_cache_tree, &ct_login_cache, entry);

	return entry->lc_name;
}
开发者ID:finid,项目名称:cyphertite,代码行数:35,代码来源:ct_main.c

示例9: pfi_kif_get

struct pfi_kif *
pfi_kif_get(const char *kif_name)
{
	struct pfi_kif		*kif;
	struct pfi_kif_cmp	 s;

	bzero(&s, sizeof(s));
	strlcpy(s.pfik_name, kif_name, sizeof(s.pfik_name));
	if ((kif = RB_FIND(pfi_ifhead, &pfi_ifs, (struct pfi_kif *)&s)) != NULL)
		return (kif);

	/* create new one */
	if ((kif = malloc(sizeof(*kif), PFI_MTYPE, M_NOWAIT|M_ZERO)) == NULL)
		return (NULL);

	strlcpy(kif->pfik_name, kif_name, sizeof(kif->pfik_name));
#ifdef __NetBSD__
	/* time_second is not valid yet */
	kif->pfik_tzero = (time_second > 7200) ? time_second : 0;
#else
	kif->pfik_tzero = time_second;
#endif /* !__NetBSD__ */
	TAILQ_INIT(&kif->pfik_dynaddrs);

	RB_INSERT(pfi_ifhead, &pfi_ifs, kif);
	return (kif);
}
开发者ID:ryo,项目名称:netbsd-src,代码行数:27,代码来源:pf_if.c

示例10: cmd_bind_key_table

int
cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
{
	struct args			*args = self->args;
	const char			*tablename;
	const struct mode_key_table	*mtab;
	struct mode_key_binding		*mbind, mtmp;
	enum mode_key_cmd		 cmd;

	tablename = args_get(args, 't');
	if ((mtab = mode_key_findtable(tablename)) == NULL) {
		ctx->error(ctx, "unknown key table: %s", tablename);
		return (-1);
	}

	cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]);
	if (cmd == MODEKEY_NONE) {
		ctx->error(ctx, "unknown command: %s", args->argv[1]);
		return (-1);
	}

	mtmp.key = key;
	mtmp.mode = !!args_has(args, 'c');
	if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
		mbind->cmd = cmd;
		return (0);
	}
	mbind = xmalloc(sizeof *mbind);
	mbind->key = mtmp.key;
	mbind->mode = mtmp.mode;
	mbind->cmd = cmd;
	RB_INSERT(mode_key_tree, mtab->tree, mbind);
	return (0);
}
开发者ID:tomykaira,项目名称:tmux-1.6,代码行数:34,代码来源:cmd-bind-key.c

示例11: flexran_agent_destroy_channel

int flexran_agent_destroy_channel(int channel_id) {
  int i, j;

  /*Check to see if channel exists*/
  struct flexran_agent_channel_s *e = NULL;
  struct flexran_agent_channel_s search;
  memset(&search, 0, sizeof(struct flexran_agent_channel_s));

  e = RB_FIND(flexran_agent_channel_map, &channel_instance.flexran_agent_head, &search);

  if (e == NULL) {
    return -1;
  }

  /*Unregister the channel from all agents*/
  for (i = 0; i < NUM_MAX_ENB; i++) {
    for (j = 0; j < FLEXRAN_AGENT_MAX; j++) {
      if (agent_channel[i][j] != NULL) {
	if (agent_channel[i][j]->channel_id == e->channel_id) {
	  agent_channel[i][j] == NULL;
	}
      }
    }
  }

  /*Remove the channel from the tree and free memory*/
  RB_REMOVE(flexran_agent_channel_map, &channel_instance.flexran_agent_head, e);
  e->release(e);
  free(e);

  return 0;
}
开发者ID:ShibinMathew36,项目名称:OAI-step,代码行数:32,代码来源:flexran_agent_net_comm.c

示例12: wl_find

struct domain *
wl_find(const gchar *search, struct domain_list *wl)
{
	int			i;
	struct domain		*d = NULL, dfind;
	gchar			*s = NULL;

	if (search == NULL || wl == NULL)
		return (NULL);
	if (strlen(search) < 2)
		return (NULL);

	if (search[0] != '.')
		s = g_strdup_printf(".%s", search);
	else
		s = g_strdup(search);

	for (i = strlen(s) - 1; i >= 0; i--) {
		if (s[i] == '.') {
			dfind.d = &s[i];
			d = RB_FIND(domain_list, wl, &dfind);
			if (d)
				goto done;
		}
	}

done:
	if (s)
		g_free(s);

	return (d);
}
开发者ID:Hary000,项目名称:xxxterm,代码行数:32,代码来源:whitelist.c

示例13: cmd_unbind_key_table

int
cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
{
	struct args			*args = self->args;
	const char			*tablename;
	const struct mode_key_table	*mtab;
	struct mode_key_binding		*mbind, mtmp;

	tablename = args_get(args, 't');
	if ((mtab = mode_key_findtable(tablename)) == NULL) {
		ctx->error(ctx, "unknown key table: %s", tablename);
		return (-1);
	}

	if (key == KEYC_NONE) {
		while (!RB_EMPTY(mtab->tree)) {
			mbind = RB_ROOT(mtab->tree);
			RB_REMOVE(mode_key_tree, mtab->tree, mbind);
			xfree(mbind);
		}
		return (0);
	}

	mtmp.key = key;
	mtmp.mode = !!args_has(args, 'c');
	if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
		RB_REMOVE(mode_key_tree, mtab->tree, mbind);
		xfree(mbind);
	}
	return (0);
}
开发者ID:cowboyrushforth,项目名称:tmux2,代码行数:31,代码来源:cmd-unbind-key.c

示例14: ctfile_cache_trim_aliens

/*
 * Remove any files not in ``keepfiles'' from cachedir.
 *
 * This is best effort and returns no errors if we fail to remove a file.
 */
void
ctfile_cache_trim_aliens(const char *cachedir,
    struct ctfile_list_tree *keepfiles)
{
	struct ctfile_list_file	 sfile;
	struct dirent		*dp;
	DIR			*dirp;

	CNDBG(CT_LOG_CTFILE, "triming files not found on server");

	if ((dirp = opendir(cachedir)) == NULL)
		return;
	while ((dp = readdir(dirp)) != NULL) {
		/* ignore . and ..  */
		if (strcmp(dp->d_name, ".") == 0 ||
		    strcmp(dp->d_name, "..") == 0)
			continue;
		strlcpy(sfile.mlf_name, dp->d_name, sizeof(sfile.mlf_name));
		if ((RB_FIND(ctfile_list_tree, keepfiles, &sfile)) == NULL) {
			CNDBG(CT_LOG_CTFILE, "Trimming %s from ctfile cache: "
			    "not found on server", dp->d_name); 
			(void)ctfile_cache_remove(dp->d_name, cachedir);
		}
	}
	closedir(dirp);

	CNDBG(CT_LOG_CTFILE, "done");

	return;
}
开发者ID:carriercomm,项目名称:cyphertite,代码行数:35,代码来源:ct_ctfile_remote.c

示例15: net2_udpsocket_recv

/*
 * UDP specific implementation of receive.
 */
static void
net2_udpsocket_recv(void *udps_ptr, struct net2_dgram_rx *rx)
{
	struct net2_udpsocket	*udps = udps_ptr;
	struct net2_conn_receive*r;
	struct net2_conn_p2p	*c, search;

	if ((r = net2_malloc(sizeof(*r))) == NULL)
		return;	/* Drop packet. */
	r->buf = rx->data;
	rx->data = NULL;
	r->error = rx->error;

	search.np2p_remote = (struct sockaddr*)&rx->addr;
	search.np2p_remotelen = rx->addrlen;
	c = RB_FIND(net2_udpsocket_conns, &udps->conns, &search);
	if (c != NULL)
		net2_connection_recv(&c->np2p_conn, r);
	else {
		/* Unrecognized connection. */
		/* XXX Implement new connection callback. */
		if (r->buf)
			net2_buffer_free(r->buf);
		net2_free(r);
	}
}
开发者ID:nahratzah,项目名称:ilias_net2,代码行数:29,代码来源:udp_connection.c


注:本文中的RB_FIND函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。