package com.day_215
import org.apache.spark.{
SparkConf, SparkContext}
object IPLocation {
//*****************************将传进来的数转换成10进制的数
def ip2Long(ip: String): Long = {
val fragments = ip.split("[.]")
var ipNum = 0L
for (i <- 0 until fragments.length){
ipNum = fragments(i).toLong | ipNum << 8L
}
ipNum
}
//*****************************8二分查找
def binarySearch(lines: Array[(String, String, String)], ip: Long) : Int = {
var low =
运用广播变量(关键词:broadcast())查找每个ip所对应的地址,以及每个地址出现的频率;int转十进制的方法;二分查找的方法
最新推荐文章于 2022-11-18 10:56:05 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)