手把手教你写网络爬虫(7):URL去重

2018 年 5 月 17 日 Python开发者

(点击上方公众号,可快速关注)


来源: 拓海

http://www.cnblogs.com/tuohai666/p/8949393.html


本系列:


IPv6编码地址数:2^128(约3.4×10^38)

IPv6是IETF设计的用于替代现行版本IP协议(IPv4)的下一代IP协议,号称可以为全世界的每一粒沙子编上一个网址。

public <T> boolean put(T object, Funnel<? super T> funnel, int numHashFunctions, BitArray bits) {

    long bitSize = bits.bitSize();

    long hash64 = Hashing.murmur3_128().hashObject(object, funnel).asLong();

    int hash1 = (int) hash64;

    int hash2 = (int) (hash64 >>> 32);

 

    boolean bitsChanged = false;

    for (int i = 1; i <= numHashFunctions; i++) {

        int combinedHash = hash1 + (i * hash2);

        // Flip all the bits if it's negative (guaranteed positive number)

        if (combinedHash < 0) {

            combinedHash = ~combinedHash;

        }

        bitsChanged |= bits.set(combinedHash % bitSize);

    }

    return bitsChanged;

}


boolean set(long index) {

    if (!get(index)) {

        data[(int) (index >>> 6)] |= (1L << index);

        bitCount++;

        return true;

    }

    return false;

}

  

boolean get(long index) {

    return (data[(int) (index >>> 6)] & (1L << index)) != 0;

}


02 先get()一下,看看是不是已经置为1。

03 index右移6位就是除以64,说明data是long型的数组,除以64就定位到了bit所在的数组下标。1L左移index位,定位到了bit在long中的位置。


看完本文有收获?请转发分享给更多人

关注「Python开发者」,提升Python技能

登录查看更多
0

相关内容

网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常被称为网页追逐者),是一种按照一定的规则,自动的抓取万维网信息的程序或者脚本,已被广泛应用于互联网领域。搜索引擎使用网络爬虫抓取Web网页、文档甚至图片、音频、视频等资源,通过相应的索引技术组织这些信息,提供给搜索用户进行查询。网络爬虫也为中小站点的推广提供了有效的途径。
一份简明有趣的Python学习教程,42页pdf
专知会员服务
76+阅读 · 2020年6月22日
干净的数据:数据清洗入门与实践,204页pdf
专知会员服务
160+阅读 · 2020年5月14日
【实用书】Python爬虫Web抓取数据,第二版,306页pdf
专知会员服务
115+阅读 · 2020年5月10日
【干货】大数据入门指南:Hadoop、Hive、Spark、 Storm等
专知会员服务
94+阅读 · 2019年12月4日
【电子书】C++ Primer Plus 第6版,附PDF
专知会员服务
83+阅读 · 2019年11月25日
【电子书】Flutter实战305页PDF免费下载
专知会员服务
20+阅读 · 2019年11月7日
TensorFlow 2.0 学习资源汇总
专知会员服务
66+阅读 · 2019年10月9日
手把手教你入门深度强化学习(附链接&代码)
THU数据派
75+阅读 · 2019年7月16日
百闻不如一码!手把手教你用Python搭一个Transformer
大数据文摘
18+阅读 · 2019年4月22日
已删除
创业邦杂志
5+阅读 · 2019年3月27日
手把手教你用R语言制作网络爬虫机器人(一)
R语言中文社区
4+阅读 · 2019年1月26日
Python | 爬爬爬:爬百度云,爬百度贴吧,爬爱奇艺
计算机与网络安全
3+阅读 · 2018年3月30日
python数据分析师面试题选
数据挖掘入门与实战
6+阅读 · 2017年11月21日
Python3爬虫之入门和正则表达式
全球人工智能
7+阅读 · 2017年10月9日
【宁波站】网络爬虫与文本挖掘
数萃大数据
4+阅读 · 2017年7月19日
Arxiv
12+阅读 · 2019年4月9日
Arxiv
7+阅读 · 2018年6月19日
Arxiv
5+阅读 · 2018年6月12日
VIP会员
相关VIP内容
一份简明有趣的Python学习教程,42页pdf
专知会员服务
76+阅读 · 2020年6月22日
干净的数据:数据清洗入门与实践,204页pdf
专知会员服务
160+阅读 · 2020年5月14日
【实用书】Python爬虫Web抓取数据,第二版,306页pdf
专知会员服务
115+阅读 · 2020年5月10日
【干货】大数据入门指南:Hadoop、Hive、Spark、 Storm等
专知会员服务
94+阅读 · 2019年12月4日
【电子书】C++ Primer Plus 第6版,附PDF
专知会员服务
83+阅读 · 2019年11月25日
【电子书】Flutter实战305页PDF免费下载
专知会员服务
20+阅读 · 2019年11月7日
TensorFlow 2.0 学习资源汇总
专知会员服务
66+阅读 · 2019年10月9日
相关资讯
手把手教你入门深度强化学习(附链接&代码)
THU数据派
75+阅读 · 2019年7月16日
百闻不如一码!手把手教你用Python搭一个Transformer
大数据文摘
18+阅读 · 2019年4月22日
已删除
创业邦杂志
5+阅读 · 2019年3月27日
手把手教你用R语言制作网络爬虫机器人(一)
R语言中文社区
4+阅读 · 2019年1月26日
Python | 爬爬爬:爬百度云,爬百度贴吧,爬爱奇艺
计算机与网络安全
3+阅读 · 2018年3月30日
python数据分析师面试题选
数据挖掘入门与实战
6+阅读 · 2017年11月21日
Python3爬虫之入门和正则表达式
全球人工智能
7+阅读 · 2017年10月9日
【宁波站】网络爬虫与文本挖掘
数萃大数据
4+阅读 · 2017年7月19日
Top
微信扫码咨询专知VIP会员