-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentsList.py
47 lines (39 loc) · 1.09 KB
/
DocumentsList.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
__author__ = 'kasper'
# DISC
# TODO
import math
class DocumentList:
def __init__(self, did):
self.__docList = []
self.__docId = did
self.__count = 0
def addDocument(self, dId, idf):
self.__docList.append((dId, idf))
self.__count += 1
def docList(self):
return self.__docList
def count(self):
return self.__count
def searchDocument(self, dId):
if self.__count == 0:
self.__docList[0] = dId
return 1
else:
i = 0
num = self.__count - 1
while True:
if i == num:
# return i
break
if dId < self.__docList[(num+i)/2]:
num = (num+i)/2
num -= 1
elif dId > self.__docList[(num+i)/2]:
i = (num+i-1) / 2
i += 1
else:
# return (num+i)/2
i = (num+i)/2
break
if dId > self.__docList[i]:
return i