随笔 - 170  文章 - 0  评论 - 16  阅读 - 35908 

#include <stdio.h>
#include <stdlib.h>

#include <map>
#include <vector>
#include <iostream>
using namespace std;

struct m_info_url_hash_id_t {
unsigned long long info_id;
char **url;
};

std::map<unsigned long long, std::vector<struct m_info_url_hash_id_t> > g_map_info_url_hash;

char *gene_url = "ftp://github.com";

unsigned long long insert_info_url_hash_map(unsigned long long info_url_hash, char **url_addr, unsigned long long info_id,
std::map<unsigned long long, std::vector<struct m_info_url_hash_id_t> > &v_info_hash_map)
{

printf("line=%d url_hash=0x%llx \n", __LINE__, info_url_hash);
if(v_info_hash_map.empty())
{ //如果是一个空的map,直接插入进入去就行
printf("line=%d\n", __LINE__);
struct m_info_url_hash_id_t info;
info.info_id = info_id;
info.url = url_addr;
v_info_hash_map[info_url_hash] = vector<struct m_info_url_hash_id_t>();
v_info_hash_map[info_url_hash].push_back(info);
}else {
//非空的map有两大情况,如果是找到了相同的hash,则比较URL是否相同,如果URL也相同,就不用再插入了。如果URL不同,就插入到找到的
//hash对应的单元的vector中。
printf("line=%d\n", __LINE__);

std::map<unsigned long long, std::vector<struct m_info_url_hash_id_t> >::iterator iter;
iter = v_info_hash_map.find(info_url_hash);
if (iter == v_info_hash_map.end())
{
printf("line=%d\n", __LINE__);
struct m_info_url_hash_id_t info;
info.info_id = info_id;
info.url = url_addr;
//std::vector<struct m_info_url_hash_id_t> it1 =
v_info_hash_map[info_url_hash] = vector<struct m_info_url_hash_id_t>();
v_info_hash_map[info_url_hash].push_back(info);

}else {
printf("line=%d\n", __LINE__);
struct m_info_url_hash_id_t info;
info.info_id = info_id;
info.url = url_addr;
#if 1
v_info_hash_map[info_url_hash].push_back(info);
#else
//XXXX 这种做法就不能正确插入数据
vector<struct m_info_url_hash_id_t> vstr = iter->second;
vstr.push_back(info);
#endif

}
}

return 0;
}

int main(int argc, char *argv[])
{

#if 1
char *url1 = "/home/yyy";
char *url2 = "https://news.sina.com.cn";
char *url3 = "https://news.sohu.com.cn";
char *url4 = "https://news.yahoo.com.cn";
char *url5 = "https://tv.yahoo.com.cn";
char *url7 = "https://tv.sina.com.cn";
char *url8 = "https://tv.sohu.com.cn";
char *url9 = "https://tv.yahoo.com.cn";
int idx = 0;


insert_info_url_hash_map(0x1001, &url1, 0x10001, g_map_info_url_hash);
insert_info_url_hash_map(0x2002, &url2, 0x20002, g_map_info_url_hash);
insert_info_url_hash_map(0x3003, &url3, 0x30003, g_map_info_url_hash);

insert_info_url_hash_map(0x1001, &url8, 0x10004, g_map_info_url_hash);
insert_info_url_hash_map(0x2002, &url5, 0x20005, g_map_info_url_hash);
insert_info_url_hash_map(0x3003, &url7, 0x30006, g_map_info_url_hash);

for (std::map<unsigned long long, std::vector<struct m_info_url_hash_id_t> >::iterator iter = g_map_info_url_hash.begin(); iter != g_map_info_url_hash.end(); iter++)
{
printf("\n line=%d\n", __LINE__);
unsigned long long ulli = iter->first;
printf("\n line=%d\n", __LINE__);
vector<struct m_info_url_hash_id_t> vstr = iter->second;
printf("\n line=%d\n", __LINE__);
printf("\n hash=0x%llx", ulli);
for (vector<struct m_info_url_hash_id_t>::iterator it = vstr.begin(); it != vstr.end(); it++)
{
printf("\n line=%d\n", __LINE__);
struct m_info_url_hash_id_t info = *it; //vstr[idx];
printf("\t info_id =0x%llx, url=%s ", info.info_id, *info.url);

}
printf("\n end\n");
}

printf("\n\n");

return 0

}

 

posted on   北京开发  阅读(178)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
点击右上角即可分享
微信分享提示