public string GetAddressWithIP(string IPValue) { if (!bFilePathInitialized) { return(""); } Initialize(); UInt32 ip = IPToUInt32(IPValue); while (true) { //首先初始化本轮查找的区间 //区间头 Search_Set = IndexInfoAtPos(Search_Index_Set); //区间尾 Search_End = IndexInfoAtPos(Search_Index_End); //判断IP是否在区间头内 if (ip >= Search_Set.IpSet && ip <= Search_Set.IpEnd) { return(ReadAddressInfoAtOffset(Search_Set.Offset)); } //判断IP是否在区间尾内 if (ip >= Search_End.IpSet && ip <= Search_End.IpEnd) { return(ReadAddressInfoAtOffset(Search_End.Offset)); } //计算出区间中点 Search_Mid = IndexInfoAtPos((Search_Index_End + Search_Index_Set) / 2); //判断IP是否在中点 if (ip >= Search_Mid.IpSet && ip <= Search_Mid.IpEnd) { return(ReadAddressInfoAtOffset(Search_Mid.Offset)); } //本轮没有找到,准备下一轮 if (ip < Search_Mid.IpSet) { //IP比区间中点要小,将区间尾设为现在的中点,将区间缩小1倍。 Search_Index_End = (Search_Index_End + Search_Index_Set) / 2; } else { //IP比区间中点要大,将区间头设为现在的中点,将区间缩小1倍。 Search_Index_Set = (Search_Index_End + Search_Index_Set) / 2; } } //return ""; }
protected CZ_INDEX_INFO IndexInfoAtPos(uint Index_Pos) { CZ_INDEX_INFO cZ_INDEX_INFO = new CZ_INDEX_INFO(); FileStrm.Seek(Index_Set + 7 * Index_Pos, SeekOrigin.Begin); cZ_INDEX_INFO.IpSet = GetUInt32(); cZ_INDEX_INFO.Offset = GetOffset(); FileStrm.Seek(cZ_INDEX_INFO.Offset, SeekOrigin.Begin); cZ_INDEX_INFO.IpEnd = GetUInt32(); return(cZ_INDEX_INFO); }
protected CZ_INDEX_INFO IndexInfoAtPos(uint Index_Pos) { var Index_Info = new CZ_INDEX_INFO(); //根据索引编号计算出在文件中在偏移位置 FileStrm.Seek(Index_Set + 7 * Index_Pos, SeekOrigin.Begin); Index_Info.IpSet = GetUInt32(); Index_Info.Offset = GetOffset(); FileStrm.Seek(Index_Info.Offset, SeekOrigin.Begin); Index_Info.IpEnd = GetUInt32(); return(Index_Info); }
public string GetAddressWithIP(string IPValue) { if (!bFilePathInitialized) { return(""); } Initialize(); uint num = IPToUInt32(IPValue); while (true) { Search_Set = IndexInfoAtPos(Search_Index_Set); Search_End = IndexInfoAtPos(Search_Index_End); if (num >= Search_Set.IpSet && num <= Search_Set.IpEnd) { return(ReadAddressInfoAtOffset(Search_Set.Offset)); } if (num >= Search_End.IpSet && num <= Search_End.IpEnd) { return(ReadAddressInfoAtOffset(Search_End.Offset)); } Search_Mid = IndexInfoAtPos((Search_Index_End + Search_Index_Set) / 2u); if (num >= Search_Mid.IpSet && num <= Search_Mid.IpEnd) { break; } if (num < Search_Mid.IpSet) { Search_Index_End = (Search_Index_End + Search_Index_Set) / 2u; } else { Search_Index_Set = (Search_Index_End + Search_Index_Set) / 2u; } } return(ReadAddressInfoAtOffset(Search_Mid.Offset)); }
protected CZ_INDEX_INFO IndexInfoAtPos(UInt32 Index_Pos) { CZ_INDEX_INFO Index_Info = new CZ_INDEX_INFO(); //根据索引编号计算出在文件中在偏移位置 FileStrm.Seek(Index_Set + 7 * Index_Pos, SeekOrigin.Begin); Index_Info.IpSet = GetUInt32(); Index_Info.Offset = GetOffset(); FileStrm.Seek(Index_Info.Offset, SeekOrigin.Begin); Index_Info.IpEnd = GetUInt32(); return Index_Info; }
public string GetAddressWithIP(string IPValue) { if (!bFilePathInitialized) return ""; Initialize(); UInt32 ip = IPToUInt32(IPValue); while (true) { //首先初始化本轮查找的区间 //区间头 Search_Set = IndexInfoAtPos(Search_Index_Set); //区间尾 Search_End = IndexInfoAtPos(Search_Index_End); //判断IP是否在区间头内 if (ip >= Search_Set.IpSet && ip <= Search_Set.IpEnd) return ReadAddressInfoAtOffset(Search_Set.Offset); //判断IP是否在区间尾内 if (ip >= Search_End.IpSet && ip <= Search_End.IpEnd) return ReadAddressInfoAtOffset(Search_End.Offset); //计算出区间中点 Search_Mid = IndexInfoAtPos((Search_Index_End + Search_Index_Set) / 2); //判断IP是否在中点 if (ip >= Search_Mid.IpSet && ip <= Search_Mid.IpEnd) return ReadAddressInfoAtOffset(Search_Mid.Offset); //本轮没有找到,准备下一轮 if (ip < Search_Mid.IpSet) //IP比区间中点要小,将区间尾设为现在的中点,将区间缩小1倍。 Search_Index_End = (Search_Index_End + Search_Index_Set) / 2; else //IP比区间中点要大,将区间头设为现在的中点,将区间缩小1倍。 Search_Index_Set = (Search_Index_End + Search_Index_Set) / 2; } }