MCPcopy Create free account
hub / github.com/EASY233/Finger / memorySearch

Method memorySearch

lib/ip2Region.py:25–56  ·  view source on GitHub ↗

" memory search method " param: ip

(self, ip)

Source from the content-addressed store, hash-verified

23 self.initDatabase(dbfile)
24
25 def memorySearch(self, ip):
26 """
27 " memory search method
28 " param: ip
29 """
30 if not ip.isdigit(): ip = self.ip2long(ip)
31
32 if self.__dbBinStr == '':
33 self.__dbBinStr = self.__f.read() #read all the contents in file
34 self.__indexSPtr = self.getLong(self.__dbBinStr, 0)
35 self.__indexLPtr = self.getLong(self.__dbBinStr, 4)
36 self.__indexCount = int((self.__indexLPtr - self.__indexSPtr)/self.__INDEX_BLOCK_LENGTH)+1
37
38 l, h, dataPtr = (0, self.__indexCount, 0)
39 while l <= h:
40 m = int((l+h) >> 1)
41 p = self.__indexSPtr + m*self.__INDEX_BLOCK_LENGTH
42 sip = self.getLong(self.__dbBinStr, p)
43
44 if ip < sip:
45 h = m -1
46 else:
47 eip = self.getLong(self.__dbBinStr, p+4)
48 if ip > eip:
49 l = m + 1;
50 else:
51 dataPtr = self.getLong(self.__dbBinStr, p+8)
52 break
53
54 if dataPtr == 0: raise Exception("Data pointer not found")
55
56 return self.returnData(dataPtr)
57
58 def binarySearch(self, ip):
59 """

Callers

nothing calls this directly

Calls 3

ip2longMethod · 0.95
getLongMethod · 0.95
returnDataMethod · 0.95

Tested by

no test coverage detected