class BitMap:
def __init__(self,maxsize):
self.size=maxsize//31+1
self.data=[0 for i in range(self.size)]
def getIndex(self,num):
return num//31
def getBitIndex(self,num):
return num%31
def setnum(self,num):
index=self.getIndex(num)
bitIndex=self.getBitIndex(num)
self.data[index]=self.data[index]|(1<<bitIndex)
def find(self,num):
index = self.getIndex(num)
bitIndex = self.getBitIndex(num)
if self.data[index] & (1 << bitIndex):
return True
return False
array=[45, 2, 78, 35, 67, 90, 879, 0, 340, 123, 46]
out=[]
bitmap=BitMap(max(array))
for i in array:
bitmap.setnum(i)
for i in range(max(array)+1):
if bitmap.find(i):
out.append(i)
print(out)