• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ HASH_FIND函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: get_min_time_from_neighbor

uint32_t get_min_time_from_neighbor(uint8_t neighbor_main_addr[ETH_ALEN]) {
    if(neighbor_set_ett == NULL) {
        return false;
    }

    // Searching for entry with neighbor_main_addr as key
    olsr_db_neighbors_ett_entry_t* entry;
    HASH_FIND(hh, neighbor_set_ett, neighbor_main_addr, ETH_ALEN, entry);

    if(entry == NULL) {
        return false;
    }

    // searching for the minimum time_int_sw entry
    uint32_t min = INT_MAX;
    int i;

    for(i = 0; i < ETT_SW_SIZE; i++) {
        if(entry->time_int_sw[i] > 0) {
            if(entry->time_int_sw[i] < min) {
                min = entry->time_int_sw[i];
            }
        }
    }

    if(min == INT_MAX) {
        return false;
    }

    return min;
}
开发者ID:Dekue,项目名称:des-routing-algorithms,代码行数:31,代码来源:neighbor_set_ett.c


示例2: process_ett_stop_time

uint32_t process_ett_stop_time(uint8_t neighbor_main_addr[ETH_ALEN], struct timeval* ett_stop_time) {
    olsr_db_neighbors_ett_entry_t* entry;

    if(neighbor_set_ett == NULL) {
        return false;
    }

    HASH_FIND(hh, neighbor_set_ett, neighbor_main_addr, ETH_ALEN, entry);

    if(entry == NULL) {
        return false;
    }

    // If no previous ETT-START package was received false is returned
    if(entry->timeval_recv.tv_sec == 0 && entry->timeval_recv.tv_usec == 0) {
        return false;
    }

    // calculates the difference between ett_stop_time and timeval_recv
    struct timeval res;
    timeval_subtract(&res, &(entry->timeval_recv), ett_stop_time);
    // calculates the difference time in usec
    uint32_t result = res.tv_sec * 1000000 + res.tv_usec;
    // deleting the old timeval_recv value
    entry->timeval_recv.tv_sec = 0;
    entry->timeval_recv.tv_usec = 0;
    return result;
}
开发者ID:Dekue,项目名称:des-routing-algorithms,代码行数:28,代码来源:neighbor_set_ett.c


示例3: draw_character

void draw_character(void *screen,int x,int y,int w,uint32_t cin,uint32_t bg,uint32_t fg,int bold,int underline,int italic,int strike) {

    SDL_Texture *texture=0;
 
    lookup_key_t chr;
    chr.c = cin;
    chr.fg = fg;
    chr.bg = bg;
    chr.bold = bold;
    chr.underline = underline;
    chr.italic = italic;
    chr.strike = strike;
    
    char_render_t *mchr=0;
    HASH_FIND( hh, display_cache, &chr, char_render_t_keylen, mchr);
    
    if(!mchr) {
      uint32_t Rmask, Gmask, Bmask, Amask;      /* masks for desired format */
   
      Rmask = 0xff000000;
      Gmask = 0x00ff0000;
      Bmask = 0x0000ff00;
      Amask = 0x000000ff;
    
      int bpp=32;                /* bits per pixel for desired format */
    
 //     SDL_Surface *converted = SDL_CreateRGBSurface(0,w,16,32,0,0,0,0);
      SDL_Surface *converted = SDL_CreateRGBSurface(SDL_SWSURFACE, w, 16, bpp, Rmask, Gmask, Bmask, Amask);
    
      if(converted == NULL) {
        printf("failed to create surface\n");
      }
      
      draw_character_surface(converted,0,0,w,cin,bg,fg,bold,underline,italic,strike);

 //     texture = SDL_CreateTexture(screen,converted->format,0,w,16);
 //     (((uint32_t *) (converted->pixels))[0]) = 0xFFFFFFFF;
 //     SDL_UpdateTexture(texture,NULL,converted->pixels,w*4);
      texture = SDL_CreateTextureFromSurface(screen, converted);
   // SDL_Rect dstRect = { x, y, w, 16 };
   // SDL_RenderCopy(screen, texture, NULL, &dstRect);
    
     // SDL_FreeSurface(converted);

      mchr = malloc(sizeof(char_render_t));
      mchr->c = cin;
      mchr->fg = fg;
      mchr->bg = bg;
      mchr->bold = bold;
      mchr->underline = underline;
      mchr->italic = italic;
      mchr->strike = strike;
      mchr->texture = texture;
        
      HASH_ADD( hh, display_cache, c, char_render_t_keylen, mchr);
    }

    SDL_Rect dstRect = { x, y, w, 16 };
    SDL_RenderCopy(screen, mchr->texture, NULL, &dstRect);
}
开发者ID:new299,项目名称:wflow,代码行数:60,代码来源:nunifont.c


示例4: get_first_record_number

struct fl_url_record *get_first_url_record()
{
   struct fl_url_record *s;
   uint64_t lowest = get_first_record_number();
   HASH_FIND(hh, url_map, &lowest, sizeof(uint64_t), s); 
   return(s);
}
开发者ID:sanyaade-g2g-repos,项目名称:fineline-computer-forensics-timeline-tools,代码行数:7,代码来源:flurlhashmap.c


示例5: fcitx_input_context_manager_create_ic

FcitxInputContext* fcitx_input_context_manager_create_ic(FcitxInputContextManager* manager,
                                                         FcitxInputContextFillDataCallback callback,
                                                         void* userData)
{
    FcitxInputContext* ic = NULL;
    if (manager->freeList) {
        ic = manager->freeList;
        manager->freeList = ic->hh.next;
    } else {
        uint32_t newid;
        while ((newid = ++manager->icid) != 0);
        HASH_FIND(hh, manager->ics, &newid, sizeof(uint32_t), ic);
        if (ic) {
            return NULL;
        }
        ic = fcitx_utils_new(FcitxInputContext);
        ic->id = newid;
        ic->manager = manager;
    }

    if (callback) {
        callback(ic, userData);
    }

    return ic;
}
开发者ID:rwdxll,项目名称:fcitx5,代码行数:26,代码来源:inputcontext.c


示例6: update_stat

/**
 * Record or update stat value.
 */
void update_stat( char *group, char *key, char *value )
{
    DPRINTF("update_stat ( %s, %s, %s )\n", group, key, value);
    statsd_stat_t *s;
    statsd_stat_name_t l;

    memset(&l, 0, sizeof(statsd_stat_name_t));
    strcpy(l.group_name, group);
    strcpy(l.key_name, key);
    DPRINTF("HASH_FIND '%s' '%s'\n", l.group_name, l.key_name);
    HASH_FIND( hh, stats, &l, sizeof(statsd_stat_name_t), s );

    if (s)
    {
        DPRINTF("Updating old stat entry\n");

        s->value = atol( value );
    }
    else
    {
        DPRINTF("Adding new stat entry\n");
        s = malloc(sizeof(statsd_stat_t));
        memset(s, 0, sizeof(statsd_stat_t));

        strcpy(s->name.group_name, group);
        strcpy(s->name.key_name, key);
        s->value = atol(value);
        s->locked = 0;

        HASH_ADD( hh, stats, name, sizeof(statsd_stat_name_t), s );
    }
}
开发者ID:togga,项目名称:statsd-c,代码行数:35,代码来源:counters.c


示例7: _xcb_im_handle_sync_reply

void _xcb_im_handle_sync_reply(xcb_im_t* im, xcb_im_client_t* client, const xcb_im_packet_header_fr_t* hdr, uint8_t* data)
{
    xcb_im_sync_reply_fr_t frame;
    _xcb_im_read_frame_with_error(im, client, frame, data, XIM_MESSAGE_BYTES(hdr));

    do {
        if (client->connect_id != frame.input_method_ID) {
            break;
        }

        xcb_im_input_context_t* ic = NULL;
        HASH_FIND(hh, client->input_contexts, &frame.input_context_ID, sizeof(uint16_t), ic);
        if (!ic) {
            break;
        }

        client->sync = false;
        if (im->sync) {
            im->sync = false;

            if (im->callback) {
                im->callback(im, client, ic, hdr, &frame, NULL, im->user_data);
            }
        }

        _xcb_im_process_queue(im, client);
    } while(0);

    xcb_im_sync_reply_fr_free(&frame);
}
开发者ID:wengxt,项目名称:xcb-imdkit,代码行数:30,代码来源:protocolhandler.c


示例8: __AI_heuristic_func

PRIVATE int
__AI_heuristic_func ( cluster_type type )
{
	AI_snort_alert  *alert_iterator;
	attribute_key   key;
	attribute_value *values = NULL;
	attribute_value *value  = NULL;
	attribute_value *found  = NULL;
	int             max     = 0;
	
	if ( type == none || !alert_log || !h_root[type] )
		return -1;

	for ( alert_iterator = alert_log; alert_iterator; alert_iterator = alert_iterator->next )
	{
		if ( !alert_iterator->h_node[type] )
			continue;

		key.min = alert_iterator->h_node[type]->min_val;
		key.max = alert_iterator->h_node[type]->max_val;

		if ( values )
		{
			HASH_FIND ( hh, values, &key, sizeof ( attribute_key ), found );
		}

		if ( !found )
		{
			if ( !( value = ( attribute_value* ) malloc ( sizeof ( attribute_value )) ))
			{
				AI_fatal_err ( "Fatal dynamic memory allocation failure", __FILE__, __LINE__ );
			}

			memset ( value, 0, sizeof ( attribute_value ));
			value->key   = key;
			value->type  = type;
			value->count = 1;
			HASH_ADD ( hh, values, key, sizeof ( attribute_key ), value );
		} else {
			found->count++;
		}
	}

	for ( value = values; value; value = ( attribute_value* ) value->hh.next )
	{
		if ( value->count > max )
		{
			max = value->count;
		}
	}

	while ( values )
	{
		value = values;
		HASH_DEL ( values, value );
		free ( value );
	}

	return max;
}		/* -----  end of function __AI_heuristic_func  ----- */
开发者ID:BlackLight,项目名称:Snort_AIPreproc,代码行数:60,代码来源:cluster.c


示例9: update_stat

/**
 * Record or update stat value.
 */
void update_stat( char *group, char *key, char *value ) {
  syslog(LOG_DEBUG, "update_stat ( %s, %s, %s )\n", group, key, value);
  statsd_stat_t *s;
  statsd_stat_name_t l;

  memset(&l, 0, sizeof(statsd_stat_name_t));
  strcpy(l.group_name, group);
  strcpy(l.key_name, key);
  syslog(LOG_DEBUG, "HASH_FIND '%s' '%s'\n", l.group_name, l.key_name);
  HASH_FIND( hh, stats, &l, sizeof(statsd_stat_name_t), s );

  if (s) {
    syslog(LOG_DEBUG, "Updating old stat entry");

    wait_for_stats_lock();
    s->value = atol( value );
    remove_stats_lock();
  } else {
    syslog(LOG_DEBUG, "Adding new stat entry");
    s = malloc(sizeof(statsd_stat_t));
    memset(s, 0, sizeof(statsd_stat_t));

    strcpy(s->name.group_name, group);
    strcpy(s->name.key_name, key);
    s->value = atol(value);
    s->locked = 0;

    wait_for_stats_lock();
    HASH_ADD( hh, stats, name, sizeof(statsd_stat_name_t), s );
    remove_stats_lock();
  }
}
开发者ID:ak2consulting,项目名称:statsd-c-buildpackage,代码行数:35,代码来源:statsd.c


示例10: olsr_db_brct_addid

int olsr_db_brct_addid(uint8_t shost_ether[ETH_ALEN], uint32_t brc_id, struct timeval* purge_time) {
    olsr_brclog_entry_t* entry;
    timeslot_purgeobjects(brclog_ts);
    HASH_FIND(hh, brclog_set, shost_ether, ETH_ALEN, entry);

    if(entry == NULL) {
        entry = malloc(sizeof(olsr_brclog_entry_t));

        if(entry == NULL) {
            return false;
        }

        memcpy(entry->shost_ether, shost_ether, ETH_ALEN);
        HASH_ADD_KEYPTR(hh, brclog_set, entry->shost_ether, ETH_ALEN, entry);
        entry->brc_id = brc_id;
        timeslot_addobject(brclog_ts, purge_time, entry);
        return true;
    }

    if(entry->brc_id < brc_id) {
        entry->brc_id = brc_id;
        timeslot_addobject(brclog_ts, purge_time, entry);
        return true;
    }

    return false;
}
开发者ID:Dekue,项目名称:des-routing-algorithms,代码行数:27,代码来源:broadcast_log.c


示例11: mgr_on_accept

void mgr_on_accept(int fd, event_manager* ev_mgr)
{
    if (internal_threads(ev_mgr->excluded_threads, pthread_self()))
        return;

    uint32_t leader_id = get_leader_id(ev_mgr->con_node);
    if (ev_mgr->node_id == leader_id)
    {
        leader_tcp_pair* new_conn = malloc(sizeof(leader_tcp_pair));
        memset(new_conn,0,sizeof(leader_tcp_pair));

        new_conn->key = fd;
        HASH_ADD_INT(ev_mgr->leader_tcp_map, key, new_conn);

        rsm_op(ev_mgr->con_node, 0, NULL, P_TCP_CONNECT, &new_conn->vs);
    } else {
        request_record* retrieve_data = NULL;
        size_t data_size;
    
        while (retrieve_data == NULL){
            retrieve_record(ev_mgr->db_ptr, sizeof(db_key_type), &ev_mgr->cur_rec, &data_size, (void**)&retrieve_data);
        }
        replica_tcp_pair* ret = NULL;
        HASH_FIND(hh, ev_mgr->replica_tcp_map, &retrieve_data->clt_id, sizeof(view_stamp), ret);
        ret->s_p = fd;
        ret->accepted = 1;
    }

    return;
}
开发者ID:apsys16-p10,项目名称:falcon,代码行数:30,代码来源:ev_mgr.c


示例12: PinyinEnhanceMapAdd

void
PinyinEnhanceMapAdd(PyEnhanceMap **map, FcitxMemoryPool *pool,
                    const char *key, unsigned int key_l,
                    const char *word, unsigned int word_l)
{
    PyEnhanceMapWord *py_word;
    PyEnhanceMap *py_map;
#define uthash_malloc(sz) fcitx_memory_pool_alloc_align(pool, sz)
#define uthash_free(ptr)
    word_l++;
    py_word = uthash_malloc(sizeof(PyEnhanceMapWord) + word_l);
    memcpy(py_enhance_map_word(py_word), word, word_l);
    HASH_FIND(hh, *map, key, key_l, py_map);
    if (py_map) {
        py_word->next = py_map->words;
        py_map->words = py_word;
    } else {
        py_map = uthash_malloc(sizeof(PyEnhanceMap) + key_l + 1);
        py_map->words = py_word;
        py_word->next = NULL;
        memcpy(py_enhance_map_key(py_map), key, key_l + 1);
        HASH_ADD_KEYPTR(hh, *map, py_enhance_map_key(py_map), key_l, py_map);
    }
#undef uthash_malloc
#undef uthash_free
}
开发者ID:13572293130,项目名称:fcitx,代码行数:26,代码来源:pinyin-enhance-map.c


示例13: parse_packet

int parse_packet(struct sockaddr_in* addr, char* raw, struct packet_header* header, char* body) {
  struct io_peer *peer = NULL;
  HASH_FIND(hh_addr, peers_addr, addr, sizeof(struct sockaddr_in), peer);
  if (peer == NULL) {
    DPRINTF(DEBUG_SOCKETS, "Unknown peer from %s:%d\n",
            inet_ntoa(addr->sin_addr),
            ntohs(addr->sin_port));
    return -1;
  }

  int peer_id = peer->id;

  memcpy(header, raw, sizeof(struct packet_header));
  packet_ntoh(header);
  if (header->magic != PACKET_MAGIC || header->version != PACKET_VERSION) {
    fprintf(stderr, "Cannot parse unknown packet with MAGIC %d and version %d\n", header->magic, header->version);
    return -1;
  }
  if (header->type == PACKET_ACK) {
    ++header->ack;
  }

  size_t body_len = header->total_len - header->header_len;
  memcpy(body, raw + header->header_len, body_len);

  DPRINTF(DEBUG_SOCKETS, "receive packet from peer:%d type:%d seq:%d ack:%d body_len:%d\n",
          peer_id, header->type, header->seq, header->ack, body_len);

  return peer_id;
}
开发者ID:htc550605125,项目名称:p2p-network,代码行数:30,代码来源:bt_io.c


示例14: _xcb_im_handle_reset_ic

void _xcb_im_handle_reset_ic(xcb_im_t* im, xcb_im_client_t* client, const xcb_im_packet_header_fr_t* hdr, uint8_t* data)
{
    xcb_im_reset_ic_fr_t frame;
    _xcb_im_read_frame_with_error(im, client, frame, data, XIM_MESSAGE_BYTES(hdr));

    do {
        if (client->connect_id != frame.input_method_ID) {
            break;
        }

        xcb_im_input_context_t* ic = NULL;
        HASH_FIND(hh, client->input_contexts, &frame.input_context_ID, sizeof(uint16_t), ic);
        if (!ic) {
            break;
        }

        xcb_im_reset_ic_reply_fr_t reply_frame;
        reply_frame.input_method_ID = frame.input_method_ID;
        reply_frame.input_context_ID = frame.input_context_ID;
        reply_frame.committed_string = NULL;
        reply_frame.byte_length_of_committed_string = 0;

        if (im->callback) {
            im->callback(im, client, ic, hdr, &frame, &reply_frame, im->user_data);
        }

        _xcb_im_send_frame(im, client, reply_frame, true);
        free(reply_frame.committed_string);
    } while(0);

    xcb_im_reset_ic_fr_free(&frame);
}
开发者ID:wengxt,项目名称:xcb-imdkit,代码行数:32,代码来源:protocolhandler.c


示例15: _xcb_im_handle_forward_event

void _xcb_im_handle_forward_event(xcb_im_t* im, xcb_im_client_t* client, const xcb_im_packet_header_fr_t* hdr, uint8_t* data)
{
    xcb_im_forward_event_fr_t frame;
    _xcb_im_read_frame_with_error(im, client, frame, data, XIM_MESSAGE_BYTES(hdr));

    do {
        if (client->connect_id != frame.input_method_ID) {
            break;
        }

        if (XIM_MESSAGE_BYTES(hdr) < xcb_im_forward_event_fr_size(&frame) + sizeof(xcb_key_press_event_t)) {
            break;
        }

        xcb_im_input_context_t* ic = NULL;
        HASH_FIND(hh, client->input_contexts, &frame.input_context_ID, sizeof(uint16_t), ic);
        if (!ic) {
            break;
        }
        if (client->sync) {
            _xcb_im_add_queue(im, client, ic->id, hdr, &frame, data);
        } else {
            xcb_key_press_event_t key_event;
            memcpy(&key_event, data, sizeof(xcb_key_press_event_t));

            if (im->callback) {
                im->callback(im, client, ic, hdr, &frame, &key_event, im->user_data);
            }
        }
    } while(0);

    xcb_im_forward_event_fr_free(&frame);
}
开发者ID:wengxt,项目名称:xcb-imdkit,代码行数:33,代码来源:protocolhandler.c


示例16: nat_fix_upstream

int nat_fix_upstream(nat_ctx_t *ctx, unsigned char *buf, size_t buflen,
                     const struct sockaddr *addr, socklen_t addrlen) {
  uint8_t iphdr_len;
  if (buflen < SHADOWVPN_USERTOKEN_LEN + 20) {
    errf("nat: ip packet too short");
    return -1;
  }
  ipv4_hdr_t *iphdr = (ipv4_hdr_t *)(buf + SHADOWVPN_USERTOKEN_LEN);
  if ((iphdr->ver & 0xf0) != 0x40) {
    // check header, currently IPv4 only
    // bypass IPv6
    return 0;
  }
  iphdr_len = (iphdr->ver & 0x0f) * 4;

  // print_hex_memory(buf, SHADOWVPN_USERTOKEN_LEN);
  client_info_t *client = NULL;
  HASH_FIND(hh1, ctx->token_to_clients, buf, SHADOWVPN_USERTOKEN_LEN, client);
  if (client == NULL) {
    errf("nat: client not found for given user token");
    return -1;
  }
  // print_hex_memory(iphdr, buflen - SHADOWVPN_USERTOKEN_LEN);

  // save source address
  client->source_addr.addrlen =  addrlen;
  memcpy(&client->source_addr.addr, addr, addrlen);

  int32_t acc = 0;
  // save tun input ip to client
  client->input_tun_ip = iphdr->saddr;

  // overwrite IP
  iphdr->saddr = client->output_tun_ip;

  // add old, sub new
  acc = client->input_tun_ip - iphdr->saddr;
  ADJUST_CHECKSUM(acc, iphdr->checksum);

  if (0 == (iphdr->frag & htons(0x1fff))) {
    // only adjust tcp & udp when frag offset == 0
    void *ip_payload = buf + SHADOWVPN_USERTOKEN_LEN + iphdr_len;
    if (iphdr->proto == IPPROTO_TCP) {
      if (buflen < iphdr_len + 20) {
        errf("nat: tcp packet too short");
        return -1;
      }
      tcp_hdr_t *tcphdr = ip_payload;
      ADJUST_CHECKSUM(acc, tcphdr->checksum);
    } else if (iphdr->proto == IPPROTO_UDP) {
      if (buflen < iphdr_len + 8) {
        errf("nat: udp packet too short");
        return -1;
      }
      udp_hdr_t *udphdr = ip_payload;
      ADJUST_CHECKSUM(acc, udphdr->checksum);
    }
  }
  return 0;
}
开发者ID:00o0o,项目名称:ShadowVPN,代码行数:60,代码来源:nat.c


示例17: _xcb_im_handle_destroy_ic

void _xcb_im_handle_destroy_ic(xcb_im_t* im,
                               xcb_im_client_t* client,
                               const xcb_im_packet_header_fr_t* hdr,
                               uint8_t* data)
{
    xcb_im_destroy_ic_fr_t frame;
    _xcb_im_read_frame_with_error(im, client, frame, data, XIM_MESSAGE_BYTES(hdr));

    do {
        if (frame.input_method_ID != client->connect_id) {
            break;
        }

        xcb_im_input_context_t* ic = NULL;
        HASH_FIND(hh, client->input_contexts, &frame.input_context_ID, sizeof(uint16_t), ic);
        if (!ic) {
            break;
        }

        xcb_im_destroy_ic_reply_fr_t reply_frame;
        reply_frame.input_method_ID = client->connect_id;
        reply_frame.input_context_ID = frame.input_context_ID;
        xcb_im_destroy_ic_fr_free(&frame);

        _xcb_im_destroy_ic(im, ic);

        _xcb_im_send_frame(im, client, reply_frame, true);
        return;
    } while(0);
    // error
    xcb_im_destroy_ic_fr_free(&frame);
    _xcb_im_send_error_message(im, client);
    return;
}
开发者ID:wengxt,项目名称:xcb-imdkit,代码行数:34,代码来源:protocolhandler.c


示例18: moloch_plugins_register_internal

int moloch_plugins_register_internal(const char *            name,
                                     gboolean                storeData,
                                     size_t                  sessionsize,
                                     int                     apiversion)
{
    MolochPlugin_t *plugin;

    if (sizeof(MolochSession_t) != sessionsize) {
        LOG("Plugin '%s' built with different version of moloch.h", name);
        exit(-1);
    }

    if (MOLOCH_API_VERSION != apiversion) {
        LOG("Plugin '%s' built with different version of moloch.h", name);
        exit(-1);
    }

    HASH_FIND(p_, plugins, name, plugin);
    if (plugin) {
        LOG("Plugin %s is already registered", name);
        exit(-1);
    }

    plugin = MOLOCH_TYPE_ALLOC0(MolochPlugin_t);
    plugin->name = strdup(name);
    if (storeData) {
        plugin->num  = config.numPlugins++;
    } else {
        plugin->num  = -1;
    }
    HASH_ADD(p_, plugins, name, plugin);
    return plugin->num;
}
开发者ID:Amelos,项目名称:moloch,代码行数:33,代码来源:plugins.c


示例19: dist_bag_compare

/**
 * Computes the bag distance of two strings. The distance approximates
 * and lower bounds the Levenshtein distance.
 * @param x first string 
 * @param y second string
 * @return Bag distance
 */
float dist_bag_compare(hstring_t x, hstring_t y)
{
    float d = 0;
    bag_t *xh, *yh, *xb, *yb;

    xh = bag_create(x);
    yh = bag_create(y);

    int missing = y.len;
    for (xb = xh; xb != NULL; xb = xb->hh.next) {
        HASH_FIND(hh, yh, &(xb->sym), sizeof(sym_t), yb);
        if (!yb) {
            d += xb->cnt;
        } else {
            d += fabs(xb->cnt - yb->cnt);
            missing -= yb->cnt;
        }
    }
    d += missing;

    bag_destroy(xh);
    bag_destroy(yh);

    return lnorm(n, d, x, y);
}
开发者ID:MLDroid,项目名称:harry,代码行数:32,代码来源:dist_bag.c


示例20: do_action_tcp_connect

static void do_action_tcp_connect(view_stamp clt_id,void* arg){
    event_manager* ev_mgr = arg;
    replica_tcp_pair* ret;

    HASH_FIND(hh, ev_mgr->replica_tcp_map, &clt_id, sizeof(view_stamp), ret);
    if(NULL==ret){
        ret = malloc(sizeof(replica_tcp_pair));
        memset(ret,0,sizeof(replica_tcp_pair));
        ret->key = clt_id;
        ret->accepted = 0;
        HASH_ADD(hh, ev_mgr->replica_tcp_map, key, sizeof(view_stamp), ret);
    }

    int fd = socket(AF_INET, SOCK_STREAM, 0);

    connect(fd, (struct sockaddr*)&ev_mgr->sys_addr.s_addr,ev_mgr->sys_addr.s_sock_len);

    ret->p_s = fd;

    SYS_LOG(ev_mgr, "EVENT MANAGER sets up socket connection with server application.\n");
    set_blocking(fd, 0);

    int enable = 1;
    if(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void*)&enable, sizeof(enable)) < 0)
        printf("TCP_NODELAY SETTING ERROR!\n");
    keep_alive(fd);
    while (!ret->accepted);

    return;
}
开发者ID:apsys16-p10,项目名称:falcon,代码行数:30,代码来源:ev_mgr.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ HASH_FIND_INT函数代码示例发布时间:2022-05-30
下一篇:
C++ HASH_DataIn函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap